6
6
*/
7
7
8
8
import { useCallback } from 'react' ;
9
- import {
10
- type EquipmentFetcher ,
11
- type SpreadsheetEquipmentsByNodes ,
12
- SpreadsheetEquipmentType ,
13
- } from '../types/spreadsheet.type' ;
9
+ import { type SpreadsheetEquipmentsByNodes , type SpreadsheetEquipmentType } from '../types/spreadsheet.type' ;
14
10
import type { UUID } from 'crypto' ;
15
11
import { useDispatch , useSelector } from 'react-redux' ;
16
12
import { type AppState } from '../../../redux/reducer' ;
17
13
import { loadEquipments } from '../../../redux/actions' ;
18
14
import { useSnackMessage } from '@gridsuite/commons-ui' ;
19
- import {
20
- fetchBatteries ,
21
- fetchBusbarSections ,
22
- fetchBuses ,
23
- fetchDanglingLines ,
24
- fetchGenerators ,
25
- fetchHvdcLines ,
26
- fetchLccConverterStations ,
27
- fetchLines ,
28
- fetchLoads ,
29
- fetchShuntCompensators ,
30
- fetchStaticVarCompensators ,
31
- fetchSubstations ,
32
- fetchThreeWindingsTransformers ,
33
- fetchTieLines ,
34
- fetchTwoWindingsTransformers ,
35
- fetchVoltageLevels ,
36
- fetchVscConverterStations ,
37
- } from '../../../services/study/network' ;
15
+ import { fetchNetworkElementsInfos } from '../../../services/study/network' ;
38
16
import { mapSpreadsheetEquipments } from '../../../utils/spreadsheet-equipments-mapper' ;
17
+ import { EQUIPMENT_INFOS_TYPES } from '../../utils/equipment-types' ;
39
18
40
- const getFetcher = ( equipmentType : SpreadsheetEquipmentType ) : EquipmentFetcher => {
41
- switch ( equipmentType ) {
42
- case SpreadsheetEquipmentType . SUBSTATION :
43
- return fetchSubstations ;
44
- case SpreadsheetEquipmentType . VOLTAGE_LEVEL :
45
- return fetchVoltageLevels ;
46
- case SpreadsheetEquipmentType . LINE :
47
- return fetchLines ;
48
- case SpreadsheetEquipmentType . TIE_LINE :
49
- return fetchTieLines ;
50
- case SpreadsheetEquipmentType . TWO_WINDINGS_TRANSFORMER :
51
- return fetchTwoWindingsTransformers ;
52
- case SpreadsheetEquipmentType . THREE_WINDINGS_TRANSFORMER :
53
- return fetchThreeWindingsTransformers ;
54
- case SpreadsheetEquipmentType . HVDC_LINE :
55
- return fetchHvdcLines ;
56
- case SpreadsheetEquipmentType . GENERATOR :
57
- return fetchGenerators ;
58
- case SpreadsheetEquipmentType . BATTERY :
59
- return fetchBatteries ;
60
- case SpreadsheetEquipmentType . LOAD :
61
- return fetchLoads ;
62
- case SpreadsheetEquipmentType . SHUNT_COMPENSATOR :
63
- return fetchShuntCompensators ;
64
- case SpreadsheetEquipmentType . DANGLING_LINE :
65
- return fetchDanglingLines ;
66
- case SpreadsheetEquipmentType . STATIC_VAR_COMPENSATOR :
67
- return fetchStaticVarCompensators ;
68
- case SpreadsheetEquipmentType . VSC_CONVERTER_STATION :
69
- return fetchVscConverterStations ;
70
- case SpreadsheetEquipmentType . LCC_CONVERTER_STATION :
71
- return fetchLccConverterStations ;
72
- case SpreadsheetEquipmentType . BUS :
73
- return fetchBuses ;
74
- case SpreadsheetEquipmentType . BUSBAR_SECTION :
75
- return fetchBusbarSections ;
76
- }
77
- } ;
78
-
79
- export const useFetchEquipment = ( type : SpreadsheetEquipmentType ) => {
19
+ export function useFetchEquipment ( type : SpreadsheetEquipmentType ) {
80
20
const dispatch = useDispatch ( ) ;
81
21
const { snackError } = useSnackMessage ( ) ;
82
22
const studyUuid = useSelector ( ( state : AppState ) => state . studyUuid ) ;
@@ -91,7 +31,14 @@ export const useFetchEquipment = (type: SpreadsheetEquipmentType) => {
91
31
} ;
92
32
93
33
nodeIds . forEach ( ( nodeId ) => {
94
- const promise = getFetcher ( type ) ( studyUuid , nodeId as UUID , currentRootNetworkUuid , [ ] ) ;
34
+ const promise = fetchNetworkElementsInfos (
35
+ studyUuid ,
36
+ nodeId ,
37
+ currentRootNetworkUuid ,
38
+ [ ] ,
39
+ type ,
40
+ EQUIPMENT_INFOS_TYPES . TAB . type
41
+ ) ;
95
42
fetcherPromises . push ( promise ) ;
96
43
promise
97
44
. then ( ( results ) => {
@@ -128,8 +75,8 @@ export const useFetchEquipment = (type: SpreadsheetEquipmentType) => {
128
75
} ) ;
129
76
}
130
77
} ,
131
- [ dispatch , mapEquipments , snackError , studyUuid , type ]
78
+ [ dispatch , snackError , studyUuid , type ]
132
79
) ;
133
80
134
81
return { fetchNodesEquipmentData } ;
135
- } ;
82
+ }
0 commit comments