Skip to content

Commit 9899df9

Browse files
Rename SelectionForCopy for confusion with common-ui one's (#2419)
1 parent 754908a commit 9899df9

File tree

5 files changed

+81
-73
lines changed

5 files changed

+81
-73
lines changed

src/components/graph/menus/create-node-menu.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { NodeInsertModes } from '../nodes/node-insert-modes';
1515
import { CustomDialog } from '../../utils/custom-dialog';
1616
import { CustomNestedMenuItem } from '../../utils/custom-nested-menu';
1717
import { BUILD_STATUS } from '../../network/constants';
18-
import { AppState, CurrentTreeNode } from 'redux/reducer';
18+
import { type AppState, type CurrentTreeNode, type NodeSelectionForCopy } from 'redux/reducer';
1919
import { UUID } from 'crypto';
2020
import NetworkModificationTreeModel from '../network-modification-tree-model';
2121
import { CopyType } from 'components/network-modification.type';
@@ -47,7 +47,7 @@ interface CreateNodeMenuProps {
4747
handleUnbuildNode: (element: CurrentTreeNode) => void;
4848
handleExportCaseOnNode: (node: CurrentTreeNode) => void;
4949
activeNode: CurrentTreeNode;
50-
selectionForCopy: { sourceStudyUuid: string; nodeId: UUID; copyType: CopyType; allChildrenIds: string[] };
50+
nodeSelectionForCopy: NodeSelectionForCopy;
5151
handleCopyNode: (nodeId: string) => void;
5252
handleCutNode: (nodeId: UUID | null) => void;
5353
handlePasteNode: (activeNode: string, insertMode: NodeInsertModes) => void;
@@ -104,7 +104,7 @@ const CreateNodeMenu: React.FC<CreateNodeMenuProps> = ({
104104
handleNodeRemoval,
105105
handleExportCaseOnNode,
106106
activeNode,
107-
selectionForCopy,
107+
nodeSelectionForCopy,
108108
handleCopyNode,
109109
handleCutNode,
110110
handlePasteNode,
@@ -199,18 +199,18 @@ const CreateNodeMenu: React.FC<CreateNodeMenuProps> = ({
199199
function isNodePastingAllowed() {
200200
return (
201201
!mapDataLoading &&
202-
((selectionForCopy.nodeId !== activeNode.id && selectionForCopy.copyType === CopyType.NODE_CUT) ||
203-
selectionForCopy.copyType === CopyType.NODE_COPY)
202+
((nodeSelectionForCopy.nodeId !== activeNode.id && nodeSelectionForCopy.copyType === CopyType.NODE_CUT) ||
203+
nodeSelectionForCopy.copyType === CopyType.NODE_COPY)
204204
);
205205
}
206206

207207
function isSubtreePastingAllowed() {
208208
return (
209209
!mapDataLoading &&
210-
((selectionForCopy.nodeId !== activeNode.id &&
211-
!selectionForCopy.allChildrenIds?.includes(activeNode.id) &&
212-
selectionForCopy.copyType === CopyType.SUBTREE_CUT) ||
213-
selectionForCopy.copyType === CopyType.SUBTREE_COPY)
210+
((nodeSelectionForCopy.nodeId !== activeNode.id &&
211+
!nodeSelectionForCopy.allChildrenIds?.includes(activeNode.id) &&
212+
nodeSelectionForCopy.copyType === CopyType.SUBTREE_CUT) ||
213+
nodeSelectionForCopy.copyType === CopyType.SUBTREE_COPY)
214214
);
215215
}
216216

@@ -227,11 +227,13 @@ const CreateNodeMenu: React.FC<CreateNodeMenuProps> = ({
227227
}
228228

229229
function isNodeAlreadySelectedForCut() {
230-
return selectionForCopy?.nodeId === activeNode.id && selectionForCopy?.copyType === CopyType.NODE_CUT;
230+
return nodeSelectionForCopy?.nodeId === activeNode.id && nodeSelectionForCopy?.copyType === CopyType.NODE_CUT;
231231
}
232232

233233
function isSubtreeAlreadySelectedForCut() {
234-
return selectionForCopy?.nodeId === activeNode.id && selectionForCopy?.copyType === CopyType.SUBTREE_CUT;
234+
return (
235+
nodeSelectionForCopy?.nodeId === activeNode.id && nodeSelectionForCopy?.copyType === CopyType.SUBTREE_CUT
236+
);
235237
}
236238
function isNodeHasChildren(node: CurrentTreeNode, treeModel: NetworkModificationTreeModel | null): boolean {
237239
return treeModel?.treeNodes.some((item) => item.parentId === node.id) ?? false;

src/components/graph/nodes/network-modification-node.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const styles = {
127127

128128
const NetworkModificationNode = (props: NodeProps<ModificationNode>) => {
129129
const currentNode = useSelector((state: AppState) => state.currentTreeNode);
130-
const selectionForCopy = useSelector((state: AppState) => state.selectionForCopy);
130+
const selectionForCopy = useSelector((state: AppState) => state.nodeSelectionForCopy);
131131

132132
const isSelectedNode = () => {
133133
return props.id === currentNode?.id;

src/components/network-modification-tree-pane.jsx

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
networkModificationTreeNodesUpdated,
1414
removeNotificationByNode,
1515
networkModificationHandleSubtree,
16-
setSelectionForCopy,
16+
setNodeSelectionForCopy,
1717
resetLogsFilter,
1818
} from '../redux/actions';
1919
import { useDispatch, useSelector } from 'react-redux';
@@ -65,11 +65,11 @@ const usePreviousTreeDisplay = (display, width) => {
6565
return ref.current;
6666
};
6767

68-
const noSelectionForCopy = {
68+
const noNodeSelectionForCopy = {
6969
sourceStudyUuid: null,
7070
nodeId: null,
7171
copyType: null,
72-
allChilddrenIds: null,
72+
allChildrenIds: null,
7373
};
7474

7575
const HTTP_MAX_NODE_BUILDS_EXCEEDED_MESSAGE = 'MAX_NODE_BUILDS_EXCEEDED';
@@ -82,10 +82,10 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
8282
const isInitiatingCopyTab = useRef(false);
8383
const [nodesToRestore, setNodesToRestore] = useState([]);
8484

85-
const dispatchSelectionForCopy = useCallback(
85+
const dispatchNodeSelectionForCopy = useCallback(
8686
(sourceStudyUuid, nodeId, copyType) => {
8787
dispatch(
88-
setSelectionForCopy({
88+
setNodeSelectionForCopy({
8989
sourceStudyUuid: sourceStudyUuid,
9090
nodeId: nodeId,
9191
copyType: copyType,
@@ -101,13 +101,13 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
101101
console.info('message received from broadcast channel');
102102
console.info(event.data);
103103
isInitiatingCopyTab.current = false;
104-
if (JSON.stringify(noSelectionForCopy) === JSON.stringify(event.data)) {
105-
dispatch(setSelectionForCopy(noSelectionForCopy));
104+
if (JSON.stringify(noNodeSelectionForCopy) === JSON.stringify(event.data)) {
105+
dispatch(setNodeSelectionForCopy(noNodeSelectionForCopy));
106106
snackInfo({
107107
messageId: 'CopiedNodeInvalidationMessage',
108108
});
109109
} else {
110-
dispatchSelectionForCopy(event.data.sourceStudyUuid, event.data.nodeId, event.data.copyType);
110+
dispatchNodeSelectionForCopy(event.data.sourceStudyUuid, event.data.nodeId, event.data.copyType);
111111
}
112112
};
113113
return broadcast;
@@ -121,7 +121,7 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
121121
//If the tab is closed we want to invalidate the copy on all tabs because we won't able to track the node modification
122122
window.addEventListener('beforeunload', (event) => {
123123
if (true === isInitiatingCopyTab.current) {
124-
broadcastChannel.postMessage(noSelectionForCopy);
124+
broadcastChannel.postMessage(noNodeSelectionForCopy);
125125
}
126126
});
127127
//broadcastChannel doesn't change
@@ -133,9 +133,9 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
133133
const currentNodeRef = useRef();
134134
currentNodeRef.current = currentNode;
135135

136-
const selectionForCopy = useSelector((state) => state.selectionForCopy);
137-
const selectionForCopyRef = useRef();
138-
selectionForCopyRef.current = selectionForCopy;
136+
const selectionForCopy = useSelector((state) => state.nodeSelectionForCopy);
137+
const nodeSelectionForCopyRef = useRef();
138+
nodeSelectionForCopyRef.current = selectionForCopy;
139139

140140
const isModificationsDrawerOpen = useSelector((state) => state.isModificationsDrawerOpen);
141141
const isEventScenarioDrawerOpen = useSelector((state) => state.isEventScenarioDrawerOpen);
@@ -158,26 +158,26 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
158158

159159
const isSubtreeImpacted = useCallback(
160160
(nodes) =>
161-
(selectionForCopyRef.current.copyType === CopyType.SUBTREE_COPY ||
162-
selectionForCopyRef.current.copyType === CopyType.SUBTREE_CUT) &&
161+
(nodeSelectionForCopyRef.current.copyType === CopyType.SUBTREE_COPY ||
162+
nodeSelectionForCopyRef.current.copyType === CopyType.SUBTREE_CUT) &&
163163
nodes.some(
164164
(nodeId) =>
165-
nodeId === selectionForCopyRef.current.nodeId ||
166-
selectionForCopyRef.current.allChildrenIds?.includes(nodeId)
165+
nodeId === nodeSelectionForCopyRef.current.nodeId ||
166+
nodeSelectionForCopyRef.current.allChildrenIds?.includes(nodeId)
167167
),
168168

169169
[]
170170
);
171171

172172
const resetNodeClipboard = useCallback(() => {
173-
dispatch(setSelectionForCopy(noSelectionForCopy));
173+
dispatch(setNodeSelectionForCopy(noNodeSelectionForCopy));
174174
snackInfo({
175175
messageId: 'CopiedNodeInvalidationMessage',
176176
});
177177

178178
//only the tab that initiated the copy should update through the websocket, all the other tabs will get the info through broadcast
179179
if (true === isInitiatingCopyTab.current) {
180-
broadcastChannel.postMessage(noSelectionForCopy);
180+
broadcastChannel.postMessage(noNodeSelectionForCopy);
181181

182182
//we need to reset isInitiatingCopyTab here otherwise it won't in the current tab thus next unrelated pasting actions will reset other tabs clipboard
183183
isInitiatingCopyTab.current = false;
@@ -238,7 +238,7 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
238238
} else if (studyUpdatedForce.eventData.headers['updateType'] === UpdateType.NODE_DELETED) {
239239
if (
240240
studyUpdatedForce.eventData.headers['nodes'].some(
241-
(nodeId) => nodeId === selectionForCopyRef.current.nodeId
241+
(nodeId) => nodeId === nodeSelectionForCopyRef.current.nodeId
242242
) ||
243243
isSubtreeImpacted(studyUpdatedForce.eventData.headers['nodes'])
244244
) {
@@ -257,7 +257,7 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
257257
}
258258
if (
259259
studyUpdatedForce.eventData.headers['nodes'].some(
260-
(nodeId) => nodeId === selectionForCopyRef.current.nodeId
260+
(nodeId) => nodeId === nodeSelectionForCopyRef.current.nodeId
261261
) ||
262262
isSubtreeImpacted(studyUpdatedForce.eventData.headers['nodes'])
263263
) {
@@ -277,7 +277,7 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
277277
//creating, updating or deleting modifications must invalidate the node clipboard
278278
} else if (UPDATE_TYPE.includes(studyUpdatedForce.eventData.headers['updateType'])) {
279279
if (
280-
studyUpdatedForce.eventData.headers['parentNode'] === selectionForCopyRef.current.nodeId ||
280+
studyUpdatedForce.eventData.headers['parentNode'] === nodeSelectionForCopyRef.current.nodeId ||
281281
isSubtreeImpacted([studyUpdatedForce.eventData.headers['parentNode']])
282282
) {
283283
resetNodeClipboard();
@@ -324,7 +324,7 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
324324
const handleCopyNode = (nodeId) => {
325325
console.info('node with id ' + nodeId + ' from study ' + studyUuid + ' selected for copy');
326326
isInitiatingCopyTab.current = true;
327-
dispatchSelectionForCopy(studyUuid, nodeId, CopyType.NODE_COPY);
327+
dispatchNodeSelectionForCopy(studyUuid, nodeId, CopyType.NODE_COPY);
328328
broadcastChannel.postMessage({
329329
sourceStudyUuid: studyUuid,
330330
nodeId: nodeId,
@@ -334,14 +334,14 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
334334

335335
const handleCutNode = (nodeId) => {
336336
nodeId
337-
? dispatchSelectionForCopy(studyUuid, nodeId, CopyType.NODE_CUT)
338-
: dispatch(setSelectionForCopy(noSelectionForCopy));
337+
? dispatchNodeSelectionForCopy(studyUuid, nodeId, CopyType.NODE_CUT)
338+
: dispatch(setNodeSelectionForCopy(noNodeSelectionForCopy));
339339
};
340340

341341
const handlePasteNode = useCallback(
342342
(referenceNodeId, insertMode) => {
343-
if (CopyType.NODE_CUT === selectionForCopyRef.current.copyType) {
344-
cutTreeNode(studyUuid, selectionForCopyRef.current.nodeId, referenceNodeId, insertMode).catch(
343+
if (CopyType.NODE_CUT === nodeSelectionForCopyRef.current.copyType) {
344+
cutTreeNode(studyUuid, nodeSelectionForCopyRef.current.nodeId, referenceNodeId, insertMode).catch(
345345
(error) => {
346346
snackError({
347347
messageTxt: error.message,
@@ -350,12 +350,12 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
350350
}
351351
);
352352
//Do not wait for the response, after the first CUT / PASTE operation, we can't paste anymore
353-
dispatch(setSelectionForCopy(noSelectionForCopy));
354-
} else if (CopyType.NODE_COPY === selectionForCopyRef.current.copyType) {
353+
dispatch(setNodeSelectionForCopy(noNodeSelectionForCopy));
354+
} else if (CopyType.NODE_COPY === nodeSelectionForCopyRef.current.copyType) {
355355
copyTreeNode(
356-
selectionForCopyRef.current.sourceStudyUuid,
356+
nodeSelectionForCopyRef.current.sourceStudyUuid,
357357
studyUuid,
358-
selectionForCopyRef.current.nodeId,
358+
nodeSelectionForCopyRef.current.nodeId,
359359
referenceNodeId,
360360
insertMode
361361
).catch((error) => {
@@ -466,7 +466,7 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
466466
const handleCopySubtree = (nodeId) => {
467467
console.info('node with id ' + nodeId + ' from study ' + studyUuid + ' selected for copy');
468468
isInitiatingCopyTab.current = true;
469-
dispatchSelectionForCopy(studyUuid, nodeId, CopyType.SUBTREE_COPY);
469+
dispatchNodeSelectionForCopy(studyUuid, nodeId, CopyType.SUBTREE_COPY);
470470
broadcastChannel.postMessage({
471471
sourceStudyUuid: studyUuid,
472472
nodeId: nodeId,
@@ -476,26 +476,26 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
476476

477477
const handleCutSubtree = (nodeId) => {
478478
nodeId
479-
? dispatchSelectionForCopy(studyUuid, nodeId, CopyType.SUBTREE_CUT)
480-
: dispatch(setSelectionForCopy(noSelectionForCopy));
479+
? dispatchNodeSelectionForCopy(studyUuid, nodeId, CopyType.SUBTREE_CUT)
480+
: dispatch(setNodeSelectionForCopy(noNodeSelectionForCopy));
481481
};
482482

483483
const handlePasteSubtree = useCallback(
484484
(referenceNodeId) => {
485-
if (CopyType.SUBTREE_CUT === selectionForCopyRef.current.copyType) {
486-
cutSubtree(studyUuid, selectionForCopyRef.current.nodeId, referenceNodeId).catch((error) => {
485+
if (CopyType.SUBTREE_CUT === nodeSelectionForCopyRef.current.copyType) {
486+
cutSubtree(studyUuid, nodeSelectionForCopyRef.current.nodeId, referenceNodeId).catch((error) => {
487487
snackError({
488488
messageTxt: error.message,
489489
headerId: 'NodeCreateError',
490490
});
491491
});
492492
//Do not wait for the response, after the first CUT / PASTE operation, we can't paste anymore
493-
dispatch(setSelectionForCopy(noSelectionForCopy));
494-
} else if (CopyType.SUBTREE_COPY === selectionForCopyRef.current.copyType) {
493+
dispatch(setNodeSelectionForCopy(noNodeSelectionForCopy));
494+
} else if (CopyType.SUBTREE_COPY === nodeSelectionForCopyRef.current.copyType) {
495495
copySubtree(
496-
selectionForCopyRef.current.sourceStudyUuid,
496+
nodeSelectionForCopyRef.current.sourceStudyUuid,
497497
studyUuid,
498-
selectionForCopyRef.current.nodeId,
498+
nodeSelectionForCopyRef.current.nodeId,
499499
referenceNodeId
500500
).catch((error) => {
501501
snackError({
@@ -537,7 +537,7 @@ export const NetworkModificationTreePane = ({ studyUuid, studyMapTreeDisplay })
537537
handleNodeRemoval={handleRemoveNode}
538538
handleExportCaseOnNode={handleExportCaseOnNode}
539539
handleClose={closeCreateNodeMenu}
540-
selectionForCopy={selectionForCopyRef.current}
540+
nodeSelectionForCopy={nodeSelectionForCopyRef.current}
541541
handleCopyNode={handleCopyNode}
542542
handleCutNode={handleCutNode}
543543
handlePasteNode={handlePasteNode}

src/redux/actions.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
CurrentTreeNode,
4343
EquipmentUpdateType,
4444
OneBusShortCircuitAnalysisDiagram,
45-
SelectionForCopy,
45+
NodeSelectionForCopy,
4646
StudyIndexationStatus,
4747
StudyUpdatedEventData,
4848
TableSortKeysType,
@@ -126,7 +126,7 @@ export type AppActions =
126126
| ChangeReorderedColumnsAction
127127
| FavoriteContingencyListsAction
128128
| CurrentTreeNodeAction
129-
| SelectionForCopyAction
129+
| NodeSelectionForCopyAction
130130
| SetModificationsDrawerOpenAction
131131
| SetEventScenarioDrawerOpenAction
132132
| CenterOnSubstationAction
@@ -741,14 +741,16 @@ export function setCurrentTreeNode(currentTreeNode: CurrentTreeNode): CurrentTre
741741
};
742742
}
743743

744-
export const SELECTION_FOR_COPY = 'SELECTION_FOR_COPY';
745-
export type SelectionForCopyAction = Readonly<Action<typeof SELECTION_FOR_COPY>> & {
746-
selectionForCopy: NonNullable<SelectionForCopy>;
744+
export const NODE_SELECTION_FOR_COPY = 'NODE_SELECTION_FOR_COPY';
745+
export type NodeSelectionForCopyAction = Readonly<Action<typeof NODE_SELECTION_FOR_COPY>> & {
746+
nodeSelectionForCopy: NonNullable<NodeSelectionForCopy>;
747747
};
748-
export function setSelectionForCopy(selectionForCopy: NonNullable<SelectionForCopy>): SelectionForCopyAction {
748+
export function setNodeSelectionForCopy(
749+
nodeSelectionForCopy: NonNullable<NodeSelectionForCopy>
750+
): NodeSelectionForCopyAction {
749751
return {
750-
type: SELECTION_FOR_COPY,
751-
selectionForCopy: selectionForCopy,
752+
type: NODE_SELECTION_FOR_COPY,
753+
nodeSelectionForCopy: nodeSelectionForCopy,
752754
};
753755
}
754756

0 commit comments

Comments
 (0)