Skip to content

Commit

Permalink
[frontend] Trial for color in DangerZone
Browse files Browse the repository at this point in the history
  • Loading branch information
aHenryJard authored and Kedae committed Oct 3, 2024
1 parent cc18b01 commit 971c7d0
Show file tree
Hide file tree
Showing 51 changed files with 1,062 additions and 322 deletions.
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/back/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"Is family": "Ist Familie",
"Is live": "Ist live",
"Is read": "Wird gelesen",
"Is sensitive changes allowed": "Sind sensible Änderungen erlaubt?",
"Issuer": "Ausgeber",
"Issuer alternative name": "Alternativer Name des Ausstellers",
"Job title": "Berufsbezeichnung",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/back/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"Is family": "Is family",
"Is live": "Is live",
"Is read": "Is read",
"Is sensitive changes allowed": "Is sensitive changes allowed",
"Issuer": "Issuer",
"Issuer alternative name": "Issuer alternative name",
"Job title": "Job title",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/back/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"Is family": "Es familia",
"Is live": "Está vivo",
"Is read": "Se lee",
"Is sensitive changes allowed": "¿Se permiten cambios sensibles?",
"Issuer": "Emisor",
"Issuer alternative name": "Nombre alternativo del emisor",
"Job title": "Cargo",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/back/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"Is family": "Est la famille",
"Is live": "Est en direct",
"Is read": "Est lu",
"Is sensitive changes allowed": "Les modifications sensibles sont-elles autorisées ?",
"Issuer": "Émetteur",
"Issuer alternative name": "Nom alternatif de l'émetteur",
"Job title": "Titre du poste",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/back/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"Is family": "アーキテクチャの実行環境",
"Is live": "ライブ",
"Is read": "ユーザー",
"Is sensitive changes allowed": "センシティブな変更は許されるか",
"Issuer": "発行者",
"Issuer alternative name": "発行者別名",
"Job title": "配偶者の有無",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/back/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"Is family": "가족 여부",
"Is live": "실시간 여부",
"Is read": "읽음 여부",
"Is sensitive changes allowed": "민감한 변경이 허용되나요?",
"Issuer": "발행자",
"Issuer alternative name": "발행자 대체 이름",
"Job title": "직책",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/back/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"Is family": "是否属于",
"Is live": "已激活",
"Is read": "已读",
"Is sensitive changes allowed": "是否允许敏感变化",
"Issuer": "签发人",
"Issuer alternative name": "签发人替代名称",
"Job title": "职位",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"All types of relationship": "Alle Arten von Beziehungen",
"All types of target": "Alle Arten von Ziel",
"All years": "Alle Jahre",
"Allow modification of sensitive configuration": "Änderung der sensiblen Konfiguration zulassen",
"Allowed marking definitions": "Erlaubte Markierungsdefinitionen",
"Allowed markings": "Erlaubte Markierungen",
"Already in plat.": "Bereits in plat.",
Expand Down Expand Up @@ -578,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
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"All types of relationship": "All types of relationship",
"All types of target": "All types of target",
"All years": "All years",
"Allow modification of sensitive configuration": "Allow modification of sensitive configuration",
"Allowed marking definitions": "Allowed marking definitions",
"Allowed markings": "Allowed markings",
"Already in plat.": "Already in plat.",
Expand Down Expand Up @@ -578,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
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"All types of relationship": "Todos los tipos de relación",
"All types of target": "Todo los tipos de objetivo",
"All years": "Todos los años",
"Allow modification of sensitive configuration": "Permitir la modificación de la configuración sensible",
"Allowed marking definitions": "Definiciones de marcado permitidas",
"Allowed markings": "Marcas permitidas",
"Already in plat.": "Ya está en la plataforma.",
Expand Down Expand Up @@ -578,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
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"All types of relationship": "Tous les types de relation",
"All types of target": "Tous les types de cible",
"All years": "Toutes les années",
"Allow modification of sensitive configuration": "Permettre la modification d'une configuration sensible",
"Allowed marking definitions": "Définitions de marquage autorisées",
"Allowed markings": "Marquages autorisés",
"Already in plat.": "Déjà dans la plat.",
Expand Down Expand Up @@ -578,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
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"All types of relationship": "全てのリレーションシップの種別",
"All types of target": "あらゆる種類のターゲット",
"All years": "すべての年",
"Allow modification of sensitive configuration": "機密設定の変更を許可する",
"Allowed marking definitions": "許可されたマーキング定義",
"Allowed markings": "許可されるマーキング",
"Already in plat.": "すでにプラットフォームに存在します",
Expand Down Expand Up @@ -578,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
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"All types of relationship": "모든 관계 유형",
"All types of target": "모든 대상 유형",
"All years": "모든 연도",
"Allow modification of sensitive configuration": "민감한 구성의 수정 허용",
"Allowed marking definitions": "허용된 마킹 정의",
"Allowed markings": "허용된 마킹",
"Already in plat.": "이미 플랫폼에 있음",
Expand Down Expand Up @@ -578,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
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"All types of relationship": "关系的所有类型",
"All types of target": "所有类型的目标",
"All years": "所有年份",
"Allow modification of sensitive configuration": "允许修改敏感配置",
"Allowed marking definitions": "允许的标记定义",
"Allowed markings": "允许的标记",
"Already in plat.": "已经在平台",
Expand Down Expand Up @@ -578,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
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/src/private/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const meUserFragment = graphql`
id
name
}
can_manage_sensitive_config
}
`;

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;
Loading

0 comments on commit 971c7d0

Please sign in to comment.