-
Notifications
You must be signed in to change notification settings - Fork 19
/
factsheet.js
2965 lines (2763 loc) · 115 KB
/
factsheet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React, { useState, useEffect, useRef } from 'react';
import Grid from '@mui/material/Grid';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import TextField from '@mui/material/TextField';
import ColorToggleButton from './customSwapButton.js';
import CustomTabs from './customTabs.js';
import CustomAutocomplete from './customAutocomplete.js';
import CustomAutocompleteWithoutEdit from './customAutocompleteWithoutEdit';
import Scenario from './scenario.js';
import CustomTreeViewWithCheckBox from './customTreeViewWithCheckbox.js';
import Snackbar from '@mui/material/Snackbar';
import Typography from '@mui/material/Typography';
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
import axios from 'axios';
import { Link } from 'react-router-dom';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
import Stack from '@mui/material/Stack';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
import Fab from '@mui/material/Fab';
import AddIcon from '@mui/icons-material/Add';
import Checkbox from '@mui/material/Checkbox';
import FormGroup from '@mui/material/FormGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import conf from "../conf.json";
import { colors, Tooltip } from '@mui/material';
import HtmlTooltip from '../styles/oep-theme/components/tooltipStyles.js'
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
import { styled } from '@mui/material/styles';
import SaveIcon from '@mui/icons-material/Save';
import uuid from "react-uuid";
import Alert from '@mui/material/Alert';
import AlertTitle from '@mui/material/AlertTitle';
import CircularProgress from '@mui/material/CircularProgress';
import Badge from '@mui/material/Badge';
import { Route, Routes, useNavigate } from 'react-router-dom';
import ShareIcon from '@mui/icons-material/Share';
import sunburstKapsule from 'sunburst-chart';
import fromKapsule from 'react-kapsule';
import Select from '@mui/material/Select';
import CustomAutocompleteWithoutAddNew from './customAutocompleteWithoutAddNew.js';
import IconButton from '@mui/material/IconButton';
import Divider from '@mui/material/Divider';
import { makeStyles, Theme } from '@material-ui/core/styles';
import BreadcrumbsNavGrid from '../styles/oep-theme/components/breadcrumbsNavigation.js';
import TableContainer from '@mui/material/TableContainer';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import Toolbar from '@mui/material/Toolbar';
import { ContentTableCell, FirstRowTableCell } from '../styles/oep-theme/components/tableStyles.js';
import InfoListItem from '../styles/oep-theme/components/infoListItem.js'
import BundleScenariosGridItem from '../styles/oep-theme/components/editBundleScenariosForms.js';
import AttachmentIcon from '@mui/icons-material/Attachment';
import MenuBookOutlinedIcon from '@mui/icons-material/MenuBookOutlined';
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
import FeedOutlinedIcon from '@mui/icons-material/FeedOutlined';
import LinkIcon from '@mui/icons-material/Link';
import Chip from '@mui/material/Chip';
import ListAltOutlinedIcon from '@mui/icons-material/ListAltOutlined';
import Container from '@mui/material/Container';
import Backdrop from '@mui/material/Backdrop';
import CSRFToken from './csrfToken';
import '../styles/App.css';
import { TableRow } from '@mui/material';
import variables from '../styles/oep-theme/variables.js';
function TabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`vertical-tabpanel-${index}`}
aria-labelledby={`vertical-tab-${index}`}
{...other}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function Factsheet(props) {
const navigate = useNavigate();
const [activeStep, setActiveStep] = React.useState(0);
const steps = getSteps();
const { id, fsData } = props;
const [openSavedDialog, setOpenSavedDialog] = useState(false);
const [openUpdatedDialog, setOpenUpdatedDialog] = useState(false);
const [openExistDialog, setOpenExistDialog] = useState(false);
const [emptyAcronym, setEmptyAcronym] = useState(false);
const [notTheOwner, setNotTheOwner] = useState(false);
const [openRemoveddDialog, setOpenRemovedDialog] = useState(false);
const [mode, setMode] = useState(id === "new" ? "edit" : "overview");
const [factsheetObject, setFactsheetObject] = useState({});
const [factsheetName, setFactsheetName] = useState(id !== 'new' ? '' : '');
const [acronym, setAcronym] = useState(id !== 'new' ? fsData.acronym : '');
const [uid, setUID] = useState(id !== 'new' ? fsData.uid : '');
const [prevUID, setPrevUID] = useState(id !== 'new' ? fsData.acronym : '');
const [studyName, setStudyName] = useState(id !== 'new' ? fsData.study_name : '');
const [abstract, setAbstract] = useState(id !== 'new' ? fsData.abstract : '');
const [selectedSectors, setSelectedSectors] = useState(id !== 'new' ? fsData.sectors : []);
const [expandedSectors, setExpandedSectors] = useState(id !== 'new' ? [] : []);
const [expandedTechnologies, setExpandedTechnologies] = useState(id !== 'new' ? [] : []);
const [institutions, setInstitutions] = useState([]);
const [authors, setAuthors] = useState([]);
const [fundingSources, setFundingSources] = useState([]);
const [contactPersons, setContactPersons] = useState([]);
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 handleCloseBackDrop = () => {
setOpenBackDrop(false);
};
const handleOpenBackDrop = () => {
setOpenBackDrop(true);
};
const Sunburst = fromKapsule(sunburstKapsule);
const handleNext = () => {
setActiveStep((prevActiveStep) => prevActiveStep + 1);
};
const handleBack = () => {
setActiveStep((prevActiveStep) => prevActiveStep - 1);
};
const handleReset = () => {
setActiveStep(0);
};
const handleStepClick = (i) => {
setActiveStep(i);
};
const wrapInTooltip = (name, description, link) => <span> <HtmlTooltip
placement="top"
title={
<React.Fragment>
<Typography color="inherit" variant="caption">
Description of <b>{name}</b> from Open Energy Ontology (OEO): TDB ...
<br />
<a href={link}>More info from Open Enrgy Knowledge Graph (OEKG)...</a>
</Typography>
</React.Fragment>
}
>
<HelpOutlineIcon sx={{ fontSize: '24px', color: '#708696', marginLeft: '-10px' }} />
</HtmlTooltip>
<span
style={{ marginLeft: '5px', marginTop: '-20px' }}
>
{name}
</span>
</span>
// const [sectors, setSectors] = useState(sectors_json);
const myChartRef = useRef(0);
const [sectors, setSectors] = useState([]);
const [sectorDivisions, setSectorDivisions] = useState([]);
const [filteredSectors, setFilteredSectors] = useState([]);
const [selectedSectorDivisions, setSelectedSectorDivisions] = useState(id !== 'new' ? fsData.sector_divisions : []);
const [selectedInstitution, setSelectedInstitution] = useState(id !== 'new' ? fsData.institution : []);
const [selectedFundingSource, setSelectedFundingSource] = useState(id !== 'new' ? fsData.funding_sources : []);
const [selectedContactPerson, setselectedContactPerson] = useState(id !== 'new' ? fsData.contact_person : []);
const [scenarios, setScenarios] = useState(id !== 'new' ? fsData.scenarios : [{
id: uuid(),
name: '',
acronym: '',
abstract: '',
regions: [],
interacting_regions: [],
scenario_years: [],
descriptors: [],
input_datasets: [],
output_datasets: [],
}
]);
const [publications, setPublications] = useState(id !== 'new' ? fsData.publications : [{
id: uuid(),
report_title: '',
authors: [],
doi: '',
link_to_study_report: '',
date_of_publication: '',
}
]);
const [scenariosObject, setScenariosObject] = useState({});
const [selectedStudyKewords, setSelectedStudyKewords] = useState(id !== 'new' ? fsData.study_keywords : []);
const [selectedModels, setSelectedModels] = useState(id !== 'new' ? fsData.models : []);
const [selectedFrameworks, setSelectedFrameworks] = useState(id !== 'new' ? fsData.frameworks : []);
const [removeReport, setRemoveReport] = useState(false);
const [addedEntity, setAddedEntity] = useState(false);
const [openAddedDialog, setOpenAddedDialog] = React.useState(false);
const [openEditDialog, setOpenEditDialog] = React.useState(false);
const [editedEntity, setEditedEntity] = useState(false);
const [scenarioTabValue, setScenarioTabValue] = React.useState(0);
const [publicatioTabValue, setPublicationTabValue] = React.useState(0);
const [technologies, setTechnologies] = React.useState([]);
const [selectedTechnologies, setSelectedTechnologies] = useState(id !== 'new' ? fsData.technologies : []);
const [expandedTechnologyList, setExpandedTechnologyList] = useState([]);
const [scenarioDescriptors, setScenarioDescriptors] = React.useState([]);
const [selectedScenarioDescriptors, setSelectedScenarioDescriptors] = useState([]);
const [modelsList, setModelsList] = useState([]);
const getModelList = async () => {
const { data } = await axios.get(conf.toep + `api/v0/factsheet/models/`, {
headers: { 'X-CSRFToken': CSRFToken() }
});
return data;
};
useEffect(() => {
getModelList().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'url': item.url, 'name': item.model_name, 'id': item.id }));
setModelsList(tmp);
});
}, []);
const [frameworksList, setFrameworkList] = useState([]);
const getFrameworkList = async () => {
const { data } = await axios.get(conf.toep + `api/v0/factsheet/frameworks/`, {
headers: { 'X-CSRFToken': CSRFToken() }
});
return data;
};
useEffect(() => {
getFrameworkList().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'url': item.url, 'name': item.model_name, 'id': item.id }));
setFrameworkList(tmp);
});
}, []);
// See https://github.com/OpenEnergyPlatform/oekg/issues/19
const StudyKeywords = [
['resilience', 'https://openenergy-platform.org/ontology/oeo/OEO_00360015', 'Resilience is a disposition of a system that represents the capacity of a system to absorb disturbance and reorganize so as to retain essentially the same function, structure, and feedbacks.'],
['life cycle analysis', 'http://www.openenergy-platform.org/ontology/oeo/OEO_00330023', 'A life cycle assessment is a methodology to calculate and analyse environmental impacts of the life cycle of a material entity or process.'],
['CO2 emissions', 'https://openenergy-platform.org/ontology/oeo/OEO_00260007', 'A CO2 emission is an emission that releases carbon dioxide.'],
['Greenhouse gas emissions', 'https://openenergy-platform.org/ontology/oeo/OEO_00000199', 'A greenhouse gas emission is an emission that releases a greenhouse gas.'],
['100% renewables', 'https://openenergy-platform.org/ontology/oeo/OEO_00140133', 'A renewable energy share is a process attribute that indicates the fraction of renewable energy related to the total energy of an energy generation or consumption process.'],
['acceptance', 'https://openenergy-platform.org/ontology/oeo/OEO_00360000', 'Acceptance is a realizable entity that represents the attitude of a person or organisation with respect to a certain constructional, (infra)structural or political measure that may be realized in, affected by or results of complex processes like discussions, communications, transformative measures or former personal experiences.'],
['sufficiency', 'https://openenergy-platform.org/ontology/oeo/OEO_00010444', 'Sufficiency is a plan specification for reducing, in absolute terms, the consumption and production of end-use products and services through changes in social practices in order to comply with environmental sustainability while ensuring an adequate social foundation for all people.'],
['(changes in) demand', '', ''],
['degree of electrifiaction', 'https://openenergy-platform.org/ontology/oeo/OEO_00020254', 'Electrical energy share is a process attribute that indicates the fraction of electrical energy related to the total energy of an energy generation or consumption process.'],
['regionalisation', 'https://openenergy-platform.org/ontology/oeo/OEO_00340006', 'Regionalisation is a methodology to calculate spatially distributed energy producers and consumers with the aim to highlight regional differences in energy supply and potentials, particularly related to renewable energies.'],
['total gross electricity generation', 'https://openenergy-platform.org/ontology/oeo/OEO_00240012', 'Gross electricity generation is a process attribute that refers to the total amount of electrical energy produced in an electricity generation process.'],
['total net electricity generation', '', ''],
['peak electricity generation', 'https://github.com/OpenEnergyPlatform/ontology/issues/1837', ''],
['study report due to legal obligation', 'https://openenergy-platform.org/ontology/oeo/OEO_00020373', 'A study report due to legal obligation is a study report that is created beacause of a legal obligation.'],
['carbon neutrality', 'https://openenergy-platform.org/ontology/oeo/OEO_00360010', 'Climate neutrality criteria are measures to achieve a balance between the amount of greenhouse gases emitted and the amount removed from the atmosphere.'],
['negative emissions', 'https://openenergy-platform.org/ontology/oeo/OEO_00000293', 'Negative emission refers to the removal of greenhouse gases from the atmosphere, typically through various forms of carbon capture and storage.'],
['decarbonization pathways', 'https://openenergy-platform.org/ontology/oeo/OEO_00010212', 'Decarbonization pathways are strategic plans to reduce carbon emissions through various technological, structural, and behavioral changes.'],
['Flexibility', 'https://openenergy-platform.org/ontology/oeo/OEO_00360007', 'Flexibility in energy systems refers to the ability to adapt to changes in supply and demand, often through diverse generation and storage options.'],
['Efficiency', 'https://openenergy-platform.org/ontology/oeo/OEO_00140050', 'Efficiency value is the ratio of useful output to the total input in any system, often related to energy conversion processes.'],
['Efficiency', 'https://openenergy-platform.org/ontology/oeo/OEO_00140049', 'Energy conversion efficiency is the ratio of useful energy output to total energy input, important for evaluating the performance of energy systems.'],
['primary energy demand', 'https://openenergy-platform.org/ontology/oeo/OEO_00140146', 'Energy demand refers to the total amount of energy required by consumers, including both primary and final energy needs.'],
['final energy demand', 'https://openenergy-platform.org/ontology/oeo/OEO_00140146', 'Energy demand refers to the total amount of energy required by consumers, including both primary and final energy needs.'],
['control area', 'https://openenergy-platform.org/ontology/oeo/OEO_00360004', 'A control area is a supply grid that is under the responsibility of a transmission system operator and is a part of a supply grid.'],
['electricity grid', 'https://openenergy-platform.org/ontology/oeo/OEO_00000143', 'An electricity grid is a supply grid that distributes electrical energy / electricity.'],
['gas grid', 'https://openenergy-platform.org/ontology/oeo/OEO_00020004', 'A gas grid is a supply grid that distributes gaseous fuel, e.g. methane.'],
['heating grid', 'https://openenergy-platform.org/ontology/oeo/OEO_00020005', 'A heating grid is a supply grid that distributes thermal energy via circulating steam or liquids.'],
['scenario projection comparison', 'https://openenergy-platform.org/ontology/oeo/OEO_00360003', 'Scenario projection comparison is the analysis of different future scenarios to evaluate potential outcomes and impacts.'],
['model intercomparison study', 'https://openenergy-platform.org/ontology/oeo/OEO_00360002', 'Model intercomparison study involves comparing the outputs of different models to understand variability and improve accuracy in projections.'],
['policies and measures', 'https://openenergy-platform.org/ontology/oeo/OEO_00140151', 'Policy instrument is a means through which governments or organizations implement strategies to influence economic or social outcomes.'],
['emission scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00140151', 'An emission scenario is a scenario that describes a possible emission trajectory.'],
['economic scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00030008', ' An economic scenario is a scenario that describes a possible future state of economic systems.'],
['explorative scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00020248', 'An explorative scenario is a scenario that contains certain constraints / statements regarding measures that are taken in the near future / today to explore where these measures will lead to in a later future. The later future is not predefined in the scenario.'],
['climate scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00030007', 'A climate scenario is a scenario that describes a possible future state of a climate system.'],
['sufficiency scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00020345', 'A sufficiency scenario is a scenario that comprises sufficiency strategies.'],
['energy scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00030010', 'An energy scenario is a scenario that describes a possible future state of an energy system.'],
['reference scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00020314', 'A reference scenario is a scenario that is used as a reference, e.g. in a scenario comparison. It has the reference role.'],
['target driven scenario', 'https://openenergy-platform.org/ontology/oeo/OEO_00020247', 'A target driven scenario is a scenario that contains certain target constraints/ statements that in a possible future shall be realized. The path how the targets will be met is not predefined in the scenario.']
];
const handleScenarioTabChange = (event: React.SyntheticEvent, newValue: number) => {
setScenarioTabValue(newValue);
}
const handlePublicationTabChange = (event: React.SyntheticEvent, newValue: number) => {
setPublicationTabValue(newValue);
}
const populateFactsheetElements = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/populate_factsheets_elements/`);
return data;
};
const getNodeIds = (nodes) => {
let ids = [];
nodes?.forEach(({ value, children }) => {
ids = [...ids, value, ...getNodeIds(children)];
});
return ids;
};
useEffect(() => {
populateFactsheetElements().then((data) => {
function parse(arr) {
return arr.map(obj => {
Object.keys(obj).forEach(key => {
if (key === 'label') {
obj[key] = <span>
<HtmlTooltip
title={
<React.Fragment>
<Typography color="inherit" variant="subtitle1">
{obj.definition}
<br />
<a href={obj.iri}>More info from Open Energy Ontology (OEO)....</a>
</Typography>
</React.Fragment>
}
>
<InfoOutlinedIcon sx={{ color: '#708696', marginRight: "7px" }} />
</HtmlTooltip>
{obj.label}
</span>;
}
})
return obj;
})
}
const all_technologies = parse(data.technologies['children']);
setTechnologies(all_technologies);
// setTechnologies(data.technologies['children']);
setScenarioDescriptors(data.scenario_descriptors);
const sectors_with_tooltips = data.sectors.map(item =>
({
...item,
label: <span>
<HtmlTooltip
title={
<React.Fragment>
<Typography color="inherit" variant="subtitle1">
{item.sector_difinition}
<br />
<a href={item.iri}>More info from Open Energy Ontology (OEO)....</a>
</Typography>
</React.Fragment>
}
>
<InfoOutlinedIcon sx={{ color: '#708696', marginRight: "7px" }} />
</HtmlTooltip>
{item.label}
</span>
})
);
setSectors(sectors_with_tooltips);
setFilteredSectors(sectors_with_tooltips);
//setFilteredSectors([]);
const sector_d = data.sector_divisions;
sector_d.push({ "label": "Others", "name": "Others", "class": "Others", "value": "Others" });
setSectorDivisions(sector_d);
myChartRef.current = Sunburst
const sampleData = {
name: "root",
label: "Energy carrier",
children: []
}
setSunburstData(sampleData);
});
}, []);
const handleSaveFactsheet = () => {
setOpenBackDrop(true);
factsheetObjectHandler('name', factsheetName);
if (acronym !== '') {
if (id === 'new' && !isCreated) {
const new_uid = uuid()
axios.post(conf.toep + 'scenario-bundles/add/',
{
id: id,
uid: new_uid,
study_name: studyName,
name: factsheetName,
acronym: acronym,
abstract: abstract,
institution: JSON.stringify(selectedInstitution),
funding_source: JSON.stringify(selectedFundingSource),
contact_person: JSON.stringify(selectedContactPerson),
sector_divisions: JSON.stringify(selectedSectorDivisions),
sectors: JSON.stringify(selectedSectors),
expanded_sectors: JSON.stringify(expandedSectors),
technologies: JSON.stringify(selectedTechnologies),
study_keywords: JSON.stringify(selectedStudyKewords),
scenarios: JSON.stringify(scenarios),
publications: JSON.stringify(publications),
models: JSON.stringify(selectedModels),
frameworks: JSON.stringify(selectedFrameworks),
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.status === 200) {
// Handle successful response
if (response.data === 'Factsheet saved') {
navigate('/factsheet/fs/' + new_uid);
setIsCreated(true);
setOpenSavedDialog(true);
setUID(new_uid);
setOpenBackDrop(false);
}
else if (response.data === 'Factsheet exists') {
setOpenExistDialog(true);
setOpenBackDrop(false);
}
}
}).catch(error => {
if (error.response && error.response.status === 403) {
// Handle "Access Denied" error
const redirectUrl = conf.toep + "/user/login/?next=/scenario-bundles/id/new";
window.location.href = redirectUrl;
}
});
} else {
axios.get(conf.toep + `scenario-bundles/get/`, { params: { id: uid } }).then(res => {
axios.post(conf.toep + 'scenario-bundles/update/',
{
fsData: res.data,
id: id,
uid: uid,
study_name: studyName,
name: factsheetName,
acronym: acronym,
abstract: abstract,
institution: JSON.stringify(selectedInstitution),
funding_source: JSON.stringify(selectedFundingSource),
contact_person: JSON.stringify(selectedContactPerson),
sector_divisions: JSON.stringify(selectedSectorDivisions),
sectors: JSON.stringify(selectedSectors),
expanded_sectors: JSON.stringify(expandedSectors),
technologies: JSON.stringify(selectedTechnologies),
study_keywords: JSON.stringify(selectedStudyKewords),
scenarios: JSON.stringify(scenarios),
publications: JSON.stringify(publications),
models: JSON.stringify(selectedModels),
frameworks: JSON.stringify(selectedFrameworks),
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === "factsheet updated!") {
setUID(uid);
setOpenUpdatedDialog(true);
setOpenBackDrop(false);
}
else if (response.data === 'Factsheet exists') {
setOpenExistDialog(true);
setOpenBackDrop(false);
}
})
.catch(error => {
console.error('API Error:', error.message);
if (error.response && error.response.status === 403) {
// Handle "Access Denied" error
setNotTheOwner(true);
}
})
.finally(() => {
// Close the backdrop regardless of success or error
setOpenBackDrop(false);
});
});
}
} else {
setEmptyAcronym(true);
setOpenBackDrop(false);
}
};
const handleRemoveFactsheet = () => {
axios.post(conf.toep + 'scenario-bundles/delete/', null, { params: { id: id } }, { headers: { 'X-CSRFToken': CSRFToken() } }
).then(response => setOpenRemovedDialog(true));
}
const handleCloseSavedDialog = () => {
setOpenSavedDialog(false);
};
const handleCloseExistDialog = () => {
setOpenExistDialog(false);
};
const handleCloseUpdatedDialog = () => {
setOpenUpdatedDialog(false);
};
const handleCloseRemovedDialog = () => {
setOpenRemovedDialog(false);
};
const handleAcronym = e => {
setAcronym(e.target.value);
setEmptyAcronym(false);
factsheetObjectHandler('acronym', e.target.value);
};
const handleStudyName = e => {
setStudyName(e.target.value);
factsheetObjectHandler('study_name', e.target.value);
};
const handleAbstract = e => {
setAbstract(e.target.value);
factsheetObjectHandler('abstract', e.target.value);
};
const handleReportTitle = (event, index) => {
const updatePublications = [...publications];
updatePublications[index].report_title = event.target.value;
setPublications(updatePublications);
};
const handleDOI = (event, index) => {
const updatePublications = [...publications];
updatePublications[index].doi = event.target.value;
setPublications(updatePublications);
};
const handleFactsheetName = e => {
setFactsheetName(e.target.value);
factsheetObjectHandler('name', e.target.value);
};
// const handlePlaceOfPublication = e => {
// setPlaceOfPublication(e.target.value);
// factsheetObjectHandler('place_of_publication', e.target.value);
// };
const handleLinkToStudy = (event, index) => {
const updatePublications = [...publications];
updatePublications[index].link_to_study_report = event.target.value;
setPublications(updatePublications);
};
// const handleDateOfPublication = e => {
// setDateOfPublication(e.target.value);
// factsheetObjectHandler('date_of_publication', e.target.value);
// };
const handleClickOpenSavedDialog = () => {
openSavedDialog(true);
};
const handleClickOpenUpdatedDialog = () => {
openSavedDialog(true);
};
const handleClickOpenRemovedDialog = () => {
setOpenRemovedDialog(true);
};
const handleClickCloseRemovedDialog = () => {
setOpenRemovedDialog(false);
};
const handleAddedMessageClose = (event: React.SyntheticEvent | Event, reason?: string) => {
if (reason === 'clickaway') {
return;
}
setOpenAddedDialog(false);
};
const handleEditMessageClose = (event: React.SyntheticEvent | Event, reason?: string) => {
if (reason === 'clickaway') {
return;
}
setOpenEditDialog(false);
};
const handleScenariosInputChange = ({ target }) => {
const { name, value } = target;
const element = name.split('_')[0];
const id = name.split('_')[1];
const newScenarios = [...scenarios];
const obj = newScenarios.find(el => el.id === id);
if (obj)
obj[element] = value
setScenarios(newScenarios);
factsheetObjectHandler('scenarios', JSON.stringify(newScenarios));
};
const handleScenariosAutoCompleteChange = (selectedList, name, idx) => {
const newScenarios = [...scenarios];
const obj = newScenarios.find(el => el.id === idx);
if (obj)
obj[name] = selectedList
setScenarios(newScenarios);
};
const scenariosInputDatasetsHandler = (scenariosInputDatasetsList, id) => {
const newScenarios = [...scenarios];
const obj = newScenarios.find(el => el.id === id);
if (obj)
obj.input_datasets = scenariosInputDatasetsList
setScenarios(newScenarios);
factsheetObjectHandler('scenarios', JSON.stringify(newScenarios));
};
const scenariosOutputDatasetsHandler = (scenariosOutputDatasetsList, id) => {
const newScenarios = [...scenarios];
const obj = newScenarios.find(el => el.id === id);
if (obj)
obj.output_datasets = scenariosOutputDatasetsList
setScenarios(newScenarios);
factsheetObjectHandler('scenarios', JSON.stringify(newScenarios));
};
const handleAddScenario = () => {
const newScenarios = [...scenarios];
newScenarios.push({
id: uuid(),
name: '',
acronym: '',
abstract: '',
regions: [],
interacting_regions: [],
scenario_years: [],
descriptors: [],
input_datasets: [],
output_datasets: [],
});
setScenarios(newScenarios);
};
const handleAddPublication = () => {
const newPublications = [...publications];
newPublications.push({
id: uuid(),
report_title: '',
authors: [],
doi: '',
link_to_study_report: '',
date_of_publication: '',
});
setPublications(newPublications);
};
const removeScenario = (id) => {
let newScenarios = [...scenarios].filter((obj => obj.id !== id));;
setScenarios(newScenarios);
factsheetObjectHandler('scenarios', JSON.stringify(newScenarios));
setRemoveReport(true);
};
const handleSwap = (mode) => {
setMode(mode);
};
const factsheetObjectHandler = (key, obj) => {
let newFactsheetObject = factsheetObject;
newFactsheetObject[key] = obj
setFactsheetObject(newFactsheetObject);
}
const scenariosObjectHandler = (key, obj) => {
let newScenariosObject = scenariosObject;
newScenariosObject[key] = obj
setScenariosObject(newScenariosObject);
}
const renderFactsheet = () => {
return <div>'studyName'</div>
}
const getInstitution = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OEO.OEO_00000238' } });
return data;
};
const getFundingSources = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OEO.OEO_00090001' } });
return data;
};
const getContactPersons = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OEO.OEO_00000107' } });
return data;
};
const getAuthors = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OEO.OEO_00000064' } });
return data;
};
const getScenarioRegions = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OBO.BFO_0000006' } });
return data;
};
const getScenarioInteractingRegions = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OEO.OEO_00020036' } });
return data;
};
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' } });
return data;
};
const getFrameworks = async () => {
const { data } = await axios.get(conf.toep + `scenario-bundles/get_entities_by_type/`, { params: { entity_type: 'OEO.OEO_00000172' } });
return data;
};
useEffect(() => {
getInstitution().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }));
setInstitutions(tmp);
});
}, []);
useEffect(() => {
getFundingSources().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setFundingSources(tmp);
});
}, []);
useEffect(() => {
getContactPersons().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setContactPersons(tmp);
});
}, []);
useEffect(() => {
getAuthors().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setAuthors(tmp);
});
}, []);
useEffect(() => {
getScenarioRegions().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setScenarioRegions(tmp);
});
}, []);
useEffect(() => {
getScenarioInteractingRegions().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setScenarioInteractingRegions(tmp);
});
}, []);
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) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setModels(tmp);
});
}, []);
useEffect(() => {
getFrameworks().then((data) => {
const tmp = [];
data.map((item) => tmp.push({ 'iri': item.iri, 'name': item.name, 'id': item.name }))
setFrameworks(tmp);
});
}, []);
const HandleAddNewInstitution = (newElement) => {
axios.post(conf.toep + 'scenario-bundles/add_entities/',
{
entity_type: 'OEO.OEO_00000238',
entity_label: newElement.name,
entity_iri: newElement.iri
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'A new entity added!') {
setOpenAddedDialog(true);
setAddedEntity(['Institution', newElement.name]);
getInstitution().then((data) => {
const tmp = [];
data.map((item) => tmp.push(item))
setInstitutions(tmp);
});
}
});
}
const HandleEditInstitution = (oldElement, newElement, editIRI) => {
axios.post(conf.toep + 'scenario-bundles/update_an_entity/',
{
entity_type: 'OEO.OEO_00000238',
entity_label: oldElement,
new_entity_label: newElement,
entity_iri: editIRI
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'entity updated!') {
setOpenEditDialog(true);
setEditedEntity(['Institution', oldElement, newElement]);
getInstitution().then((data) => {
const tmp = [];
data.map((item) => tmp.push(item))
setInstitutions(tmp);
});
}
});
}
const HandleAddNewFundingSource = (newElement) => {
axios.post(conf.toep + 'scenario-bundlesrio-bundles/add_entities/',
{
entity_type: 'OEO.OEO_00090001',
entity_label: newElement.name,
entity_iri: newElement.iri
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'A new entity added!')
setOpenAddedDialog(true);
setAddedEntity(['Funding source', newElement.name]);
getFundingSources().then((data) => {
const tmp = [];
data.map((item) => tmp.push(item))
setFundingSources(tmp);
});
});
}
const HandleEditFundingSource = (oldElement, newElement, editIRI) => {
console.log(editIRI)
axios.post(conf.toep + 'scenario-bundles/update_an_entity/',
{
entity_type: 'OEO.OEO_00090001',
entity_label: oldElement,
new_entity_label: newElement,
entity_iri: editIRI
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'entity updated!') {
setOpenEditDialog(true);
setEditedEntity(['Funding source', oldElement, newElement]);
getFundingSources().then((data) => {
const tmp = [];
data.map((item) => tmp.push(item))
setFundingSources(tmp);
});
}
});
}
const HandleAddNewContactPerson = (newElement) => {
axios.post(conf.toep + 'scenario-bundles/add_entities/',
{
entity_type: 'OEO.OEO_00000107',
entity_label: newElement.name,
entity_iri: newElement.iri
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'A new entity added!')
setOpenAddedDialog(true);
setAddedEntity(['Contact person', newElement.name]);
getContactPersons().then((data) => {
const tmp = [];
data.map((item) => tmp.push(item))
setContactPersons(tmp);
});
});
}
const HandleEditContactPerson = (oldElement, newElement, editIRI) => {
axios.post(conf.toep + 'scenario-bundles/update_an_entity/',
{
entity_type: 'OEO.OEO_00000107',
entity_label: oldElement,
new_entity_label: newElement,
entity_iri: editIRI
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'entity updated!') {
setOpenEditDialog(true);
setEditedEntity(['Contact person', oldElement, newElement]);
getAuthors().then((data) => {
const tmp = [];
data.map((item) => tmp.push(item))
setAuthors(tmp);
});
}
});
}
const HandleAddNewAuthor = (newElement) => {
axios.post(conf.toep + 'scenario-bundles/add_entities/',
{
entity_type: 'OEO.OEO_00000064',
entity_label: newElement.name,
entity_iri: newElement.iri
},
{
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'A new entity added!')
setOpenAddedDialog(true);
setAddedEntity(['Author', newElement.name]);
getAuthors().then((data) => {