Skip to content

Commit

Permalink
[frontend] Trial for color in DangerZone (#8284)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kedae authored Oct 4, 2024
1 parent 1f2f2fa commit a277b00
Show file tree
Hide file tree
Showing 35 changed files with 673 additions and 421 deletions.
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@
"CVSS3 - Integrity impact (I)": "CVSS3 - Auswirkungen auf die Integrität (I)",
"CVSS3 - Score": "CVSS3 - Bewertung",
"CVSS3 - Severity": "CVSS3 - Schweregrad",
"Danger Zone": "Gefahrenzone",
"DangerZoneTooltip": "Eine Änderung der Konfiguration an dieser Stelle könnte erhebliche Auswirkungen auf die Stabilität der Plattform haben. Nur Benutzer mit der Fähigkeit, sensible Konfigurationen zu ändern, dürfen dies tun. Stellen Sie sicher, dass Sie wissen, was Sie tun.",
"Dark": "Dunkel",
"Dark (with background)": "Dunkel (mit Hintergrund)",
"Dark (without background)": "Dunkel (ohne Hintergrund)",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@
"CVSS3 - Integrity impact (I)": "CVSS3 - Integrity impact (I)",
"CVSS3 - Score": "CVSS3 - Score",
"CVSS3 - Severity": "CVSS3 - Severity",
"Danger Zone": "Danger Zone",
"DangerZoneTooltip": "Changing the configuration here could have a significant impact on the stability of the platform. Only users with the capability to change sensitive configurations are allowed to do so. Make sure you know what you are doing.",
"Dark": "Dark",
"Dark (with background)": "Dark (with background)",
"Dark (without background)": "Dark (without background)",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@
"CVSS3 - Integrity impact (I)": "CVSS3 - Impacto en la integridad (I)",
"CVSS3 - Score": "CVSS3 - Puntuación",
"CVSS3 - Severity": "CVSS3 - Gravedad",
"Danger Zone": "Zona de peligro",
"DangerZoneTooltip": "Cambiar la configuración aquí podría tener un impacto significativo en la estabilidad de la plataforma. Sólo los usuarios con capacidad para cambiar configuraciones sensibles pueden hacerlo. Asegúrate de que sabes lo que estás haciendo.",
"Dark": "Oscuro",
"Dark (with background)": "Oscuro (con fondo)",
"Dark (without background)": "Oscuro (sin fondo)",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@
"CVSS3 - Integrity impact (I)": "CVSS3 - Impact sur l'intégrité (I)",
"CVSS3 - Score": "CVSS3 - Score",
"CVSS3 - Severity": "CVSS3 - Gravité",
"Danger Zone": "Zone de danger",
"DangerZoneTooltip": "La modification de la configuration ici peut avoir un impact significatif sur la stabilité de la plateforme. Seuls les utilisateurs ayant la capacité de modifier des configurations sensibles sont autorisés à le faire. Assurez-vous de savoir ce que vous faites.",
"Dark": "Sombre",
"Dark (with background)": "Sombre (avec arrière-plan)",
"Dark (without background)": "Sombre (sans arrière-plan)",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@
"CVSS3 - Integrity impact (I)": "CVSS3 - 完全性への影響 (I)",
"CVSS3 - Score": "CVSS3 - スコア",
"CVSS3 - Severity": "CVSS3 - 重大度",
"Danger Zone": "危険地帯",
"DangerZoneTooltip": "ここで設定を変更すると、プラットフォームの安定性に重大な影響を及ぼす可能性がある。重要なコンフィギュレーションを変更できるのは、その権限を持つユーザーだけです。自分が何をしているのかをよく理解してください。",
"Dark": "ダークテーマ",
"Dark (with background)": "ダークテーマ (背景有り)",
"Dark (without background)": "ダークテーマ (背景無し)",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@
"CVSS3 - Integrity impact (I)": "CVSS3 - 무결성 영향 (I)",
"CVSS3 - Score": "CVSS3 - 점수",
"CVSS3 - Severity": "CVSS3 - 심각도",
"Danger Zone": "위험 구역",
"DangerZoneTooltip": "여기서 구성을 변경하면 플랫폼의 안정성에 중대한 영향을 미칠 수 있습니다. 민감한 구성을 변경할 수 있는 권한이 있는 사용자만 변경할 수 있습니다. 자신이 수행하는 작업에 대해 잘 알고 있는지 확인하세요.",
"Dark": "어두운",
"Dark (with background)": "어두운 (배경 포함)",
"Dark (without background)": "어두운 (배경 없음)",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@
"CVSS3 - Integrity impact (I)": "CVSS3 - 完整性影响 (I)",
"CVSS3 - Score": "CVSS3 - 得分",
"CVSS3 - Severity": "CVSS3 - 严重程度",
"Danger Zone": "危险地带",
"DangerZoneTooltip": "更改这里的配置可能会对平台的稳定性产生重大影响。只有有能力更改敏感配置的用户才能更改。请确保您知道自己在做什么。",
"Dark": "暗色",
"Dark (with background)": "暗色(带背景)",
"Dark (without background)": "暗色(无背景)",
Expand Down
13 changes: 10 additions & 3 deletions opencti-platform/opencti-front/src/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MUIBreadcrumbs from '@mui/material/Breadcrumbs';
import { Link } from 'react-router-dom';
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/styles';
import DangerZoneChip from '@components/common/dangerZone/DangerZoneChip';
import { truncate } from '../utils/String';
import type { Theme } from './Theme';

Expand All @@ -13,17 +14,23 @@ interface element {
}

interface BreadcrumbsProps {
elements: element[],
elements: element[]
isSensitive?: boolean
}

const Breadcrumbs: FunctionComponent<BreadcrumbsProps> = ({ elements }) => {
const Breadcrumbs: FunctionComponent<BreadcrumbsProps> = ({ elements, isSensitive = false }) => {
const theme = useTheme<Theme>();
return (
<MUIBreadcrumbs style={{ marginBottom: theme.spacing(2) }}>
{elements.map((element) => {
if (element.current) {
return (
<Typography key={element.label} color="text.primary">{truncate(element.label, 30, false)}</Typography>
<span key={element.label} style={{ display: 'flex', alignItems: 'center' }}>
<Typography color={'text.primary'}>
{truncate(element.label, 30, false)}
</Typography>
{isSensitive && <DangerZoneChip />}
</span>
);
}
if (!element.link) {
Expand Down
15 changes: 15 additions & 0 deletions opencti-platform/opencti-front/src/components/Theme.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Theme as MuiTheme, ThemeOptions } from '@mui/material/styles/createThem
declare module '@mui/material/IconButton' {
interface IconButtonPropsColorOverrides {
ee: true
dangerZone: true
}
}

Expand All @@ -26,9 +27,22 @@ declare module '@mui/material/SvgIcon' {
}
}

declare module '@mui/material/Fab' {
interface FabPropsColorOverrides {
dangerZone: true
}
}

declare module '@mui/material/Alert' {
interface AlertPropsColorOverrides {
dangerZone: true
}
}

interface ExtendedColor extends PaletteColorOptions {
main: string
dark: string
light: string
palette: ExtendedPaletteOptions
text: Partial<TypeText>
mode: PaletteMode
Expand All @@ -52,6 +66,7 @@ interface ExtendedPaletteOptions extends PaletteOptions {
pagination: string
lightBackground?: string
}
dangerZone: Partial<ExtendedColor>
primary: Partial<ExtendedColor>
error: Partial<ExtendedColor>
success: Partial<ExtendedColor>
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/src/components/ThemeDark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ThemeDark = (
main: '#f44336',
dark: '#c62828',
},
dangerZone: { main: '#f6685e', light: '#fbc2be', dark: '#f44336', contrastText: 'black', text: { primary: '#fbc2be' } },
success: { main: '#03a847' },
primary: { main: primary || THEME_DARK_DEFAULT_PRIMARY },
secondary: { main: secondary || THEME_DARK_DEFAULT_SECONDARY },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ThemeLight = (
main: '#f44336',
dark: '#c62828',
},
dangerZone: { main: '#f6685e', light: '#fbc2be', dark: '#D1584F', contrastText: 'black', text: { primary: '#D1584F' } },
success: { main: '#03a847' },
primary: { main: primary || THEME_LIGHT_DEFAULT_PRIMARY },
secondary: { main: secondary || THEME_LIGHT_DEFAULT_SECONDARY },
Expand Down
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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { useTheme } from '@mui/styles';
import Tooltip from '@mui/material/Tooltip';
import type { Theme } from '../../../../components/Theme';
import { useFormatter } from '../../../../components/i18n';

const DangerZoneChip = () => {
const { t_i18n } = useFormatter();
const theme = useTheme<Theme>();
return (
<div
style={{
fontSize: 'xx-small',
textTransform: 'uppercase',
fontWeight: 500,
height: 14,
display: 'inline-flex',
justifyContent: 'center',
alignItems: 'center',
marginTop: theme.spacing(0.25),
marginLeft: theme.spacing(0.5),
padding: `${theme.spacing(1)} ${theme.spacing(0.5)}`,
borderRadius: theme.borderRadius,
border: `1px solid ${theme.palette.dangerZone.main}`,
color: theme.palette.dangerZone.text?.primary,
backgroundColor: 'transparent',
}}
>
<Tooltip
title={t_i18n('DangerZoneTooltip')}
>
<>
Danger Zone
</>
</Tooltip>
</div>
);
};

export default DangerZoneChip;
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ interface DrawerProps {
header?: React.ReactElement;
controlledDial?: DrawerControlledDialType;
containerStyle?: CSSProperties
disabled?: boolean
isSensitive?: boolean
}

// eslint-disable-next-line react/display-name
Expand All @@ -91,6 +93,8 @@ const Drawer = forwardRef(({
header,
controlledDial,
containerStyle,
disabled = false,
isSensitive = false,
}: DrawerProps, ref) => {
const {
bannerSettings: { bannerHeightNumber },
Expand Down Expand Up @@ -127,8 +131,9 @@ const Drawer = forwardRef(({
{variant && (
<Fab
onClick={() => setOpen(true)}
color="primary"
color={isSensitive ? 'dangerZone' : 'primary'}
aria-label={update ? 'Edit' : 'Add'}
disabled={disabled}
className={classNames({
[classes.mainButton]: true,
[classes.withPanel]: [
Expand Down
Loading

0 comments on commit a277b00

Please sign in to comment.