Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/components/dialogs/import-modification-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ import {
TreeViewFinderNodeProps,
useSnackMessage,
} from '@gridsuite/commons-ui';
import { copyOrMoveModifications } from '../../services/study';
import { executeCompositeModificationAction } from '../../services/study';
import { FunctionComponent } from 'react';
import { useSelector } from 'react-redux';
import { AppState } from 'redux/reducer.type';
import { NetworkModificationCopyType } from 'components/graph/menus/network-modifications/network-modification-menu.type';
import { CompositeModificationAction } from 'components/graph/menus/network-modifications/network-modification-menu.type';

/**
* Dialog to select some network modifications and append them in the current node
* @param {Boolean} open Is the dialog open ?
* @param {EventListener} onClose Event to close the dialog
* @param currentNode the current node
* @param studyUuid Id of the current study
*/

interface ImportModificationDialogProps {
open: boolean;
onClose: () => void;
Expand All @@ -39,15 +36,20 @@ const ImportModificationDialog: FunctionComponent<ImportModificationDialogProps>
const currentNode = useSelector((state: AppState) => state.currentTreeNode);

const processSelectedElements = (selectedElements: TreeViewFinderNodeProps[]) => {
const modificationUuidList = selectedElements.map((e) => e.id);
// import selected modifications
if (modificationUuidList.length > 0 && studyUuid && currentNode) {
const copyInfos = {
copyType: NetworkModificationCopyType.SPLIT_COMPOSITE,
originStudyUuid: studyUuid,
originNodeUuid: currentNode.id,
const modificationsToInsert = selectedElements.map((e) => {
return {
first: e.id,
second: e.name,
};
copyOrMoveModifications(studyUuid, currentNode.id, modificationUuidList, copyInfos).catch((error) => {
});
// import selected modifications
if (modificationsToInsert.length > 0 && studyUuid && currentNode) {
executeCompositeModificationAction(
studyUuid,
currentNode.id,
modificationsToInsert,
CompositeModificationAction.SPLIT
).catch((error) => {
snackWithFallback(snackError, error, { headerId: 'errDuplicateModificationMsg' });
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ export interface ExcludedNetworkModifications {
export enum NetworkModificationCopyType {
COPY = 'COPY',
MOVE = 'MOVE',
SPLIT_COMPOSITE = 'SPLIT_COMPOSITE',
INSERT_COMPOSITE = 'INSERT_COMPOSITE',
}

export enum CompositeModificationAction {
SPLIT = 'SPLIT', // the network modifications contained into the composite modifications are extracted and inserted one by one
INSERT = 'INSERT', // the composite modifications are fully inserted as composite modifications
}

export interface NetworkModificationCopyInfos {
Expand Down
42 changes: 35 additions & 7 deletions src/services/study/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
Parameter,
safeEncodeURIComponent,
} from '@gridsuite/commons-ui';
import { NetworkModificationCopyInfos } from 'components/graph/menus/network-modifications/network-modification-menu.type';
import {
CompositeModificationAction,
NetworkModificationCopyInfos,
} from 'components/graph/menus/network-modifications/network-modification-menu.type';
import type { Svg } from 'components/grid-layout/cards/diagrams/diagram.type';

export const PREFIX_STUDY_QUERIES = import.meta.env.VITE_API_GATEWAY + '/study';
Expand Down Expand Up @@ -219,6 +222,36 @@ export function fetchContingencyCount(
return backendFetchJson(url);
}

export function executeCompositeModificationAction(
studyUuid: UUID,
targetNodeId: UUID,
compositeModificationsToInsert: {
first: UUID;
second: string; // composite modification name (if needed)
}[],
compositeModificationAction: CompositeModificationAction
) {
const url =
PREFIX_STUDY_QUERIES +
'/v1/studies/' +
safeEncodeURIComponent(studyUuid) +
'/nodes/' +
safeEncodeURIComponent(targetNodeId) +
'/composite-modifications?' +
new URLSearchParams({
action: compositeModificationAction.toString(),
});

return backendFetch(url, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(compositeModificationsToInsert),
});
}

export function copyOrMoveModifications(
studyUuid: UUID,
targetNodeId: UUID,
Expand All @@ -239,18 +272,13 @@ export function copyOrMoveModifications(
originNodeUuid: copyInfos.originNodeUuid ?? '',
});

// TODO : conversion to a ModificationsToCopyInfos dto => this will be useful and improved when INSERT_COMPOSITE action will be made available from the front
const modifications = modificationToCutUuidList.map((modificationUuid) => {
return { uuid: modificationUuid };
});

return backendFetch(copyOrMoveModificationUrl, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(modifications),
body: JSON.stringify(modificationToCutUuidList),
});
}

Expand Down
Loading