Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e049649
first commit
carojeandat Oct 3, 2025
ec938ab
fix rerender
carojeandat Oct 6, 2025
65c1394
clean
carojeandat Oct 6, 2025
454b2a7
clean
carojeandat Oct 6, 2025
c59a9b1
remove unused imports
carojeandat Oct 6, 2025
c6df3ac
Merge branch 'main' into copy-paste-network-modifications
carojeandat Oct 6, 2025
b878556
clean
carojeandat Oct 6, 2025
142898e
clean
carojeandat Oct 6, 2025
ba7b092
Merge branch 'main' into copy-paste-network-modifications
EstherDarkish Oct 7, 2025
5aa8885
Merge branch 'main' into copy-paste-network-modifications
EstherDarkish Oct 7, 2025
b9785d4
Merge branch 'main' into copy-paste-network-modifications
EstherDarkish Oct 8, 2025
37ebe58
remove redux store
carojeandat Oct 8, 2025
71a6884
Merge branch 'main' into copy-paste-network-modifications
carojeandat Oct 8, 2025
80de64f
add snack bars
carojeandat Oct 8, 2025
a245099
clean comments
carojeandat Oct 8, 2025
dde3479
Merge branch 'main' into copy-paste-network-modifications
carojeandat Oct 9, 2025
072fe0a
delete cut handling
carojeandat Oct 9, 2025
8f12aa5
remove duplicated console info
carojeandat Oct 9, 2025
4e7f189
Merge branch 'main' into copy-paste-network-modifications
carojeandat Oct 10, 2025
68986d9
Merge branch 'main' into copy-paste-network-modifications
carojeandat Oct 10, 2025
bddfe1f
Update network-modification-node-editor.tsx
carojeandat Oct 10, 2025
b623c83
fix translation
carojeandat Oct 10, 2025
baccf9b
clean
carojeandat Oct 10, 2025
7c590ec
make sure only one tab isInitiatingCopyTab
carojeandat Oct 10, 2025
097068f
Merge branch 'main' into copy-paste-network-modifications
carojeandat Oct 13, 2025
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 @@ -54,6 +54,7 @@ export enum NetworkModificationCopyType {

export interface NetworkModificationCopyInfo {
copyType: NetworkModificationCopyType;
originStudyUuid?: UUID;
originNodeUuid?: UUID;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ const isEditableModification = (modif: NetworkModificationMetadata) => {
return !nonEditableModificationTypes.has(modif.type);
};

const emptyCopiedModificationsSelection = {
modificationsUuids: [],
copyInfos: null,
};

const NetworkModificationNodeEditor = () => {
const notificationIdList = useSelector((state: AppState) => state.notificationIdList);
const studyUuid = useSelector((state: AppState) => state.studyUuid);
Expand Down Expand Up @@ -181,6 +186,40 @@ const NetworkModificationNodeEditor = () => {
const buttonAddRef = useRef<HTMLButtonElement>(null);
const [enableDeveloperMode] = useParameterState(PARAM_DEVELOPER_MODE);

const isInitiatingCopyTab = useRef(false);

const [broadcastChannel] = useState(() => {
const broadcast = new BroadcastChannel('modificationsCopyChannel');
broadcast.onmessage = (event) => {
console.info('message received from broadcast channel: ', event.data);
isInitiatingCopyTab.current = false;
if (JSON.stringify(emptyCopiedModificationsSelection) === JSON.stringify(event.data)) {
cleanClipboard();
} else {
setCopiedModifications(event.data.modificationsUuids);
setCopyInfos({
copyType: event.data.copyInfos.copyType,
originStudyUuid: event.data.copyInfos.originStudyUuid,
originNodeUuid: event.data.copyInfos.originNodeUuid,
});
snackInfo({ messageId: 'CopiedModificationUpdateMessageFromAnotherStudy' });
}
};
return broadcast;
});

useEffect(() => {
//If the tab is closed we want to invalidate the copy on all tabs because we won't able to track the node modification
window.addEventListener('beforeunload', (event) => {
if (true === isInitiatingCopyTab.current) {
broadcastChannel.postMessage(emptyCopiedModificationsSelection);
snackInfo({
messageId: 'CopiedModificationInvalidationMessageAfterTabClosure',
});
}
});
}, [broadcastChannel, snackInfo]);

const cleanClipboard = useCallback(
(showSnackInfo: boolean = true) => {
setCopyInfos(null);
Expand All @@ -192,8 +231,12 @@ const NetworkModificationNodeEditor = () => {
}
return [];
});
if (true === isInitiatingCopyTab.current) {
broadcastChannel.postMessage(emptyCopiedModificationsSelection);
isInitiatingCopyTab.current = false;
}
},
[snackInfo]
[snackInfo, broadcastChannel]
);

// TODO this is not complete.
Expand Down Expand Up @@ -1032,17 +1075,28 @@ const NetworkModificationNodeEditor = () => {
setCopiedModifications(selectedModificationsIds());
setCopyInfos({
copyType: NetworkModificationCopyType.MOVE,
originStudyUuid: studyUuid ?? undefined,
originNodeUuid: currentNode?.id,
});
}, [currentNode?.id, selectedModificationsIds]);
}, [currentNode?.id, selectedModificationsIds, studyUuid]);

