-
Notifications
You must be signed in to change notification settings - Fork 930
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] Trial for color in DangerZone
- Loading branch information
1 parent
cc18b01
commit 971c7d0
Showing
51 changed files
with
1,062 additions
and
322 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
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -141,6 +141,7 @@ const meUserFragment = graphql` | |
id | ||
name | ||
} | ||
can_manage_sensitive_config | ||
} | ||
`; | ||
|
||
|
122 changes: 122 additions & 0 deletions
122
opencti-platform/opencti-front/src/private/components/common/dangerZone/DangerZoneBlock.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,122 @@ | ||
import { useTheme } from '@mui/styles'; | ||
import Typography from '@mui/material/Typography'; | ||
import React, { FunctionComponent, ReactElement, ReactNode } from 'react'; | ||
import DangerZoneChip from '@components/common/dangerZone/DangerZoneChip'; | ||
import type { Theme } from '../../../../components/Theme'; | ||
import { hexToRGB } from '../../../../utils/Colors'; | ||
import { useFormatter } from '../../../../components/i18n'; | ||
import useSensitiveModifications from '../../../../utils/hooks/useSensitiveModifications'; | ||
|
||
interface DangerZoneBlockProps { | ||
title?: ReactNode | ||
component?: ((props: { disabled?: boolean, isSensitiveModificationEnabled?: boolean, style?: React.CSSProperties }) => ReactElement) | ReactNode | ||
children?: ((props: { disabled?: boolean, isSensitiveModificationEnabled?: boolean, style?: React.CSSProperties }) => ReactElement) | ReactNode | ||
sx?: Record<string, React.CSSProperties> | ||
} | ||
|
||
const DangerZoneBlock: FunctionComponent<DangerZoneBlockProps> = ({ title, component, children, sx }) => { | ||
const { t_i18n } = useFormatter(); | ||
const theme = useTheme<Theme>(); | ||
|
||
const { | ||
isSensitiveModificationEnabled, | ||
isAllowed, | ||
} = useSensitiveModifications(); | ||
|
||
let currentTitle = title; | ||
if (isSensitiveModificationEnabled) { | ||
currentTitle = ( | ||
<> | ||
{title}<DangerZoneChip /> | ||
</> | ||
); | ||
} | ||
|
||
if (component) { | ||
if (typeof component === 'function') { | ||
return ( | ||
<> | ||
<Typography | ||
variant="h4" | ||
gutterBottom | ||
> | ||
{currentTitle} | ||
</Typography> | ||
{component({ | ||
disabled: isSensitiveModificationEnabled && !isAllowed, | ||
isSensitiveModificationEnabled, | ||
style: { | ||
borderColor: isSensitiveModificationEnabled ? hexToRGB(theme.palette.dangerZone.main, 0.5) : undefined, | ||
}, | ||
})} | ||
</> | ||
); | ||
} | ||
return ( | ||
<> | ||
<Typography | ||
variant="h4" | ||
gutterBottom | ||
> | ||
{currentTitle} | ||
</Typography> | ||
{React.cloneElement(component as ReactElement, { | ||
disabled: isSensitiveModificationEnabled && !isAllowed, | ||
isSensitiveModificationEnabled, | ||
style: { | ||
borderColor: isSensitiveModificationEnabled ? hexToRGB(theme.palette.dangerZone.main, 0.5) : undefined, | ||
}, | ||
})} | ||
</> | ||
); | ||
} | ||
|
||
let child; | ||
if (typeof children === 'function') { | ||
child = children({ disabled: !isAllowed, isSensitiveModificationEnabled }); | ||
} else { | ||
child = React.cloneElement(children as ReactElement, { disabled: !isAllowed, isSensitiveModificationEnabled }); | ||
} | ||
|
||
if (!isSensitiveModificationEnabled) { | ||
return child; | ||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
border: `1px solid ${hexToRGB(theme.palette.dangerZone.main, 0.5)}`, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
minHeight: theme.spacing(4), | ||
padding: theme.spacing(1), | ||
paddingTop: theme.spacing(0.5), | ||
borderRadius: theme.spacing(0.5), | ||
...(sx?.root ?? {}), | ||
}} | ||
> | ||
<Typography | ||
variant="h4" | ||
style={{ | ||
color: theme.palette.dangerZone.text?.primary, | ||
marginTop: theme.spacing(-1.1), | ||
marginBottom: !title ? theme.spacing(0.5) : 0, | ||
background: theme.palette.background.default, | ||
paddingLeft: theme.spacing(1), | ||
paddingRight: theme.spacing(1), | ||
fontSize: 10, | ||
textTransform: 'uppercase', | ||
fontFamily: '"Geoligica", sans-serif', | ||
fontWeight: 700, | ||
width: 'fit-content', | ||
...(sx?.title ?? {}), | ||
}} | ||
> | ||
{t_i18n('Danger Zone')}{title && (<> - {title}</>)} | ||
</Typography> | ||
{child} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DangerZoneBlock; |
Oops, something went wrong.