Skip to content

Commit

Permalink
[frontend] roll back to pre expansion state added with session storag…
Browse files Browse the repository at this point in the history
…e history (#3167)
  • Loading branch information
ValentinBouzinFiligran committed Mar 25, 2024
1 parent 372a1df commit afe5ee2
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 20 deletions.
6 changes: 5 additions & 1 deletion opencti-platform/opencti-front/lang/back/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,9 @@
"X_Aliases": "X_Aliases",
"Samples": "Stichproben",
"Contains observable": "Enthält beobachtbar",
"Artifact content": "Artefaktinhalt"
"Artifact content": "Artefaktinhalt",
"Entity ID": "Entitäts-ID",
"Source connector": "Quellverbinder",
"Malware analysis operating System": "Betriebssystem der Malware-Analyse",
"Allowed markings": "Erlaubte Markierungen"
}
6 changes: 5 additions & 1 deletion opencti-platform/opencti-front/lang/back/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,9 @@
"X_Aliases": "X_Aliases",
"Samples": "Samples",
"Contains observable": "Contains observable",
"Artifact content": "Artifact content"
"Artifact content": "Artifact content",
"Entity ID": "Entity ID",
"Source connector": "Source connector",
"Malware analysis operating System": "Malware analysis operating System",
"Allowed markings": "Allowed markings"
}
6 changes: 5 additions & 1 deletion opencti-platform/opencti-front/lang/back/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,9 @@
"X_Aliases": "X_Aliases",
"Samples": "Muestras",
"Contains observable": "Contiene observable",
"Artifact content": "Contenido del artefacto"
"Artifact content": "Contenido del artefacto",
"Entity ID": "Entidad ID",
"Source connector": "Conector fuente",
"Malware analysis operating System": "Sistema operativo de análisis de malware",
"Allowed markings": "Marcas permitidas"
}
6 changes: 5 additions & 1 deletion opencti-platform/opencti-front/lang/back/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,9 @@
"X_Aliases": "X_Aliases",
"Samples": "Échantillons",
"Contains observable": "Contient des observables",
"Artifact content": "Contenu de l'artefact"
"Artifact content": "Contenu de l'artefact",
"Entity ID": "ID de l'entité",
"Source connector": "Connecteur source",
"Malware analysis operating System": "Système d'exploitation pour l'analyse des logiciels malveillants",
"Allowed markings": "Marques autorisées"
}
6 changes: 5 additions & 1 deletion opencti-platform/opencti-front/lang/back/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,9 @@
"X_Aliases": "X_エイリアス",
"Samples": "サンプル",
"Contains observable": "観測値を含む",
"Artifact content": "人工物の内容"
"Artifact content": "人工物の内容",
"Entity ID": "エンティティID",
"Source connector": "ソースコネクター",
"Malware analysis operating System": "マルウェア解析オペレーティングシステム",
"Allowed markings": "許可マーク"
}
8 changes: 6 additions & 2 deletions opencti-platform/opencti-front/lang/back/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,9 @@
"X_Aliases": "X_别名",
"Samples": "样本",
"Contains observable": "包含观测值",
"Artifact content": "工件内容"
}
"Artifact content": "工件内容",
"Entity ID": "实体 ID",
"Source connector": "源连接器",
"Malware analysis operating System": "恶意软件分析操作系统",
"Allowed markings": "允许的标记"
}
13 changes: 11 additions & 2 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2673,5 +2673,14 @@
"Strategic": "Strategisch",
"Link created": "Link erstellt",
"Public dashboard": "Öffentliches Dashboard",
"Unless specific groups are selected, user will be created with default groups only.": "Wenn keine spezifischen Gruppen ausgewählt werden, wird der Benutzer nur mit den Standardgruppen erstellt."
}
"Unless specific groups are selected, user will be created with default groups only.": "Wenn keine spezifischen Gruppen ausgewählt werden, wird der Benutzer nur mit den Standardgruppen erstellt.",
"Most used filters": "Meist verwendete Filter",
"All other filters": "Alle anderen Filter",
"Testing csv mapper": "Csv-Mapper testen",
"This operations will only apply on labels or markings added in the context of this playbook such as enrichment or other knowledge manipulations but not if the labels or markings are already written in the platform.": "Diese Operationen gelten nur für Labels oder Markierungen, die im Kontext dieses Playbooks hinzugefügt werden, wie z. B. Anreicherung oder andere Wissensmanipulationen, nicht aber, wenn die Labels oder Markierungen bereits in der Plattform geschrieben sind.",
"Restore the state of the graphic before the last expansion": "Wiederherstellung des Zustands der Grafik vor der letzten Erweiterung",
"Revert to Pre-Expansion State": "Zurückkehren zum Zustand vor der Erweiterung",
"All actions after the last expansion will be lost": "Alle Aktionen nach der letzten Erweiterung gehen verloren",
"Last expansion": "Letzte Erweiterung",
"All actions after the last expansion will be lost.": "Alle Aktionen nach der letzten Erweiterung gehen verloren."
}
13 changes: 11 additions & 2 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,10 @@
"Create investigation": "Create investigation",
"Update dashboard": "Update dashboard",
"Update investigation": "Update investigation",
"Restore the state of the graphic before the last expansion": "Restore the state of the graphic before the last expansion",
"Revert to Pre-Expansion State": "Revert to Pre-Expansion State",
"Last expansion": "Last expansion",
"All actions after the last expansion will be lost": "All actions after the last expansion will be lost",
"Add a widget": "Add a widget",
"Update a widget": "Update a widget",
"Update an artifact": "Update an artifact",
Expand Down Expand Up @@ -2673,5 +2677,10 @@
"Operational": "Operational",
"Strategic": "Strategic",
"Link created": "Link created",
"Public dashboard": "Public dashboard"
}
"Public dashboard": "Public dashboard",
"Most used filters": "Most used filters",
"All other filters": "All other filters",
"Testing csv mapper": "Testing csv mapper",
"This operations will only apply on labels or markings added in the context of this playbook such as enrichment or other knowledge manipulations but not if the labels or markings are already written in the platform.": "This operations will only apply on labels or markings added in the context of this playbook such as enrichment or other knowledge manipulations but not if the labels or markings are already written in the platform.",
"All actions after the last expansion will be lost.": "All actions after the last expansion will be lost."
}
13 changes: 11 additions & 2 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -2673,5 +2673,14 @@
"Strategic": "Estratégico",
"Link created": "Enlace creado",
"Public dashboard": "Cuadro de mandos público",
"Unless specific groups are selected, user will be created with default groups only.": "A menos que se seleccionen grupos específicos, el usuario se creará sólo con los grupos por defecto."
}
"Unless specific groups are selected, user will be created with default groups only.": "A menos que se seleccionen grupos específicos, el usuario se creará sólo con los grupos por defecto.",
"Most used filters": "Filtros más utilizados",
"All other filters": "Todos los demás filtros",
"Testing csv mapper": "Probando el mapeador csv",
"This operations will only apply on labels or markings added in the context of this playbook such as enrichment or other knowledge manipulations but not if the labels or markings are already written in the platform.": "Estas operaciones sólo se aplicarán a las etiquetas o marcas añadidas en el contexto de este libro de jugadas, como el enriquecimiento u otras manipulaciones del conocimiento, pero no si las etiquetas o marcas ya están escritas en la plataforma.",
"Restore the state of the graphic before the last expansion": "Restaurar el estado del gráfico antes de la última ampliación",
"Revert to Pre-Expansion State": "Volver al estado anterior a la expansión",
"All actions after the last expansion will be lost": "Todas las acciones posteriores a la última expansión se perderán",
"Last expansion": "Última expansión",
"All actions after the last expansion will be lost.": "Todas las acciones posteriores a la última expansión se perderán."
}
13 changes: 11 additions & 2 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2673,5 +2673,14 @@
"Strategic": "Stratégique",
"Link created": "Lien créé",
"Public dashboard": "Tableau de bord public",
"Unless specific groups are selected, user will be created with default groups only.": "À moins que des groupes spécifiques ne soient sélectionnés, l'utilisateur sera créé avec les groupes par défaut uniquement."
}
"Unless specific groups are selected, user will be created with default groups only.": "À moins que des groupes spécifiques ne soient sélectionnés, l'utilisateur sera créé avec les groupes par défaut uniquement.",
"Most used filters": "Filtres les plus utilisés",
"All other filters": "Tous les autres filtres",
"Testing csv mapper": "Test du mappeur csv",
"This operations will only apply on labels or markings added in the context of this playbook such as enrichment or other knowledge manipulations but not if the labels or markings are already written in the platform.": "Ces opérations ne s'appliqueront qu'aux étiquettes ou marquages ajoutés dans le contexte de ce playbook, comme l'enrichissement ou d'autres manipulations de connaissances, mais pas si les étiquettes ou marquages sont déjà écrits dans la plateforme.",
"Restore the state of the graphic before the last expansion": "Rétablir l'état du graphique avant la dernière expansion",
"Revert to Pre-Expansion State": "Retour à l'état antérieur à l'expansion",
"All actions after the last expansion will be lost": "Toutes les actions postérieures à la dernière expansion seront perdues",
"Last expansion": "Dernière extension",
"All actions after the last expansion will be lost.": "Toutes les actions effectuées après la dernière expansion seront perdues."
}
13 changes: 11 additions & 2 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -2673,5 +2673,14 @@
"Strategic": "戦略的",
"Link created": "リンク作成",
"Public dashboard": "公開ダッシュボード",
"Unless specific groups are selected, user will be created with default groups only.": "特定のグループを選択しない限り、ユーザーはデフォルトのグループのみで作成されます。"
}
"Unless specific groups are selected, user will be created with default groups only.": "特定のグループを選択しない限り、ユーザーはデフォルトのグループのみで作成されます。",
"Most used filters": "最もよく使われるフィルター",
"All other filters": "その他のフィルター",
"Testing csv mapper": "csvマッパーのテスト",
"This operations will only apply on labels or markings added in the context of this playbook such as enrichment or other knowledge manipulations but not if the labels or markings are already written in the platform.": "この操作は、エンリッチメントやその他の知識操作など、このプレイブックのコンテキストで追加されたラベルやマーキングに対してのみ適用されます。",
"Restore the state of the graphic before the last expansion": "最後の拡張前のグラフィックの状態を復元する。",
"Revert to Pre-Expansion State": "拡張前の状態に戻す",
"All actions after the last expansion will be lost": "最後の拡張以降のすべてのアクションが失われる",
"Last expansion": "最後の拡張",
"All actions after the last expansion will be lost.": "最後の拡張以降のアクションはすべて失われます。"
}
13 changes: 11 additions & 2 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -2673,5 +2673,14 @@
"Strategic": "战略",
"Link created": "创建的链接",
"Public dashboard": "公共仪表板",
"Unless specific groups are selected, user will be created with default groups only.": "除非选择了特定组,否则创建的用户将只包含默认组。"
}
"Unless specific groups are selected, user will be created with default groups only.": "除非选择了特定组,否则创建的用户将只包含默认组。",
"Most used filters": "最常用的过滤器",
"All other filters": "所有其他滤波器",
"Testing csv mapper": "测试 csv 映射器",
"This operations will only apply on labels or markings added in the context of this playbook such as enrichment or other knowledge manipulations but not if the labels or markings are already written in the platform.": "此操作仅适用于在此播放列表中添加的标签或标记,如充实或其他知识操作,但不适用于平台中已写入的标签或标记。",
"Restore the state of the graphic before the last expansion": "恢复上次扩展前的图形状态",
"Revert to Pre-Expansion State": "恢复到扩展前状态",
"All actions after the last expansion will be lost": "上次扩展后的所有操作都将丢失",
"Last expansion": "最后扩",
"All actions after the last expansion will be lost.": "最后一次扩展后的所有操作都将丢失。"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';
import Button from '@mui/material/Button';
import { useFormatter } from 'src/components/i18n';

