@@ -9,11 +9,10 @@ import { useCallback, useEffect, useMemo } from 'react';
9
9
import { Grid } from '@mui/material' ;
10
10
import {
11
11
CustomFormProvider ,
12
- EquipmentType ,
13
12
SelectInput ,
14
13
TextInput ,
15
- UseStateBooleanReturn ,
16
14
useSnackMessage ,
15
+ UseStateBooleanReturn ,
17
16
} from '@gridsuite/commons-ui' ;
18
17
import { useForm } from 'react-hook-form' ;
19
18
import { yupResolver } from '@hookform/resolvers/yup' ;
@@ -22,45 +21,34 @@ import { EQUIPMENT_TYPE_FIELD } from 'components/utils/field-constants';
22
21
import { AppState } from 'redux/reducer' ;
23
22
import { UUID } from 'crypto' ;
24
23
import { dialogStyles } from '../styles/styles' ;
25
- import { ModificationDialog } from 'components/dialogs/commons/modificationDialog' ;
26
- import { getEmptySpreadsheetFormSchema , initialEmptySpreadsheetForm , SPREADSHEET_NAME } from './add-spreadsheet-form' ;
24
+ import { ModificationDialog , type ModificationDialogProps } from 'components/dialogs/commons/modificationDialog' ;
25
+ import {
26
+ type EmptySpreadsheetForm ,
27
+ getEmptySpreadsheetFormSchema ,
28
+ initialEmptySpreadsheetForm ,
29
+ SPREADSHEET_NAME ,
30
+ } from './add-spreadsheet-form' ;
27
31
import { addNewSpreadsheet } from './add-spreadsheet-utils' ;
28
32
import { COLUMN_TYPES } from 'components/custom-aggrid/custom-aggrid-header.type' ;
29
- import { ColumnDefinitionDto } from '../../types/spreadsheet.type' ;
33
+ import { ColumnDefinitionDto , SpreadsheetEquipmentType } from '../../types/spreadsheet.type' ;
30
34
import { v4 as uuid4 } from 'uuid' ;
31
35
32
36
interface AddEmptySpreadsheetDialogProps {
33
37
open : UseStateBooleanReturn ;
34
38
}
35
39
36
- const TABLES_TYPES = [
37
- EquipmentType . SUBSTATION ,
38
- EquipmentType . VOLTAGE_LEVEL ,
39
- EquipmentType . LINE ,
40
- EquipmentType . TWO_WINDINGS_TRANSFORMER ,
41
- EquipmentType . THREE_WINDINGS_TRANSFORMER ,
42
- EquipmentType . GENERATOR ,
43
- EquipmentType . LOAD ,
44
- EquipmentType . SHUNT_COMPENSATOR ,
45
- EquipmentType . STATIC_VAR_COMPENSATOR ,
46
- EquipmentType . BATTERY ,
47
- EquipmentType . HVDC_LINE ,
48
- EquipmentType . LCC_CONVERTER_STATION ,
49
- EquipmentType . VSC_CONVERTER_STATION ,
50
- EquipmentType . TIE_LINE ,
51
- EquipmentType . DANGLING_LINE ,
52
- EquipmentType . BUS ,
53
- EquipmentType . BUSBAR_SECTION ,
54
- ] ;
40
+ const TABLES_OPTIONS = Object . values ( SpreadsheetEquipmentType ) . map (
41
+ ( elementType ) => ( { id : elementType , label : elementType } ) as const
42
+ ) ;
55
43
56
- const DEFAULT_ID_COLUMN : ColumnDefinitionDto = {
44
+ const DEFAULT_ID_COLUMN = {
57
45
uuid : uuid4 ( ) as UUID ,
58
46
name : 'ID' ,
59
47
id : 'id' ,
60
48
type : COLUMN_TYPES . TEXT ,
61
49
formula : 'id' ,
62
50
visible : true ,
63
- } ;
51
+ } as const satisfies ColumnDefinitionDto ;
64
52
65
53
/**
66
54
* Dialog for creating an empty spreadsheet
@@ -88,21 +76,17 @@ export default function AddEmptySpreadsheetDialog({ open, ...dialogProps }: Read
88
76
reset ( initialEmptySpreadsheetForm ) ;
89
77
} , [ open . value , reset ] ) ;
90
78
91
- const onSubmit = useCallback (
92
- ( formData : any ) => {
79
+ const onSubmit = useCallback < ModificationDialogProps < EmptySpreadsheetForm > [ 'onSave' ] > (
80
+ ( formData ) => {
93
81
if ( ! studyUuid ) {
94
82
return ;
95
83
}
96
- const tabIndex = tablesDefinitions . length ;
97
- const tabName = formData [ SPREADSHEET_NAME ] ;
98
- const equipmentType = formData . equipmentType ;
99
-
100
84
addNewSpreadsheet ( {
101
85
studyUuid,
102
86
columns : [ DEFAULT_ID_COLUMN ] ,
103
- sheetType : equipmentType ,
104
- tabIndex,
105
- tabName,
87
+ sheetType : formData . equipmentType ,
88
+ tabIndex : tablesDefinitions . length ,
89
+ tabName : formData [ SPREADSHEET_NAME ] ,
106
90
spreadsheetsCollectionUuid : spreadsheetsCollectionUuid as UUID ,
107
91
dispatch,
108
92
snackError,
@@ -119,7 +103,7 @@ export default function AddEmptySpreadsheetDialog({ open, ...dialogProps }: Read
119
103
open = { open . value }
120
104
onClose = { open . setFalse }
121
105
onSave = { onSubmit }
122
- onClear = { ( ) => null }
106
+ onClear = { ( ) => { } }
123
107
PaperProps = { { sx : dialogStyles . dialogContent } }
124
108
{ ...dialogProps }
125
109
>
@@ -133,10 +117,7 @@ export default function AddEmptySpreadsheetDialog({ open, ...dialogProps }: Read
133
117
</ Grid >
134
118
< Grid item xs >
135
119
< SelectInput
136
- options = { Object . values ( TABLES_TYPES ) . map ( ( elementType ) => ( {
137
- id : elementType ,
138
- label : elementType ,
139
- } ) ) }
120
+ options = { TABLES_OPTIONS }
140
121
name = { EQUIPMENT_TYPE_FIELD }
141
122
label = "spreadsheet/create_new_spreadsheet/element_type"
142
123
size = "small"
0 commit comments