Skip to content

Commit 9b5883a

Browse files
Replace a NAD with another in the same card (#3207)
Signed-off-by: BOUTIER Charly <[email protected]>
1 parent 6ebf003 commit 9b5883a

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

src/components/diagrams/diagram-card.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ interface DiagramCardProps extends ReactGridLayoutCustomChildComponentProps {
4141
createDiagram: (diagram: DiagramParams) => void;
4242
updateDiagram: (diagram: Diagram) => void;
4343
updateDiagramPositions: (diagram: DiagramParams) => void;
44-
onLoad: (elementUuid: UUID, elementType: ElementType, elementName: string) => void;
4544
key: string; // Required for React Grid Layout to identify the component
4645
}
4746

@@ -58,7 +57,6 @@ export const DiagramCard = forwardRef((props: DiagramCardProps, ref: Ref<HTMLDiv
5857
createDiagram,
5958
updateDiagram,
6059
updateDiagramPositions,
61-
onLoad,
6260
...reactGridLayoutCustomChildComponentProps
6361
} = props;
6462
const { style, children, ...otherProps } = reactGridLayoutCustomChildComponentProps;
@@ -134,6 +132,25 @@ export const DiagramCard = forwardRef((props: DiagramCardProps, ref: Ref<HTMLDiv
134132
[diagram, updateDiagramPositions]
135133
);
136134

135+
const handleReplaceNad = useCallback(
136+
(elementUuid: UUID, elementType: ElementType, elementName: string) => {
137+
if (diagram.type === DiagramType.NETWORK_AREA_DIAGRAM) {
138+
updateDiagram({
139+
...diagram,
140+
name: elementName,
141+
nadConfigUuid: elementType === ElementType.DIAGRAM_CONFIG ? elementUuid : undefined,
142+
filterUuid: elementType === ElementType.FILTER ? elementUuid : undefined,
143+
initializationNadConfigUuid: undefined,
144+
voltageLevelIds: [],
145+
voltageLevelToExpandIds: [],
146+
voltageLevelToOmitIds: [],
147+
positions: [],
148+
});
149+
}
150+
},
151+
[diagram, updateDiagram]
152+
);
153+
137154
// This function is called by the diagram's contents, when they get their sizes from the backend.
138155
const setDiagramSize = useCallback((diagramId: UUID, diagramType: DiagramType, width: number, height: number) => {
139156
console.log('TODO setDiagramSize', diagramId, diagramType, width, height);
@@ -207,7 +224,7 @@ export const DiagramCard = forwardRef((props: DiagramCardProps, ref: Ref<HTMLDiv
207224
visible={visible}
208225
isEditNadMode={diagramsInEditMode}
209226
onToggleEditNadMode={(isEditMode) => setDiagramsInEditMode(isEditMode)}
210-
onLoadNad={onLoad}
227+
onLoadNad={handleReplaceNad}
211228
onExpandVoltageLevel={handleExpandVoltageLevelId}
212229
onAddVoltageLevel={handleAddVoltageLevel}
213230
onExpandAllVoltageLevels={handleExpandAllVoltageLevels}

src/components/diagrams/diagram-controls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ const DiagramControls: React.FC<DiagramControlsProps> = ({
215215
<SaveIcon sx={styles.icon} />
216216
</IconButton>
217217
</Tooltip>
218-
<Tooltip title={<FormattedMessage id={'importFromGridExplore'} />}>
218+
<Tooltip title={<FormattedMessage id={'importAndReplaceFromGridExplore'} />}>
219219
<IconButton sx={styles.actionIcon} onClick={handleClickLoadIcon}>
220220
<UploadIcon sx={styles.icon} />
221221
</IconButton>

src/components/diagrams/diagram-grid-layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ function DiagramGridLayout({ studyUuid, showInSpreadsheet, showGrid, visible }:
477477
createDiagram={createDiagram}
478478
updateDiagram={updateDiagram}
479479
updateDiagramPositions={updateDiagramPositions}
480-
onLoad={handleLoadNad}
481480
/>
482481
);
483482
})}

src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@
11911191
"elementSelection": "Element selection",
11921192
"addNetworkModification": "Add a network modification",
11931193
"importFromGridExplore": "Import from GridExplore",
1194+
"importAndReplaceFromGridExplore": "Import and replace from GridExplore",
11941195
"SaveToGridexplore": "Save to GridExplore",
11951196
"SaveToGridexploreError": "An error occurred while saving to GridExplore",
11961197
"diagramConfigCreationMsg": "Network area diagram created in {directory}",

src/translations/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@
11891189
"elementSelection": "Sélection d'un élément",
11901190
"addNetworkModification": "Ajouter une modification de réseau",
11911191
"importFromGridExplore": "Importer de GridExplore",
1192+
"importAndReplaceFromGridExplore": "Importer et remplacer à partir de GridExplore",
11921193
"SaveToGridexplore": "Enregistrer dans GridExplore",
11931194
"SaveToGridexploreError": "Une erreur est survenue lors de la sauvegarde dans GridExplore",
11941195
"diagramConfigCreationMsg": "Création de l'image nodale de zone dans {directory}",

0 commit comments

Comments
 (0)