Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frontend] Widgets code refacto #9483

Merged
merged 8 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2852,10 +2852,12 @@
"This rule has been applied on the existing data": "Diese Regel wurde auf die vorhandenen Daten angewandt",
"This score is updated with the decay rule applied to this indicator.": "Diese Punktzahl wird mit der auf diesen Indikator angewandten Verfallsregel aktualisiert.",
"This sector does not have any description.": "Für diesen Sektor gibt es keine Beschreibung.",
"This step is not implemented": "Dieser Schritt ist nicht implementiert",
"This trigger/digest has been shared with you and you are not able to modify or delete it": "Dieser Trigger/Digest wurde für Sie freigegeben und Sie können ihn nicht ändern oder löschen",
"This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.": "Dieser Benutzer erbt keine maximale Vertrauensstufe von seiner Gruppe. Konfigurieren Sie Benutzer's Gruppen mit einem maximalen Vertrauensniveau.",
"This user has no effective confidence level from the groups assigned.": "Dieser Benutzer hat kein effektives Vertrauensniveau der zugewiesenen Gruppen.",
"This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.": "Dieser Benutzer hat kein Max Confidence Level und erbt auch keines von Gruppen. Fügen Sie eine Gruppe zu diesem Benutzer hinzu, um das Problem zu beheben.",
"This value cannot be null": "Dieser Wert kann nicht null sein",
"This value is overridden for the following entity types": "Dieser Wert wird für die folgenden Entitätstypen außer Kraft gesetzt",
"Threat actor": "Bedrohungsakteur",
"Threat actor types": "Arten von Bedrohungsakteuren",
Expand Down
3 changes: 2 additions & 1 deletion opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@
"Create a vocabulary": "Create a vocabulary",
"Create a vulnerability": "Create a vulnerability",
"Create a widget": "Create a widget",
"Create a Widget": "Create a Widget",
"Create a workbench": "Create a workbench",
"Create a workspace": "Create a workspace",
"Create an area": "Create an area",
Expand Down Expand Up @@ -2856,10 +2855,12 @@
"This rule has been applied on the existing data": "This rule has been applied on the existing data",
"This score is updated with the decay rule applied to this indicator.": "This score is updated with the decay rule applied to this indicator.",
"This sector does not have any description.": "This sector does not have any description.",
"This step is not implemented": "This step is not implemented",
"This trigger/digest has been shared with you and you are not able to modify or delete it": "This trigger/digest has been shared with you and you are not able to modify or delete it",
"This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.": "This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.",
"This user has no effective confidence level from the groups assigned.": "This user has no effective confidence level from the groups assigned.",
"This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.": "This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.",
"This value cannot be null": "This value cannot be null",
"This value is overridden for the following entity types": "This value is overridden for the following entity types",
"Threat actor": "Threat actor",
"Threat actor types": "Threat actor types",
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 @@ -2852,10 +2852,12 @@
"This rule has been applied on the existing data": "Esta regla se ha aplicado a los datos existentes",
"This score is updated with the decay rule applied to this indicator.": "Esta puntuación se actualiza con la regla de decaimiento aplicada a este indicador.",
"This sector does not have any description.": "Este sector no tiene ninguna descripción.",
"This step is not implemented": "Este paso no está implementado",
"This trigger/digest has been shared with you and you are not able to modify or delete it": "Este desencadenante/digerido ha sido compartido con usted y no puede modificarlo ni eliminarlo",
"This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.": "Este usuario no hereda un nivel de confianza máximo de su grupo. Configurar grupos de usuarios con un nivel de confianza máximo.",
"This user has no effective confidence level from the groups assigned.": "Este usuario no tiene nivel de confianza efectivo de los grupos asignados.",
"This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.": "Este usuario no tiene Nivel de Confianza Máximo y no hereda uno de los grupos. Agregue un grupo a este usuario para resolver el problema.",
"This value cannot be null": "Este valor no puede ser nulo",
"This value is overridden for the following entity types": "Este valor se anula para los siguientes tipos de entidad",
"Threat actor": "Actor de amenazas",
"Threat actor types": "Tipos de actor de amenazas",
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 @@ -2852,10 +2852,12 @@
"This rule has been applied on the existing data": "Cette règle a été appliquée sur les données de la plateforme",
"This score is updated with the decay rule applied to this indicator.": "Ce score est mis à jour avec la règle de désintégration appliquée à cet indicateur.",
"This sector does not have any description.": "Ce secteur n'a aucune description.",
"This step is not implemented": "Cette étape n'est pas mise en œuvre",
"This trigger/digest has been shared with you and you are not able to modify or delete it": "Ce déclencheur/digest a été partagé avec vous et vous n'êtes pas en mesure de le modifier ou de le supprimer",
"This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.": "Cet utilisateur n'hérite pas d'un niveau de confiance maximum de son groupe. Configurer les groupes d'utilisateurs avec un niveau de confiance maximum.",
"This user has no effective confidence level from the groups assigned.": "Cet utilisateur n'a pas de niveau de confiance effectif dans les groupes qui lui ont été attribués.",
"This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.": "Cet utilisateur n'a pas de niveau de confiance maximal et n'en hérite pas des groupes. Ajoutez un groupe à cet utilisateur pour résoudre le problème.",
"This value cannot be null": "Cette valeur ne peut être nulle",
"This value is overridden for the following entity types": "Cette valeur est remplacée pour les types d'entités suivants",
"Threat actor": "Acteur",
"Threat actor types": "Type d'acteur",
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 @@ -2852,10 +2852,12 @@
"This rule has been applied on the existing data": "既存のデータにルールを適用しました",
"This score is updated with the decay rule applied to this indicator.": "このスコアはこのインジケータに適用される減衰ルールで更新される。",
"This sector does not have any description.": "このセクターには説明がありません。",
"This step is not implemented": "このステップは実装されていません",
"This trigger/digest has been shared with you and you are not able to modify or delete it": "このトリガー/ダイジェストはあなたと共有され、あなたはそれを変更または削除することはできません。",
"This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.": "このユーザはグループから最大信頼レベルを継承しません。最大信頼レベルを持つユーザーグループを設定します。",
"This user has no effective confidence level from the groups assigned.": "このユーザーには、割り当てられたグループからの有効な信頼レベルがありません。",
"This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.": "このユーザーには最大信頼度がなく、グループからの信頼度も継承していません。この問題を解決するには、このユーザーにグループを追加してください。",
"This value cannot be null": "この値をNULLにすることはできない",
"This value is overridden for the following entity types": "この値は以下のエンティティ・タイプでオーバーライドされます。",
"Threat actor": "脅威アクター",
"Threat actor types": "脅威アクターの種別",
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 @@ -2852,10 +2852,12 @@
"This rule has been applied on the existing data": "이 규칙은 기존 데이터에 적용되었습니다",
"This score is updated with the decay rule applied to this indicator.": "이 점수는 이 인디케이터에 적용된 감소 규칙으로 업데이트됩니다.",
"This sector does not have any description.": "이 부문에는 설명이 없습니다.",
"This step is not implemented": "이 단계는 구현되지 않습니다",
"This trigger/digest has been shared with you and you are not able to modify or delete it": "이 트리거/다이제스트가 귀하와 공유되었으며 수정 또는 삭제할 수 없습니다",
"This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.": "이 사용자는 그룹에서 최대 신뢰 수준을 상속받지 않습니다. 사용자 그룹을 최대 신뢰 수준으로 구성하십시오.",
"This user has no effective confidence level from the groups assigned.": "이 사용자는 할당된 그룹에서 유효한 신뢰 수준이 없습니다.",
"This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.": "이 사용자는 최대 신뢰 수준이 없으며 그룹에서 상속받지 않습니다. 이 사용자를 그룹에 추가하여 문제를 해결하십시오.",
"This value cannot be null": "이 값은 null일 수 없습니다",
"This value is overridden for the following entity types": "이 값은 다음 엔터티 유형에 대해 재정의됩니다",
"Threat actor": "위협 행위자",
"Threat actor types": "위협 행위자 유형",
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 @@ -2852,10 +2852,12 @@
"This rule has been applied on the existing data": "该规则已应用于现有数据",
"This score is updated with the decay rule applied to this indicator.": "该分数会根据适用于该指标的衰减规则进行更新。",
"This sector does not have any description.": "此部门没有任何描述。",
"This step is not implemented": "此步骤未执行",
"This trigger/digest has been shared with you and you are not able to modify or delete it": "这个触发器/摘要已经与你共享,你不能修改或删除它。",
"This user does not inherit a Max Confidence Level from their group. Configure user's groups with a Max Confidence Level.": "该用户不继承其组的最大置信度。为用户组配置最大置信度。",
"This user has no effective confidence level from the groups assigned.": "该用户没有指定组的有效信任级别。",
"This user has no Max Confidence Level and does not inherit one from groups. Add a group to this user to resolve the issue.": "该用户没有最大信任度,也没有从组中继承最大信任度。为该用户添加一个组来解决问题。",
"This value cannot be null": "该值不能为空",
"This value is overridden for the following entity types": "以下实体类型可重载该值",
"Threat actor": "威胁主体",
"Threat actor types": "威胁主体类型",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import React, { FunctionComponent, useState } from 'react';
import { v4 as uuid } from 'uuid';
import WidgetCreationTypes from '@components/widgets/WidgetCreationTypes';
import WidgetCreationPerspective from '@components/widgets/WidgetCreationPerspective';
import WidgetCreationDataSelection from '@components/widgets/WidgetCreationDataSelection';
import WidgetCreationParameters from '@components/widgets/WidgetCreationParameters';
import MenuItem from '@mui/material/MenuItem';
import WidgetUpsert from '@components/widgets/WidgetUpsert';
import { emptyFilterGroup } from '../../../utils/filters/filtersUtils';
import { useFormatter } from '../../../components/i18n';
import type { Widget } from '../../../utils/widget/widget';
import { WidgetPerspective } from './widgetUtils';