type InvestigationRollBackExpandDialogProps = {
closeDialog: () => void;
handleRollBackToPreExpansionState: () => void;
isRollBackPreExpandStateDialogOpen: boolean;
};

const InvestigationRollBackExpandDialog = ({ closeDialog, handleRollBackToPreExpansionState, isRollBackPreExpandStateDialogOpen }: InvestigationRollBackExpandDialogProps) => {
const { t_i18n, fldt } = useFormatter();

const handleSubmit = () => {
handleRollBackToPreExpansionState();
closeDialog();
};

const getLastRollBackExpandDate = () => {
const storedPreExpansion = sessionStorage.getItem('preExpansionStateList');
if (storedPreExpansion) {
return fldt(JSON.parse(storedPreExpansion)[0].dateTime);
}
return null;
};

return (
<Dialog
PaperProps={{ elevation: 1 }}
open={isRollBackPreExpandStateDialogOpen}
onClose={closeDialog}
fullWidth={true}
maxWidth="sm"
>
<DialogTitle>{t_i18n('Revert to Pre-Expansion State')}</DialogTitle>
<DialogContent>
<p>{t_i18n('Last expansion')}: {getLastRollBackExpandDate()}</p>
<p>{t_i18n('All actions after the last expansion will be lost.')}</p>
</DialogContent>
<DialogActions>
<Button onClick={closeDialog}>{t_i18n('Cancel')}</Button>
<Button onClick={handleSubmit} color="secondary">{t_i18n('Validate')}</Button>
</DialogActions>
</Dialog>
);
};

export default InvestigationRollBackExpandDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { withRouter } from 'react-router-dom';
import { Subject, timer } from 'rxjs';
import { debounce } from 'rxjs/operators';
import SpriteText from 'three-spritetext';
import InvestigationRollBackExpandDialog from './Dialog/InvestigationRollBackExpandDialog';
import InvestigationExpandForm from './InvestigationExpandForm';
import inject18n from '../../../../components/i18n';
import { commitMutation, fetchQuery, MESSAGING$ } from '../../../../relay/environment';
Expand Down Expand Up @@ -965,6 +966,7 @@ class InvestigationGraphComponent extends Component {
prevClick: null,
navOpen: localStorage.getItem('navOpen') === 'true',
openCreatedRelation: false,
isRollBackPreExpandStateDialogOpen: false,
};
this.canvas = null;
}
Expand Down Expand Up @@ -1538,7 +1540,6 @@ class InvestigationGraphComponent extends Component {

async handleDeleteSelected() {
let idsToRemove = [];

// Retrieve selected links
const selectedLinks = Array.from(this.selectedLinks);
const selectedLinksIds = R.filter(
Expand Down Expand Up @@ -1835,6 +1836,7 @@ class InvestigationGraphComponent extends Component {
this.fetchObjectRelCounts(newElements);
}
if (newElementsIds.length > 0) {
this.setPreExpansionStateOnSessionStorage(newElementsIds);
this.graphData = buildGraphData(
this.graphObjects,
decodeGraphData(this.props.workspace.graph_data),
Expand Down Expand Up @@ -1879,6 +1881,80 @@ class InvestigationGraphComponent extends Component {
this.handleToggleDisplayProgress();
}

// eslint-disable-next-line class-methods-use-this
setPreExpansionStateOnSessionStorage(investigatedEntitiesIdsList) {
const storedPreExpansion = sessionStorage.getItem('preExpansionStateList');
const currentStoredPreExpansion = storedPreExpansion ? JSON.parse(storedPreExpansion) : [];

currentStoredPreExpansion.unshift({
dateTime: new Date().getTime(),
investigatedEntitiesIdsList,
});

if (currentStoredPreExpansion.length > 10) currentStoredPreExpansion.pop();

sessionStorage.setItem('preExpansionStateList', JSON.stringify(currentStoredPreExpansion));
}

handleRollBackToPreExpansionState() {
const storedPreExpansion = sessionStorage.getItem('preExpansionStateList');

if (storedPreExpansion) {
const currentStoredPreExpansion = JSON.parse(storedPreExpansion);
const { investigatedEntitiesIdsList } = currentStoredPreExpansion[0];

commitMutation({
mutation: investigationAddStixCoreObjectsLinesRelationsDeleteMutation,
variables: {
id: this.props.workspace.id,
input: {
key: 'investigated_entities_ids',
value: investigatedEntitiesIdsList,
operation: 'remove',
},
},
onCompleted: () => {
const currentGraphObjects = this.graphObjects;
const newGraphObjects = currentGraphObjects.filter((graphObjects) => !investigatedEntitiesIdsList.includes(graphObjects.id));

this.graphObjects = newGraphObjects;

this.graphData = buildGraphData(
newGraphObjects,
decodeGraphData(this.props.workspace.graph_data),
this.props.t,
);

this.setState({
graphData: applyFilters(
this.graphData,
this.state.stixCoreObjectsTypes,
this.state.markedBy,
this.state.createdBy,
[],
this.state.selectedTimeRangeInterval,
),
});

currentStoredPreExpansion.shift();
if (currentStoredPreExpansion.length === 0) {
sessionStorage.removeItem('preExpansionStateList');
} else {
sessionStorage.setItem('preExpansionStateList', JSON.stringify(currentStoredPreExpansion));
}
},
});
}
}

handleOpenRollBackToPreExpansionStateDialog() {
this.setState({ isRollBackPreExpandStateDialogOpen: true });
}

handleCloseRollBackToPreExpansionStateDialog() {
this.setState({ isRollBackPreExpandStateDialogOpen: false });
}

handleResetLayout() {
this.graphData = buildGraphData(this.graphObjects, {}, this.props.t);
this.setState(
Expand Down Expand Up @@ -1977,6 +2053,7 @@ class InvestigationGraphComponent extends Component {
height,
openExpandElements,
navOpen,
isRollBackPreExpandStateDialogOpen,
} = this.state;
const timeRangeInterval = computeTimeRangeInterval(this.graphObjects);
const timeRangeValues = computeTimeRangeValues(
Expand Down Expand Up @@ -2012,9 +2089,17 @@ class InvestigationGraphComponent extends Component {
onReset={this.onResetExpandElements.bind(this)}
/>
</Dialog>

<InvestigationRollBackExpandDialog
isRollBackPreExpandStateDialogOpen={isRollBackPreExpandStateDialogOpen}
closeDialog={this.handleCloseRollBackToPreExpansionStateDialog.bind(this)}
handleRollBackToPreExpansionState={this.handleRollBackToPreExpansionState.bind(this)}
/>

<InvestigationGraphBar
displayProgress={displayProgress}
handleToggle3DMode={this.handleToggle3DMode.bind(this)}
handleOpenRollBackToPreExpansionStateDialog={this.handleOpenRollBackToPreExpansionStateDialog.bind(this)}
currentMode3D={mode3D}
handleToggleTreeMode={this.handleToggleTreeMode.bind(this)}
currentModeTree={modeTree}
Expand Down
Loading

0 comments on commit afe5ee2

Please sign in to comment.