Skip to content

Commit 59809d1

Browse files
authored
Migration Typescript - components/dialogs/parameters (#2400)
Signed-off-by: LE SAULNIER Kevin <[email protected]>
1 parent 5f18ff7 commit 59809d1

File tree

68 files changed

+2502
-1743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2502
-1743
lines changed

src/components/diagrams/singleLineDiagram/single-line-diagram-content.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type EquipmentMenuState = {
6464
};
6565
interface SingleLineDiagramContentProps {
6666
readonly showInSpreadsheet: (menu: { equipmentId: string | null; equipmentType: EquipmentType | null }) => void;
67-
readonly studyUuid: string;
67+
readonly studyUuid: UUID;
6868
readonly svgType: DiagramType;
6969
readonly svg?: string;
7070
readonly svgMetadata?: SLDMetadata;
@@ -656,8 +656,6 @@ function SingleLineDiagramContent(props: SingleLineDiagramContentProps) {
656656
{equipmentToDelete && displayDeletionDialog()}
657657
{equipmentToConfigDynamicSimulationEvent && (
658658
<DynamicSimulationEventDialog
659-
studyUuid={studyUuid}
660-
currentNodeId={currentNode?.id ?? ''}
661659
equipmentId={equipmentToConfigDynamicSimulationEvent.equipmentId}
662660
equipmentType={equipmentToConfigDynamicSimulationEvent.equipmentType}
663661
onClose={() => handleCloseDynamicSimulationEventDialog()}

src/components/dialogs/dynamicsimulation/event/dynamic-simulation-event-dialog.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import { fetchDynamicSimulationEvent, saveDynamicSimulationEvent } from '../../.
2121
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
2222
import { FetchStatus } from '../../../../services/utils';
2323
import { EQUIPMENT_TYPES } from '../../../utils/equipment-types';
24+
import { useSelector } from 'react-redux';
25+
import { AppState } from 'redux/reducer';
2426

2527
export type DynamicSimulationEventDialogProps = {
26-
studyUuid: string;
27-
currentNodeId: string;
2828
equipmentId: string;
2929
equipmentType: EQUIPMENT_TYPES;
3030
onClose: () => void;
@@ -33,18 +33,12 @@ export type DynamicSimulationEventDialogProps = {
3333
} & Omit<DialogProps, 'open'>;
3434

3535
export const DynamicSimulationEventDialog = (props: DynamicSimulationEventDialogProps) => {
36-
const {
37-
studyUuid,
38-
currentNodeId,
39-
equipmentId,
40-
equipmentType,
41-
onClose,
42-
title,
43-
open: defaultOpen,
44-
...dialogProps
45-
} = props;
36+
const { equipmentId, equipmentType, onClose, title, open: defaultOpen, ...dialogProps } = props;
4637

4738
const { snackError } = useSnackMessage();
39+
const studyUuid = useSelector((state: AppState) => state.studyUuid);
40+
const currentNode = useSelector((state: AppState) => state.currentTreeNode);
41+
const currentNodeId = currentNode?.id;
4842
const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);
4943
const [event, setEvent] = useState<Event>();
5044

@@ -92,6 +86,9 @@ export const DynamicSimulationEventDialog = (props: DynamicSimulationEventDialog
9286

9387
// load event for equipment
9488
useEffect(() => {
89+
if (!studyUuid || !currentNodeId) {
90+
return;
91+
}
9592
setDataFetchStatus(FetchStatus.RUNNING);
9693
fetchDynamicSimulationEvent(studyUuid, currentNodeId, equipmentId).then((event) => {
9794
setDataFetchStatus(FetchStatus.SUCCEED);
@@ -120,6 +117,9 @@ export const DynamicSimulationEventDialog = (props: DynamicSimulationEventDialog
120117
// submit form
121118
const handleSubmit = useCallback(
122119
(formObj: { [KEY in EventPropertyName]: any }) => {
120+
if (!studyUuid || !currentNodeId) {
121+
return;
122+
}
123123
// formObj to EventProperty[]
124124
const propertyNames = Object.keys(formObj ?? {}) as EventPropertyName[];
125125

src/components/dialogs/export-dialog.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { getExportUrl } from '../../services/study/network';
3232
import { isBlankOrEmpty } from 'components/utils/validation-functions';
3333
import TextField from '@mui/material/TextField';
3434
import { useSelector } from 'react-redux';
35-
import { useParameterState } from './parameters/parameters.jsx';
35+
import { useParameterState } from './parameters/parameters';
3636
import { PARAM_DEVELOPER_MODE } from '../../utils/config-params';
3737

3838
const STRING_LIST = 'STRING_LIST';

src/components/dialogs/import-modification-dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const ImportModificationDialog: FunctionComponent<ImportModificationDialogProps>
3838
};
3939
const modificationUuidList = selectedElements.map((e) => e.id);
4040
// import selected modifications
41-
if (modificationUuidList.length > 0) {
42-
copyOrMoveModifications(studyUuid, currentNode?.id, modificationUuidList, copyInfos).catch((errmsg) => {
41+
if (modificationUuidList.length > 0 && studyUuid && currentNode) {
42+
copyOrMoveModifications(studyUuid, currentNode.id, modificationUuidList, copyInfos).catch((errmsg) => {
4343
snackError({
4444
messageTxt: errmsg,
4545
headerId: 'errDuplicateModificationMsg',

src/components/dialogs/parameters/common/limitreductions/columns-definitions.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD,
1313
} from 'utils/config-params';
1414
import yup from '../../../../utils/yup-config';
15-
import { NumberSchema } from 'yup';
1615

1716
export const LIMIT_REDUCTIONS_FORM = 'limitReductionsForm';
1817
export const VOLTAGE_LEVELS_FORM = 'voltageLevelsForm';
@@ -79,19 +78,6 @@ export const COLUMNS_DEFINITIONS_LIMIT_REDUCTIONS = [
7978
},
8079
];
8180

82-
const getLimitDurationsFormSchema = (nbLimits: number) => {
83-
let limitDurationsFormSchema: Record<string, NumberSchema> = {};
84-
for (let i = 0; i < nbLimits; i++) {
85-
limitDurationsFormSchema[LIMIT_DURATION_FORM + i] = yup
86-
.number()
87-
.min(0, 'RealPercentage')
88-
.max(1, 'RealPercentage')
89-
.nullable()
90-
.required();
91-
}
92-
return limitDurationsFormSchema;
93-
};
94-
9581
export const getLimitReductionsFormSchema = (nbTemporaryLimits: number) => {
9682
return yup
9783
.object()
@@ -100,14 +86,18 @@ export const getLimitReductionsFormSchema = (nbTemporaryLimits: number) => {
10086
yup.object().shape({
10187
[VOLTAGE_LEVELS_FORM]: yup.string(),
10288
[IST_FORM]: yup.number().min(0, 'RealPercentage').max(1, 'RealPercentage').nullable().required(),
103-
...getLimitDurationsFormSchema(nbTemporaryLimits),
89+
[LIMIT_DURATION_FORM]: yup
90+
.array()
91+
.length(nbTemporaryLimits)
92+
.of(yup.number().min(0, 'RealPercentage').max(1, 'RealPercentage').nullable().required())
93+
.required(),
10494
})
10595
),
10696
})
10797
.required();
10898
};
10999

110-
export const getSAParametersFromSchema = (limitReductions: ILimitReductionsByVoltageLevel[]) => {
100+
export const getSAParametersFromSchema = (limitReductions?: ILimitReductionsByVoltageLevel[]) => {
111101
const limitReductionsSchema = getLimitReductionsFormSchema(
112102
limitReductions ? limitReductions[0].temporaryLimitReductions.length : 0
113103
);

src/components/dialogs/parameters/dynamicsimulation/curve-parameters.jsx renamed to src/components/dialogs/parameters/dynamicsimulation/curve-parameters.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import CurveSelectorDialog from './curve/dialog/curve-selector-dialog';
1414
import { GlobalFilter } from '../../../spreadsheet/global-filter';
1515
import { useFieldArray, useFormContext } from 'react-hook-form';
1616
import { CustomAGGrid } from '@gridsuite/commons-ui';
17+
import { AgGridReact } from 'ag-grid-react';
18+
import { Curve } from './curve/dialog/curve-preview';
19+
import { ValueFormatterParams } from 'ag-grid-community';
1720

1821
const styles = {
1922
grid: {
@@ -44,27 +47,25 @@ export const emptyFormData = {
4447
[CURVES]: [],
4548
};
4649

47-
const CurveParameters = ({ path }) => {
50+
const CurveParameters = ({ path }: { path: string }) => {
4851
const intl = useIntl();
4952
const [selectedRowsLength, setSelectedRowsLength] = useState(0);
5053

5154
const { control } = useFormContext();
52-
const {
53-
fields: rowData,
54-
append,
55-
remove,
56-
} = useFieldArray({
55+
const { fields, append, remove } = useFieldArray({
5756
control,
5857
name: `${path}.${CURVES}`,
5958
});
6059

60+
const rowData = fields as unknown as Curve[]; //TODO fix in a better way if possible
61+
6162
// handle open/close/append curve selector dialog
6263
const [open, setOpen] = useState(false);
6364
const handleClose = useCallback(() => {
6465
setOpen((prevState) => !prevState);
6566
}, []);
6667
const handleAppend = useCallback(
67-
(newCurves) => {
68+
(newCurves: Curve[]) => {
6869
// do save here
6970
const notYetAddedCurves = newCurves.filter(
7071
// use functional keys to lookup
@@ -87,9 +88,9 @@ const CurveParameters = ({ path }) => {
8788
}, []);
8889

8990
const handleDelete = useCallback(() => {
90-
const selectedRows = gridRef.current.api.getSelectedRows();
91+
const selectedRows = gridRef.current?.api.getSelectedRows();
9192

92-
const indexesToRemove = selectedRows.map((elem) =>
93+
const indexesToRemove = selectedRows?.map((elem) =>
9394
// use functional keys to lookup
9495
rowData.findIndex(
9596
(row) => elem[EQUIPMENT_ID] === row[EQUIPMENT_ID] && elem[VARIABLE_ID] === row[VARIABLE_ID]
@@ -106,7 +107,7 @@ const CurveParameters = ({ path }) => {
106107

107108
// curve grid configuration
108109
const theme = useTheme();
109-
const gridRef = useRef();
110+
const gridRef = useRef<AgGridReact>(null);
110111

111112
const columnDefs = useMemo(() => {
112113
return [
@@ -126,7 +127,7 @@ const CurveParameters = ({ path }) => {
126127
headerName: intl.formatMessage({
127128
id: 'DynamicSimulationCurveVariableHeader',
128129
}),
129-
valueFormatter: (params) =>
130+
valueFormatter: (params: ValueFormatterParams) =>
130131
intl.formatMessage({
131132
id: `variables.${params.value}`,
132133
}),
@@ -147,8 +148,8 @@ const CurveParameters = ({ path }) => {
147148
}, []);
148149

149150
const onSelectionChanged = useCallback(() => {
150-
const selectedRows = gridRef.current.api.getSelectedRows();
151-
setSelectedRowsLength(selectedRows.length);
151+
const selectedRows = gridRef.current?.api.getSelectedRows();
152+
setSelectedRowsLength(selectedRows?.length ?? 0);
152153
}, []);
153154

154155
return (
@@ -181,7 +182,6 @@ const CurveParameters = ({ path }) => {
181182
<Grid item xs>
182183
<Box sx={styles.grid}>
183184
<CustomAGGrid
184-
name={`${path}.${CURVES}`}
185185
ref={gridRef}
186186
rowData={rowData}
187187
columnDefs={columnDefs}

src/components/dialogs/parameters/dynamicsimulation/curve/common/checkbox-select.jsx renamed to src/components/dialogs/parameters/dynamicsimulation/curve/common/checkbox-select.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { Checkbox, MenuItem, Select } from '@mui/material';
8+
import { Checkbox, MenuItem, Select, SelectChangeEvent } from '@mui/material';
99
import ListItemText from '@mui/material/ListItemText';
10-
import { useCallback, useState } from 'react';
10+
import { FunctionComponent, useCallback, useState } from 'react';
1111
import { useIntl } from 'react-intl';
1212

1313
const ITEM_HEIGHT = 48;
@@ -25,7 +25,15 @@ const MenuProps = {
2525
const CHECK_ALL = { label: 'SelectAll', value: 'check_all' };
2626
const UNCHECK_ALL = { label: 'UnselectAll', value: 'uncheck_all' };
2727

28-
const CheckboxSelect = ({
28+
interface CheckBoxSelectProps {
29+
options: string[];
30+
getOptionLabel: (label: string) => string;
31+
onChange: (newSelectedOption: string[]) => void;
32+
value: string[];
33+
disabled: boolean;
34+
}
35+
36+
const CheckboxSelect: FunctionComponent<CheckBoxSelectProps> = ({
2937
options,
3038
getOptionLabel: defaultGetOptionLabel,
3139
onChange,
@@ -43,11 +51,13 @@ const CheckboxSelect = ({
4351
}
4452

4553
const handleChange = useCallback(
46-
(event) => {
54+
(event: SelectChangeEvent<string[]>) => {
4755
const {
48-
target: { value: values },
56+
target: { value: eventValue },
4957
} = event;
50-
let newSelectedOptions;
58+
const values = Array.isArray(eventValue) ? eventValue : [eventValue];
59+
60+
let newSelectedOptions: string[];
5161
if (values.find((elem) => elem === CHECK_ALL.value)) {
5262
// must check all items
5363
newSelectedOptions = options;
@@ -67,7 +77,7 @@ const CheckboxSelect = ({
6777
);
6878

6979
const getOptionLabel = useCallback(
70-
(option) => {
80+
(option: string) => {
7181
return defaultGetOptionLabel(option);
7282
},
7383
[defaultGetOptionLabel]
@@ -94,14 +104,14 @@ const CheckboxSelect = ({
94104
sx={{ width: '100%' }}
95105
disabled={disabled}
96106
>
97-
<MenuItem size={'small'} key={CHECK_ALL.value} value={CHECK_ALL.value}>
107+
<MenuItem key={CHECK_ALL.value} value={CHECK_ALL.value}>
98108
<ListItemText primary={intl.formatMessage({ id: CHECK_ALL.label })} />
99109
</MenuItem>
100-
<MenuItem size={'small'} key={UNCHECK_ALL.value} value={UNCHECK_ALL.value}>
110+
<MenuItem key={UNCHECK_ALL.value} value={UNCHECK_ALL.value}>
101111
<ListItemText primary={intl.formatMessage({ id: UNCHECK_ALL.label })} />
102112
</MenuItem>
103113
{options.map((option) => (
104-
<MenuItem size={'small'} key={option} value={option}>
114+
<MenuItem key={option} value={option}>
105115
<Checkbox checked={selectedOptions.indexOf(option) > -1} />
106116
<ListItemText>{getOptionLabel(option)}</ListItemText>
107117
</MenuItem>

0 commit comments

Comments
 (0)