diff --git a/src/components/dialogs/import-modification-dialog.tsx b/src/components/dialogs/import-modification-dialog.tsx index 3b4c713038..4315890b6c 100644 --- a/src/components/dialogs/import-modification-dialog.tsx +++ b/src/components/dialogs/import-modification-dialog.tsx @@ -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; @@ -39,15 +36,20 @@ const ImportModificationDialog: FunctionComponent 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' }); }); } diff --git a/src/components/graph/menus/network-modifications/network-modification-menu.type.ts b/src/components/graph/menus/network-modifications/network-modification-menu.type.ts index e7c1d3e216..d93202059e 100644 --- a/src/components/graph/menus/network-modifications/network-modification-menu.type.ts +++ b/src/components/graph/menus/network-modifications/network-modification-menu.type.ts @@ -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 { diff --git a/src/services/study/index.ts b/src/services/study/index.ts index 3f56a3b271..4891eb31dc 100644 --- a/src/services/study/index.ts +++ b/src/services/study/index.ts @@ -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'; @@ -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, @@ -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), }); }