Skip to content

Commit

Permalink
add action to toolbar
Browse files Browse the repository at this point in the history
Signed-off-by: David BRAQUART <david.braquart@rte-france.com>
  • Loading branch information
dbraquart committed Feb 18, 2025
1 parent 38516e1 commit 46d264f
Showing 1 changed file with 65 additions and 24 deletions.
89 changes: 65 additions & 24 deletions src/components/toolbars/content-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import { useCallback, useMemo, useState } from 'react';
import { useSelector } from 'react-redux';
import { useIntl } from 'react-intl';
import { Delete as DeleteIcon, DriveFileMove as DriveFileMoveIcon, FileDownload } from '@mui/icons-material';
import {
Delete as DeleteIcon,
DriveFileMove as DriveFileMoveIcon,
FileDownload,
TableView as TableViewIcon,
} from '@mui/icons-material';
import { ElementAttributes, ElementType, useSnackMessage } from '@gridsuite/commons-ui';
import { deleteElements, moveElementsToDirectory } from '../../utils/rest-api';
import DeleteDialog from '../dialogs/delete-dialog';
Expand All @@ -20,6 +25,7 @@ import ExportCaseDialog from '../dialogs/export-case-dialog';
import * as constants from '../../utils/UIconstants';
import { DialogsId } from '../../utils/UIconstants';
import { AppState } from '../../redux/types';
import CreateSpreadsheetCollectionDialog from '../dialogs/spreadsheet-collection-creation-dialog';

export type ContentToolbarProps = Omit<CommonToolbarProps, 'items'> & {
selectedElements: ElementAttributes[];
Expand Down Expand Up @@ -128,6 +134,10 @@ export default function ContentToolbar(props: Readonly<ContentToolbarProps>) {
return selectedElements.some((element) => allowedTypes.includes(element.type)) && noCreationInProgress;
}, [selectedElements, noCreationInProgress]);

const allowsSpreadsheetCollection = useMemo(() => {
return selectedElements.every((element) => ElementType.SPREADSHEET_CONFIG === element.type);
}, [selectedElements]);

const allowsExportCases = useMemo(
() => selectedElements.some((element) => element.type === ElementType.CASE) && noCreationInProgress,
[selectedElements, noCreationInProgress]
Expand All @@ -151,34 +161,56 @@ export default function ContentToolbar(props: Readonly<ContentToolbarProps>) {
const items = useMemo(() => {
const toolbarItems = [];

if (selectedElements.length && (allowsDelete || allowsMove || allowsDownload || allowsExportCases)) {
toolbarItems.push(
{
tooltipTextId: 'delete',
callback: () => {
handleOpenDialog(DialogsId.DELETE);
if (selectedElements.length) {
if (allowsDelete || allowsMove || allowsDownload || allowsExportCases) {
// actions callable for several element types
toolbarItems.push(
{
tooltipTextId: 'delete',
callback: () => {
handleOpenDialog(DialogsId.DELETE);
},
icon: <DeleteIcon fontSize="small" />,
disabled: !allowsDelete,
},
icon: <DeleteIcon fontSize="small" />,
disabled: !selectedElements.length || !allowsDelete,
},
{
tooltipTextId: 'move',
{
tooltipTextId: 'move',
callback: () => {
handleOpenDialog(DialogsId.MOVE);
},
icon: <DriveFileMoveIcon fontSize="small" />,
disabled: !allowsMove,
},
{
tooltipTextId: 'download.button',
callback: () => downloadElements(selectedElements),
icon: <FileDownload fontSize="small" />,
disabled: !allowsDownload,
}
);
}
if (allowsSpreadsheetCollection) {
// action specific to spreadsheet models
toolbarItems.push({
tooltipTextId: 'createSpreadsheetCollection',
callback: () => {
handleOpenDialog(DialogsId.MOVE);
handleOpenDialog(DialogsId.CREATE_SPREADSHEET_COLLECTION);
},
icon: <DriveFileMoveIcon fontSize="small" />,
disabled: !selectedElements.length || !allowsMove,
},
{
tooltipTextId: 'download.button',
callback: () => downloadElements(selectedElements),
icon: <FileDownload fontSize="small" />,
disabled: !selectedElements.length || !allowsDownload,
}
);
icon: <TableViewIcon fontSize="small" />,
disabled: false,
});
}
}
return toolbarItems;
}, [allowsDelete, allowsDownload, allowsExportCases, allowsMove, downloadElements, selectedElements]);
}, [
allowsDelete,
allowsDownload,
allowsExportCases,
allowsMove,
allowsSpreadsheetCollection,
downloadElements,
selectedElements,
]);

const renderDialog = () => {
switch (openDialog) {
Expand Down Expand Up @@ -219,6 +251,15 @@ export default function ContentToolbar(props: Readonly<ContentToolbarProps>) {
onExport={handleConvertCases}
/>
);
case DialogsId.CREATE_SPREADSHEET_COLLECTION:
return (
<CreateSpreadsheetCollectionDialog
open
onClose={handleCloseDialog}
initDirectory={selectedDirectory ?? undefined}
spreadsheetConfigIds={selectedElements?.map((e) => e.elementUuid)}
/>
);
default:
return null;
}
Expand Down

0 comments on commit 46d264f

Please sign in to comment.