const doCopyModifications = useCallback(() => {
setCopiedModifications(selectedModificationsIds());
setCopyInfos({
copyType: NetworkModificationCopyType.COPY,
originStudyUuid: studyUuid ?? undefined,
originNodeUuid: currentNode?.id,
});
}, [currentNode?.id, selectedModificationsIds]);
broadcastChannel.postMessage({
modificationsUuids: selectedModificationsIds(),
copyInfos: {
copyType: NetworkModificationCopyType.COPY,
originStudyUuid: studyUuid,
originNodeUuid: currentNode?.id,
},
});
isInitiatingCopyTab.current = true;
}, [broadcastChannel, currentNode?.id, selectedModificationsIds, studyUuid]);

const doPasteModifications = useCallback(() => {
if (!copyInfos || !studyUuid || !currentNode?.id) {
Expand Down
3 changes: 2 additions & 1 deletion src/services/study/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function fetchContingencyCount(
export function copyOrMoveModifications(
studyUuid: UUID,
targetNodeId: UUID,
modificationToCutUuidList: string[],
modificationToCutUuidList: UUID[],
copyInfos: NetworkModificationCopyInfo
) {
console.info(copyInfos.copyType + ' modifications');
Expand All @@ -229,6 +229,7 @@ export function copyOrMoveModifications(
'?' +
new URLSearchParams({
action: copyInfos.copyType,
originStudyUuid: copyInfos.originStudyUuid ?? '',
originNodeUuid: copyInfos.originNodeUuid ?? '',
});

Expand Down
3 changes: 3 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

"CopiedNodeInvalidationMessage": "As a result of node modification, the contents of the clipboard have been deleted",
"CopiedModificationInvalidationMessage": "Following a modification of the hypothesis, the content of the clipboard has been deleted",
"CopiedModificationInvalidationMessageFromAnotherStudy": "Following a change in the modifications in another study, the content of the clipboard has been deleted",
"CopiedModificationUpdateMessageFromAnotherStudy": "As a result of copying modifications from another study, the content of the clipboard has been updated",
"CopiedModificationInvalidationMessageAfterTabClosure": "As a result of closing the tab from another study, the content of the clipboard has been deleted",
"exportNetwork": "Export the network",
"export": "Export",
"download.fileName": "File name",
Expand Down
3 changes: 3 additions & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

"CopiedNodeInvalidationMessage": "Suite à modification de nœud, le contenu du presse papier a été supprimé",
"CopiedModificationInvalidationMessage": "Suite à modification d'hypothèse, le contenu du presse papier a été supprimé",
"CopiedModificationInvalidationMessageFromAnotherStudy": "Suite à un changement des modifications dans une autre étude, le contenu du presse papier a été supprimé",
"CopiedModificationUpdateMessageFromAnotherStudy": "Suite à la copie de modifications dans une autre étude, le presse papier a été modifié",
"CopiedModificationInvalidationMessageAfterTabClosure": "Suite à la fermeture de l'onglet d'une autre étude, le presse papier a été supprimé",
"exportNetwork": "Exporter le réseau",
"export": "Exporter",
"download.fileName": "Nom de fichier",
Expand Down
Loading