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
8 changes: 6 additions & 2 deletions src/components/menus/content-contextual-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
PARAM_LANGUAGE,
PARAM_DEVELOPER_MODE,
} from '@gridsuite/commons-ui';
import { cleanLocalStorageForStudies } from 'utils/local-storage-utils';
import RenameDialog from '../dialogs/rename-dialog';
import DeleteDialog from '../dialogs/delete-dialog';
import CreateStudyDialog from '../dialogs/create-study-dialog/create-study-dialog';
Expand Down Expand Up @@ -253,13 +254,16 @@ export default function ContentContextualMenu(props: Readonly<ContentContextualM
setDeleteError('');
// @ts-expect-error TODO: manage null case
deleteElements(elementsUuids, selectedDirectory?.elementUuid)
.then(() => handleCloseDialog())
.then(() => {
cleanLocalStorageForStudies(selectedElements);
handleCloseDialog();
})
// show the error message and don't close the dialog
.catch((error) => {
handleDeleteError(setDeleteError, error, intl, snackError);
});
},
[selectedDirectory?.elementUuid, handleCloseDialog, intl, snackError]
[selectedDirectory?.elementUuid, handleCloseDialog, selectedElements, intl, snackError]
);

const [moveCB] = useMultipleDeferredFetch(moveElementsToDirectory, undefined, handleMoveError);
Expand Down
8 changes: 6 additions & 2 deletions src/components/toolbars/content-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TableView as TableViewIcon,
DownloadForOffline,
} from '@mui/icons-material';
import { cleanLocalStorageForStudies } from 'utils/local-storage-utils';
import { ElementAttributes, ElementType, useSnackMessage, PARAM_DEVELOPER_MODE } from '@gridsuite/commons-ui';
import { deleteElements, moveElementsToDirectory, PermissionType } from '../../utils/rest-api';
import DeleteDialog from '../dialogs/delete-dialog';
Expand Down Expand Up @@ -103,12 +104,15 @@ export default function ContentToolbar(props: Readonly<ContentToolbarProps>) {
setDeleteError('');
// @ts-expect-error TODO: manage null case
deleteElements(elementsUuids, selectedDirectory.elementUuid)
.then(handleCloseDialog)
.then(() => {
cleanLocalStorageForStudies(selectedElements);
handleCloseDialog();
})
.catch((error) => {
handleDeleteError(setDeleteError, error, intl, snackError);
});
},
[selectedDirectory?.elementUuid, handleCloseDialog, intl, snackError]
[selectedDirectory?.elementUuid, selectedElements, handleCloseDialog, intl, snackError]
);

const items = useMemo(() => {
Expand Down
23 changes: 23 additions & 0 deletions src/utils/local-storage-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { ElementAttributes, ElementType } from '@gridsuite/commons-ui';

/**
* Cleans localStorage entries related to studies by removing keys containing the study UUID.
* @param selectedElements - Array of selected elements to check for studies.
*/
export function cleanLocalStorageForStudies(selectedElements: ElementAttributes[]): void {
selectedElements
.filter((element) => element.type === ElementType.STUDY)
.forEach((element) => {
const studyUuid = element.elementUuid;
Object.keys(localStorage)
.filter((key) => key.includes(studyUuid))
.forEach((key) => localStorage.removeItem(key));
});
}
Loading