Skip to content

Commit fd53b40

Browse files
Facilitate the substations hierarchy selection in generators dispatch modification (#3101)
* Facilitate the substations hierarchy selection in generators dispatch modification Signed-off-by: Franck LECUYER <[email protected]>
1 parent cad4e56 commit fd53b40

File tree

4 files changed

+117
-7
lines changed

4 files changed

+117
-7
lines changed

src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-dialog.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const GenerationDispatchDialog = ({
9191
editData,
9292
currentNode,
9393
studyUuid,
94+
currentRootNetworkUuid,
9495
isUpdate,
9596
editDataFetchStatus,
9697
...dialogProps
@@ -169,7 +170,11 @@ const GenerationDispatchDialog = ({
169170
isDataFetching={isUpdate && editDataFetchStatus === FetchStatus.RUNNING}
170171
{...dialogProps}
171172
>
172-
<GenerationDispatchForm />
173+
<GenerationDispatchForm
174+
currentNode={currentNode}
175+
studyUuid={studyUuid}
176+
currentRootNetworkUuid={currentRootNetworkUuid}
177+
/>
173178
</ModificationDialog>
174179
</CustomFormProvider>
175180
);

src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-form.jsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,33 @@ import { FormattedMessage } from 'react-intl';
2222
import SubstationsGeneratorsOrderingPane from './substations-generators-ordering-pane';
2323
import GridItem from '../../commons/grid-item';
2424
import GridSection from '../../commons/grid-section';
25+
import { useEffect, useState } from 'react';
26+
import { fetchEquipmentsIds } from '../../../../services/study/network-map';
27+
28+
const GenerationDispatchForm = ({ currentNode, studyUuid, currentRootNetworkUuid }) => {
29+
const currentNodeUuid = currentNode?.id;
30+
31+
const [substations, setSubstations] = useState([]);
2532

26-
const GenerationDispatchForm = () => {
2733
const handleCoefficientValueChange = (id, value) => {
2834
return formatPercentageValue(value);
2935
};
3036

37+
useEffect(() => {
38+
if (studyUuid && currentNodeUuid && currentRootNetworkUuid) {
39+
fetchEquipmentsIds(
40+
studyUuid,
41+
currentNodeUuid,
42+
currentRootNetworkUuid,
43+
undefined,
44+
EQUIPMENT_TYPES.SUBSTATION,
45+
true
46+
).then((values) => {
47+
setSubstations(values.sort((a, b) => a.localeCompare(b)));
48+
});
49+
}
50+
}, [studyUuid, currentNodeUuid, currentRootNetworkUuid]);
51+
3152
const lossCoefficientField = (
3253
<FloatInput
3354
name={LOSS_COEFFICIENT}
@@ -112,7 +133,7 @@ const GenerationDispatchForm = () => {
112133
</Grid>
113134
<GridSection title="GeneratorsOrdering" />
114135
<Grid container direction="column" spacing={2} alignItems="start">
115-
<SubstationsGeneratorsOrderingPane />
136+
<SubstationsGeneratorsOrderingPane substations={substations} />
116137
</Grid>
117138
</Box>
118139
);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
import { AutocompleteInputProps, genHelperError } from '@gridsuite/commons-ui';
8+
9+
import { useController } from 'react-hook-form';
10+
import { SyntheticEvent } from 'react';
11+
import { Autocomplete, AutocompleteProps, TextField, TextFieldProps, Theme } from '@mui/material';
12+
13+
const styles = {
14+
autocomplete: (theme: Theme) => ({
15+
'.MuiAutocomplete-inputRoot': {
16+
display: 'flex',
17+
alignItems: 'flex-start',
18+
justifyContent: 'flex-start',
19+
flexWrap: 'nowrap',
20+
padding: '1px',
21+
paddingLeft: '5px',
22+
},
23+
'.Mui-expanded, .Mui-focused, .Mui-focusVisible': {
24+
width: 'inherit',
25+
background: theme.palette.tabBackground,
26+
flexWrap: 'wrap',
27+
},
28+
}),
29+
};
30+
31+
type SubstationsAutocompleteProps = Pick<AutocompleteProps<string, true, false, false>, 'disabled'> & {
32+
name: AutocompleteInputProps['name'];
33+
label?: TextFieldProps['label'];
34+
disabled?: boolean;
35+
substations: string[];
36+
};
37+
38+
export default function SubstationsAutocomplete({
39+
name,
40+
label,
41+
disabled,
42+
substations,
43+
...props
44+
}: SubstationsAutocompleteProps) {
45+
const {
46+
field: { onChange, value, ref },
47+
fieldState: { error },
48+
} = useController({ name });
49+
50+
const handleChange = (_: SyntheticEvent, value: string[]) => {
51+
onChange(value);
52+
};
53+
54+
return (
55+
<Autocomplete
56+
multiple
57+
disabled={disabled}
58+
value={value}
59+
onChange={handleChange}
60+
options={substations}
61+
size={'small'}
62+
sx={styles.autocomplete}
63+
renderInput={({ inputProps, ...rest }) => (
64+
<TextField
65+
inputRef={ref}
66+
inputProps={{ ...inputProps }}
67+
label={label}
68+
{...genHelperError(error?.message)}
69+
{...rest}
70+
/>
71+
)}
72+
autoHighlight={true}
73+
disableCloseOnSelect={true}
74+
{...props}
75+
/>
76+
);
77+
}

src/components/dialogs/network-modifications/generation-dispatch/substations-generators-ordering-pane.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2023, RTE (http://www.rte-france.com)
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -10,9 +10,11 @@ import { useIntl } from 'react-intl';
1010
import { useMemo } from 'react';
1111
import { useFieldArray } from 'react-hook-form';
1212
import { DndTable, DndColumnType } from '@gridsuite/commons-ui';
13+
import SubstationsAutocomplete from './substations-autocomplete.js';
1314

14-
const SubstationsGeneratorsOrderingPane = ({ id = SUBSTATIONS_GENERATORS_ORDERING }) => {
15+
const SubstationsGeneratorsOrderingPane = ({ substations }) => {
1516
const intl = useIntl();
17+
const id = SUBSTATIONS_GENERATORS_ORDERING;
1618

1719
const columnsDefinition = useMemo(() => {
1820
return [
@@ -21,7 +23,12 @@ const SubstationsGeneratorsOrderingPane = ({ id = SUBSTATIONS_GENERATORS_ORDERIN
2123
dataKey: SUBSTATION_IDS,
2224
initialValue: [],
2325
editable: true,
24-
type: DndColumnType.CHIP_ITEMS,
26+
type: DndColumnType.CUSTOM,
27+
component: (rowIndex) =>
28+
SubstationsAutocomplete({
29+
name: `${id}[${rowIndex}].${SUBSTATION_IDS}`,
30+
substations: substations,
31+
}),
2532
},
2633
].map((column) => ({
2734
...column,
@@ -30,7 +37,7 @@ const SubstationsGeneratorsOrderingPane = ({ id = SUBSTATIONS_GENERATORS_ORDERIN
3037
.toLowerCase()
3138
.replace(/^\w/, (c) => c.toUpperCase()),
3239
}));
33-
}, [intl]);
40+
}, [intl, substations, id]);
3441

3542
const useFieldArraySubstationsGeneratorsOrdering = useFieldArray({
3643
name: `${id}`,

0 commit comments

Comments
 (0)