From d280f6c936739ab719e4d482a2a1d66292e6131d Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Thu, 30 Nov 2023 17:58:23 -0800 Subject: [PATCH] supporting array of key/value under selection (#803) Signed-off-by: Amardeepsingh Siglani (cherry picked from commit 7154042e6d34d747a59ee861ae3b07f78be73fe7) --- .../RuleEditor/DetectionVisualEditor.tsx | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx b/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx index 9ea8b145a..bf63b5fa9 100644 --- a/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx +++ b/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx @@ -61,7 +61,7 @@ interface DetectionVisualEditorState { interface SelectionData { field: string; modifier?: string; - values: string[]; + values: (string | number)[]; selectedRadioId?: string; } @@ -179,16 +179,36 @@ export class DetectionVisualEditor extends React.Component< const selectionDataEntries: SelectionData[] = []; if (Array.isArray(selectionMapJSON)) { - selectionDataEntries.push({ - field: '', - modifier: 'all', - values: selectionMapJSON, - selectedRadioId: `${ - selectionMapJSON.length <= 1 - ? SelectionMapValueRadioId.VALUE - : SelectionMapValueRadioId.LIST - }-${selectionIdx}-0`, - }); + if (selectionMapJSON.length > 0 && typeof selectionMapJSON[0] === 'object') { + selectionMapJSON.forEach((map) => { + Object.keys(map).forEach((fieldKey, dataIdx) => { + const [field, modifier] = fieldKey.split('|'); + const val = map[fieldKey]; + const values: any[] = Array.isArray(val) ? val : [val]; + selectionDataEntries.push({ + field, + modifier, + values, + selectedRadioId: `${ + values.length <= 1 + ? SelectionMapValueRadioId.VALUE + : SelectionMapValueRadioId.LIST + }-${selectionIdx}-${dataIdx}`, + }); + }); + }); + } else { + selectionDataEntries.push({ + field: '', + modifier: 'all', + values: selectionMapJSON, + selectedRadioId: `${ + selectionMapJSON.length <= 1 + ? SelectionMapValueRadioId.VALUE + : SelectionMapValueRadioId.LIST + }-${selectionIdx}-0`, + }); + } } else if (typeof selectionMapJSON === 'object') { Object.keys(selectionMapJSON).forEach((fieldKey, dataIdx) => { const [field, modifier] = fieldKey.split('|'); @@ -203,6 +223,13 @@ export class DetectionVisualEditor extends React.Component< }-${selectionIdx}-${dataIdx}`, }); }); + } else if (typeof selectionMapJSON === 'string' || typeof selectionMapJSON === 'number') { + selectionDataEntries.push({ + field: '', + modifier: 'all', + values: [selectionMapJSON], + selectedRadioId: `${SelectionMapValueRadioId.VALUE}-${selectionIdx}-0`, + }); } if (selectionDataEntries.length) {