interface WidgetConfigProps {
onComplete: (value: Widget) => void,
open: boolean,
setOpen: (open: boolean) => void,
closeMenu?: () => void,
widget?: Widget,
}

const WidgetConfig: FunctionComponent<WidgetConfigProps> = ({
onComplete,
closeMenu,
widget,
setOpen,
open,
}) => {
let initialStep = 0;
if (widget?.type === 'text') {
initialStep = 3;
} else if (widget?.dataSelection) {
initialStep = 2;
}
const { t_i18n } = useFormatter();
const [stepIndex, setStepIndex] = useState(initialStep);
const [type, setType] = useState<string | null>(widget?.type ?? null);
const [perspective, setPerspective] = useState(widget?.perspective ?? null);
const initialSelection = {
label: '',
attribute: 'entity_type',
date_attribute: 'created_at',
perspective: null,
isTo: true,
filters: emptyFilterGroup,
dynamicFrom: emptyFilterGroup,
dynamicTo: emptyFilterGroup,
};
const [dataSelection, setDataSelection] = useState(
widget?.dataSelection ?? [initialSelection],
);
const [parameters, setParameters] = useState(widget?.parameters ?? {});

const handleCloseAfterCancel = () => {
if (!widget) {
setStepIndex(0);
setType(null);
setPerspective(null);
setDataSelection([initialSelection]);
setParameters({});
} else if (widget.type === 'text') {
setStepIndex(3);
} else {
setStepIndex(2);
}
setOpen(false);
setDataSelection(widget?.dataSelection ?? [initialSelection]);
};

const handleCloseAfterUpdate = () => {
if (!widget) {
setStepIndex(0);
setType(null);
setPerspective(null);
setDataSelection([initialSelection]);
setParameters({});
} else if (widget.type === 'text') {
setStepIndex(3);
} else {
setStepIndex(2);
}
setOpen(false);
};
const completeSetup = () => {
if (type) {
onComplete({
...(widget ?? {}),
id: widget?.id ?? uuid(),
type,
perspective,
dataSelection,
parameters,
});
}
handleCloseAfterUpdate();
};
const handleSelectType = (selectedType: string) => {
setType(selectedType);
if (selectedType === 'text') {
setStepIndex(3);
} else {
setStepIndex(1);
}
};
const handleSelectPerspective = (selectedPerspective: WidgetPerspective) => {
const newDataSelection = dataSelection.map((n) => ({
...n,
perspective: selectedPerspective,
filters: selectedPerspective === n.perspective ? n.filters : emptyFilterGroup,
dynamicFrom: selectedPerspective === n.perspective ? n.dynamicFrom : emptyFilterGroup,
dynamicTo: selectedPerspective === n.perspective ? n.dynamicTo : emptyFilterGroup,
}));
setDataSelection(newDataSelection);
setPerspective(selectedPerspective);
setStepIndex(2);
};

const isDataSelectionAttributesValid = () => {
for (const n of dataSelection) {
if (n.attribute?.length === 0) {
return false;
}
}
return true;
};
const getStepContent = () => {
switch (stepIndex) {
case 0:
return <WidgetCreationTypes handleSelectType={handleSelectType} />;
case 1:
return <WidgetCreationPerspective handleSelectPerspective={handleSelectPerspective} type={type as string} />;
case 2:
return <WidgetCreationDataSelection
dataSelection={dataSelection}
setDataSelection={setDataSelection}
perspective={perspective as WidgetPerspective}
type={type as string}
setStepIndex={setStepIndex}
/>;
case 3:
return <WidgetCreationParameters
dataSelection={dataSelection}
setDataSelection={setDataSelection}
parameters={parameters}
setParameters={setParameters}
type={type as string}
/>;
default:
return <div>${t_i18n('This step is not implemented')}</div>;
}
};
return (
<>
{widget && (
<MenuItem
onClick={() => {
closeMenu?.();
setOpen(true);
}}
>
{t_i18n('Update')}
</MenuItem>
)}
<WidgetUpsert
open={open}
handleCloseAfterCancel={handleCloseAfterCancel}
stepIndex={stepIndex}
setStepIndex={setStepIndex}
getStepContent={getStepContent}
completeSetup={completeSetup}
isDataSelectionAttributesValid={isDataSelectionAttributesValid}
widget={widget}
type={type}
/>
</>
);
};

export default WidgetConfig;
Loading