Skip to content

Commit

Permalink
Merge pull request #1724 from OpenEnergyPlatform/feature-1699-fix-sce…
Browse files Browse the repository at this point in the history
…nario-years

Fix bug in scenario years #1699
  • Loading branch information
jh-RLI authored Jun 17, 2024
2 parents 5cbd08d + 68a53dd commit acd4c85
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
28 changes: 17 additions & 11 deletions factsheet/frontend/src/components/factsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,18 @@ function Factsheet(props) {
const [isCreated, setIsCreated] = useState(false);
const [scenarioRegions, setScenarioRegions] = useState([]);
const [scenarioInteractingRegions, setScenarioInteractingRegions] = useState([]);
const [scenarioYears, setScenarioYears] = useState([]);
const [models, setModels] = useState([]);
const [frameworks, setFrameworks] = useState([]);
const [sunburstData, setSunburstData] = useState([]);

const [openBackDrop, setOpenBackDrop] = React.useState(false);


const scenarioYears = Array.from({ length: 101 }, (_, i) => ({
id: 2000 + i,
name: String(2000 + i)
}));

const handleCloseBackDrop = () => {
setOpenBackDrop(false);
};
Expand Down Expand Up @@ -744,10 +750,10 @@ function Factsheet(props) {
return data;
};

const getScenarioYears = async () => {
/* const getScenarioYears = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OBO.OEO_00020097' } });
return data;
};
}; */

const getModels = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OEO.OEO_00000274' } });
Expand Down Expand Up @@ -807,13 +813,13 @@ function Factsheet(props) {
});
}, []);

useEffect(() => {
/* useEffect(() => {
getScenarioYears().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setScenarioYears(tmp);
});
}, []);
}, []); */

useEffect(() => {
getModels().then((data) => {
Expand Down Expand Up @@ -1115,7 +1121,7 @@ function Factsheet(props) {
});
}

const HandleAddNNewScenarioYears = (newElement) => {
/* const HandleAddNNewScenarioYears = (newElement) => {
axios.post(conf.toep + 'scenario-bundles/add_entities/',
{
entity_type: 'OBO.OEO_00020097',
Expand All @@ -1136,9 +1142,9 @@ function Factsheet(props) {
setScenarioYears(tmp);
});
});
}
} */

const HandleEditScenarioYears = (oldElement, newElement, editIRI) => {
/* const HandleEditScenarioYears = (oldElement, newElement, editIRI) => {
axios.post(conf.toep + 'scenario-bundles/update_an_entity/',
{
entity_type: 'OBO.OEO_00020097',
Expand All @@ -1160,7 +1166,7 @@ function Factsheet(props) {
});
}
});
}
} */

const HandleAddNewModel = (newElement) => {
axios.post(conf.toep + 'scenario-bundles/add_entities/',
Expand Down Expand Up @@ -1495,8 +1501,8 @@ function Factsheet(props) {
HandleAddNewRegion={HandleAddNewRegion}
HandleEditInteractingRegion={HandleEditInteractingRegion}
HandleAddNewInteractingRegion={HandleAddNewInteractingRegion}
HandleEditScenarioYear={HandleEditScenarioYears}
HandleAddNNewScenarioYear={HandleAddNNewScenarioYears}
//HandleEditScenarioYear={HandleEditScenarioYears}
//HandleAddNNewScenarioYear={HandleAddNNewScenarioYears}
scenarioDescriptorHandler={scenarioDescriptorHandler}
/>
</TabPanel>
Expand Down
17 changes: 5 additions & 12 deletions factsheet/frontend/src/components/scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,11 @@ export default function Scenario(props) {
scenarioDescriptorHandler
} = props;


console.log(scenarioYears);

const [scenariosInputDatasetsObj, setScenariosInputDatasetsObj] = useState(data.input_datasets);
const [scenariosOutputDatasetsObj, setScenariosOutputDatasetsObj] = useState(data.output_datasets);

console.log(scenariosInputDatasetsObj);

scenariosInputDatasetsObj.forEach((element, index) => {
console.log(element);
});


const [openRemoveddDialog, setOpenRemovedDialog] = useState(false);
const [value, setValue] = React.useState(0);
Expand Down Expand Up @@ -239,7 +233,6 @@ export default function Scenario(props) {
useEffect(() => {
getDAtaTableList().then((data) => {
const tmp = [];
console.log(data);
data.map((item) => tmp.push({ 'url': item.url, 'label': item.name, 'id': item.id }));
setDataTableList(tmp);
});
Expand Down Expand Up @@ -384,14 +377,14 @@ export default function Scenario(props) {
tooltipText="A scenario year is a time step that has a duration of one year and is part of a scenario horizon."
hrefLink="http://openenergy-platform.org/ontology/oeo/OEO_00020097"
renderField={() => (
<CustomAutocomplete
<CustomAutocompleteWithoutAddNew
width="100%"
type="scenario year"
editHandler={HandleEditScenarioYear}
addNewHandler={HandleAddNNewScenarioYear}
showSelectedElements={true}
selectedElements={data.scenario_years}
manyItems optionsSet={scenarioYears}
manyItems
noTooltip
optionsSet={scenarioYears}
kind=''
handler={(e) => handleScenariosAutoCompleteChange(e, 'scenario_years', data.id)}
/>
Expand Down
3 changes: 3 additions & 0 deletions versions/changelogs/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

- REST-API: Retrieve oemetadata from database instead of comment on table. [(#1703)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1703)

- Scenario Bundle: Fix issues scenario years, a static list of years without the possibility to edit [(#1724)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1724)

- Scenario Comparison: Split "Descriptors" into Study & Scenario descriptors adding the missing study descriptors. Additionally remove scenario descriptors for study descriptor section list. [(#1721)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1721)


## Documentation updates

0 comments on commit acd4c85

Please sign in to comment.