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
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
assembleModificationsIntoComposite,
fetchExcludedNetworkModifications,
fetchNetworkModifications,
shareCompositeModification,
stashModifications,
} from '../../../../services/study/network-modifications';
import {
Expand Down Expand Up @@ -991,6 +992,37 @@
});
};

const doShareCompositeModificationElement = ({
name,
description,
folderName,
folderId,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not related to your code but it should be directoryId/directoryName (directory-server)
the naming of folderId/folderName sounds so weired for me (it is for UI level)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said it's an existing issue, so if we want to change it we should create a new ticket.

}: IElementCreationDialog) => {
const compositeToShare = selectedNetworkModifications[0];
// the selection may have been emptied by a refresh while the dialog was open
if (!compositeToShare) {
return;
}

setSaveInProgress(true);
shareCompositeModification(studyUuid, currentNode?.id, compositeToShare.uuid, name, description, folderId)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
.then(() => {
snackInfo({
headerId: 'infoShareModificationMsg',
headerValues: {
item: name,
directory: folderName,
},
});
})
.catch((error) => {
snackWithFallback(snackError, error, { headerId: 'errShareModificationMsg' });
})
.finally(() => {
setSaveInProgress(false);
});
};

const doUpdateCompositeModificationsElements = ({
id,
name,
Expand Down Expand Up @@ -1149,6 +1181,14 @@
? (JSON.parse(selectedNetworkModifications[0]?.messageValues)?.name ?? null)
: null;

// Sharing moves the selected composite itself into gridexplore : it needs exactly one composite, and an
// already shared one (a reference) cannot be shared again. Only a composite of the node itself can be shared,
// not one nested in another composite, so the third condition: the modifications list holds the modifications of the node only
const isSharingAvailable =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useMemo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's counterproductive here.

selectedNetworkModifications.length === 1 &&
selectedNetworkModifications[0].type === ModificationType.COMPOSITE_MODIFICATION &&
modifications.some((modification) => modification.uuid === selectedNetworkModifications[0].uuid);

const renderNetworkModificationsTable = () => {
if (isRootNode) {
return (
Expand Down Expand Up @@ -1204,6 +1244,8 @@
<ElementSaveDialog
open={createCompositeModificationDialogOpen}
onSave={doCreateCompositeModificationsElements}
onSaveShared={doShareCompositeModificationElement}

Check failure on line 1247 in src/components/graph/menus/network-modifications/network-modification-node-editor.tsx

View workflow job for this annotation

GitHub Actions / build / build

Type '{ open: boolean; onSave: ({ name, description, folderName, folderId, }: IElementCreationDialog) => void; onSaveShared: ({ name, description, folderName, folderId, }: IElementCreationDialog) => void; createSharedDisabled: boolean; ... 10 more ...; updateLabelId: string; }' is not assignable to type 'IntrinsicAttributes & Readonly<ElementSaveDialogProps>'.
createSharedDisabled={!isSharingAvailable}
OnUpdate={doUpdateCompositeModificationsElements}
onClose={() => setCreateCompositeModificationDialogOpen(false)}
type={ElementType.MODIFICATION}
Expand All @@ -1213,6 +1255,7 @@
studyUuid={studyUuid}
selectorTitleId="SelectCompositeModificationTitle"
createLabelId="CreateCompositeModificationLabel"
createSharedLabelId="ShareCompositeModificationLabel"
updateLabelId="UpdateCompositeModificationLabel"
/>
)
Expand Down
19 changes: 19 additions & 0 deletions src/services/study/network-modifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,25 @@ export function assembleModificationsIntoComposite(
});
}

/**
* Moves a composite modification of the node out of the study into a directory of GridExplore,
* and replaces it in the node by a reference to the newly shared composite modification.
*/
export function shareCompositeModification(
studyUuid: UUID | null,
nodeUuid: UUID | undefined,
modificationUuid: UUID,
name: string,
description: string,
parentDirectoryUuid: UUID
) {
console.info('Sharing composite modification');
const url = `${getNetworkModificationUrl(studyUuid, nodeUuid)}/${safeEncodeURIComponent(
modificationUuid
)}/share?${new URLSearchParams({ name, description, parentDirectoryUuid }).toString()}`;
return backendFetch(url, { method: 'POST' });
}

export function getNetworkModificationsFromComposite(
compositeModificationUuids: string[],
onlyMetadata: boolean = true
Expand Down
9 changes: 6 additions & 3 deletions src/translations/messages-en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,11 @@ const messages_en = {
SubstationList: 'Substation list',
NetworkModificationTree: 'Network modification tree',
RestoreModifications: 'Restore modifications',
CreateCompositeModification: 'Create composite network modification',
CreateCompositeModification: 'Create a composite modification',
SelectCompositeModificationTitle: 'Composite network modification',
CreateCompositeModificationLabel: 'Create a new composite modification',
UpdateCompositeModificationLabel: 'Replace an existing composite modification',
CreateCompositeModificationLabel: 'New',
ShareCompositeModificationLabel: 'New (shared)',
UpdateCompositeModificationLabel: 'Replace an existing one',
'importComposites.title': 'Import composite modifications',
'importComposites.organizationLabel': 'Modifications organisation: ',
'importComposites.action.split': 'Same',
Expand Down Expand Up @@ -1024,6 +1025,8 @@ const messages_en = {
'Composite modification of {nbModifications} unitary network modifications created in {directory}',
infoUpdateModificationsMsg:
'Composite modification {item} updated with {nbModifications} unitary network modifications',
errShareModificationMsg: 'Composite modification sharing error',
infoShareModificationMsg: 'Composite modification "{item}" shared in directory "{directory}"',
'idSelector.idNeeded': 'Please select an ID',
SpreadsheetFetchError: 'An error occurred while fetching equipments in the spreadsheet',
partialCopyShuntCompensator: 'Partial copy : copying sections is not supported for this shunt compensator',
Expand Down
9 changes: 6 additions & 3 deletions src/translations/messages-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,11 @@ const messages_fr = {
SubstationList: 'Liste des postes',
NetworkModificationTree: 'Arbre décisionnel',
RestoreModifications: 'Restaurer les modifications',
CreateCompositeModification: 'Créer une modification composite de réseau',
CreateCompositeModification: 'Créer une modification composite',
SelectCompositeModificationTitle: 'Modification composite de réseau',
CreateCompositeModificationLabel: 'Créer une nouvelle modification composite',
UpdateCompositeModificationLabel: 'Remplacer une modification composite existante',
CreateCompositeModificationLabel: 'Nouvelle',
ShareCompositeModificationLabel: 'Nouvelle (partagée)',
UpdateCompositeModificationLabel: 'Remplacer une existante',
'importComposites.title': 'Importer des modifications composites',
'importComposites.organizationLabel': 'Organisation des modifications : ',
'importComposites.action.split': 'Identiques',
Expand Down Expand Up @@ -1037,6 +1038,8 @@ const messages_fr = {
"Création d'une modification composite de {nbModifications} modifications unitaires dans {directory}",
infoUpdateModificationsMsg:
'Mise à jour de la modification composite {item} avec {nbModifications} modifications unitaires',
errShareModificationMsg: 'Une erreur est survenue lors du partage de la modification composite',
infoShareModificationMsg: 'Partage de la modification composite "{item}" dans le dossier "{directory}"',
'idSelector.idNeeded': 'Veuillez sélectionner un ID',
SpreadsheetFetchError: 'Une erreur est survenue lors du chargement des ouvrages dans le tableur',
partialCopyShuntCompensator:
Expand Down
Loading