From 4bdae164d1b1d0e24d1b14a6893da7f068019f7f Mon Sep 17 00:00:00 2001 From: Laurent Bonnet <146674147+labo-flg@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:55:42 +0100 Subject: [PATCH] Fix dashboard header UI (under FAB replacement FF) --- .../workspaces/WorkspaceCreation.jsx | 2 +- .../components/workspaces/WorkspaceHeader.jsx | 78 +--------------- .../workspaces/dashboards/Dashboard.jsx | 30 ++++-- .../dashboards/DashboardTimeFilters.tsx | 93 +++++++++++++++++++ .../dashboards/WorkspaceWidgetConfig.jsx | 4 +- .../public_dashboards/PublicDashboards.tsx | 4 + 6 files changed, 126 insertions(+), 85 deletions(-) create mode 100644 opencti-platform/opencti-front/src/private/components/workspaces/dashboards/DashboardTimeFilters.tsx diff --git a/opencti-platform/opencti-front/src/private/components/workspaces/WorkspaceCreation.jsx b/opencti-platform/opencti-front/src/private/components/workspaces/WorkspaceCreation.jsx index 328f0dc5cc69..66bcf12c02c9 100644 --- a/opencti-platform/opencti-front/src/private/components/workspaces/WorkspaceCreation.jsx +++ b/opencti-platform/opencti-front/src/private/components/workspaces/WorkspaceCreation.jsx @@ -123,7 +123,6 @@ const WorkspaceCreation = ({ paginationOptions, type }) => { const createDashboardButton = FAB_REPLACED ? (props) => ( <> - + ) : ({ onOpen }) => ( - {variant === 'dashboard' && ( + {variant === 'dashboard' && !isFABReplaced && ( - - - {t_i18n('Relative time')} - - - - !context.validationError && handleDateChange('startDate', value)} - slotProps={{ - textField: { - style: { marginRight: 20 }, - variant: 'outlined', - size: 'small', - }, - }} - /> - !context.validationError && handleDateChange('endDate', value)} - slotProps={{ - textField: { - style: { marginRight: 20 }, - variant: 'outlined', - size: 'small', - }, - }} - /> - - } >
)} - {variant === 'dashboard' && isFeatureEnable('FAB_REPLACEMENT') && ( + {variant === 'dashboard' && isFABReplaced && ( -
+
diff --git a/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/Dashboard.jsx b/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/Dashboard.jsx index 2493a7f02b98..e6bdb4263fe7 100644 --- a/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/Dashboard.jsx +++ b/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/Dashboard.jsx @@ -5,6 +5,7 @@ import RGL, { WidthProvider } from 'react-grid-layout'; import Paper from '@mui/material/Paper'; import makeStyles from '@mui/styles/makeStyles'; import { v4 as uuid } from 'uuid'; +import DashboardTimeFilters from './DashboardTimeFilters'; import StixCoreObjectsPolarArea from '../../common/stix_core_objects/StixCoreObjectsPolarArea'; import StixRelationshipsPolarArea from '../../common/stix_relationships/StixRelationshipsPolarArea'; import { computerRelativeDate, dayStartDate, parse } from '../../../../utils/Time'; @@ -89,6 +90,8 @@ const DashboardComponent = ({ workspace, noToolbar }) => { const ReactGridLayout = useMemo(() => WidthProvider(RGL), []); const classes = useStyles(); const { isFeatureEnable } = useHelper(); + const isFABReplaced = isFeatureEnable('FAB_REPLACEMENT'); + useEffect(() => { const timeout = setTimeout(() => { window.dispatchEvent(new Event('resize')); @@ -799,13 +802,24 @@ const DashboardComponent = ({ workspace, noToolbar }) => { }} > {!noToolbar && ( - + <> + + {isFABReplaced && ( +
+ +
+ )} + )} {isExploreUpdater && userCanEdit ? ( { })} )} - {!noToolbar && userCanEdit && !isFeatureEnable('FAB_REPLACEMENT') && } + {!noToolbar && userCanEdit && !isFABReplaced && }
); }; diff --git a/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/DashboardTimeFilters.tsx b/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/DashboardTimeFilters.tsx new file mode 100644 index 000000000000..9bcfa57aebdc --- /dev/null +++ b/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/DashboardTimeFilters.tsx @@ -0,0 +1,93 @@ +import React from 'react'; +import FormControl from '@mui/material/FormControl'; +import InputLabel from '@mui/material/InputLabel'; +import Select from '@mui/material/Select'; +import MenuItem from '@mui/material/MenuItem'; +import { DatePicker } from '@mui/x-date-pickers/DatePicker'; +import { EXPLORE_EXUPDATE, INVESTIGATION_INUPDATE } from '../../../../utils/hooks/useGranted'; +import Security from '../../../../utils/Security'; +import { useFormatter } from '../../../../components/i18n'; +import { useGetCurrentUserAccessRight } from '../../../../utils/authorizedMembers'; +import { Dashboard_workspace$data } from './__generated__/Dashboard_workspace.graphql'; + +interface DashboardTimeFiltersProps { + workspace: Dashboard_workspace$data + config?: { + startDate: object + endDate: object + relativeDate: string + } + handleDateChange: (bound: 'startDate' | 'endDate' | 'relativeDate', value: object | string | null) => unknown +} + +const DashboardTimeFilters: React.FC = ({ + workspace, + config = {}, + handleDateChange, +}) => { + const { t_i18n } = useFormatter(); + const { canEdit } = useGetCurrentUserAccessRight(workspace.currentUserAccessRight); + + return ( + +
+ + + {t_i18n('Relative time')} + + + + !context.validationError && handleDateChange('startDate', value)} + slotProps={{ + textField: { + style: { marginRight: 8 }, + variant: 'outlined', + size: 'small', + }, + }} + /> + !context.validationError && handleDateChange('endDate', value)} + slotProps={{ + textField: { + variant: 'outlined', + size: 'small', + }, + }} + /> +
+
+ ); +}; + +export default DashboardTimeFilters; diff --git a/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/WorkspaceWidgetConfig.jsx b/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/WorkspaceWidgetConfig.jsx index c2f2948a1c16..24ea12800da0 100644 --- a/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/WorkspaceWidgetConfig.jsx +++ b/opencti-platform/opencti-front/src/private/components/workspaces/dashboards/WorkspaceWidgetConfig.jsx @@ -82,7 +82,7 @@ const WorkspaceWidgetConfig = ({ workspace, widget, onComplete, closeMenu }) =>