-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] rearrange widgets in WorkspaceHeader
- Loading branch information
Showing
3 changed files
with
118 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...tform/opencti-front/src/private/components/workspaces/dashboards/DashboardTimeFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DashboardTimeFiltersProps> = ({ | ||
workspace, | ||
config = {}, | ||
handleDateChange, | ||
}) => { | ||
const { t_i18n } = useFormatter(); | ||
const { canEdit } = useGetCurrentUserAccessRight(workspace.currentUserAccessRight); | ||
|
||
return ( | ||
<Security | ||
needs={[EXPLORE_EXUPDATE, INVESTIGATION_INUPDATE]} | ||
hasAccess={canEdit} | ||
> | ||
<div style={{ display: 'flex', marginLeft: 20 }} > | ||
<FormControl | ||
size="small" | ||
style={{ width: 194, marginRight: 8 }} | ||
variant="outlined" | ||
> | ||
<InputLabel id="relative" variant="outlined"> | ||
{t_i18n('Relative time')} | ||
</InputLabel> | ||
<Select | ||
labelId="relative" | ||
value={config.relativeDate ?? ''} | ||
onChange={(value) => handleDateChange('relativeDate', value)} | ||
label={t_i18n('Relative time')} | ||
variant="outlined" | ||
> | ||
<MenuItem value="none">{t_i18n('None')}</MenuItem> | ||
<MenuItem value="days-1">{t_i18n('Last 24 hours')}</MenuItem> | ||
<MenuItem value="days-7">{t_i18n('Last 7 days')}</MenuItem> | ||
<MenuItem value="months-1">{t_i18n('Last month')}</MenuItem> | ||
<MenuItem value="months-3">{t_i18n('Last 3 months')}</MenuItem> | ||
<MenuItem value="months-6">{t_i18n('Last 6 months')}</MenuItem> | ||
<MenuItem value="years-1">{t_i18n('Last year')}</MenuItem> | ||
</Select> | ||
</FormControl> | ||
<DatePicker | ||
value={config.startDate ?? null} | ||
label={t_i18n('Start date')} | ||
disableFuture={true} | ||
disabled={!!config.relativeDate} | ||
onChange={(value, context) => !context.validationError && handleDateChange('startDate', value)} | ||
slotProps={{ | ||
textField: { | ||
style: { marginRight: 8 }, | ||
variant: 'outlined', | ||
size: 'small', | ||
}, | ||
}} | ||
/> | ||
<DatePicker | ||
value={config.endDate ?? null} | ||
label={t_i18n('End date')} | ||
disabled={!!config.relativeDate} | ||
disableFuture={true} | ||
onChange={(value, context) => !context.validationError && handleDateChange('endDate', value)} | ||
slotProps={{ | ||
textField: { | ||
variant: 'outlined', | ||
size: 'small', | ||
}, | ||
}} | ||
/> | ||
</div> | ||
</Security> | ||
); | ||
}; | ||
|
||
export default DashboardTimeFilters; |