Skip to content

Commit

Permalink
supporting array of key/value under selection (opensearch-project#803)
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed Feb 14, 2024
1 parent 8c0ba83 commit a660068
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface DetectionVisualEditorState {
interface SelectionData {
field: string;
modifier?: string;
values: string[];
values: (string | number)[];
selectedRadioId?: string;
}

Expand Down Expand Up @@ -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('|');
Expand All @@ -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) {
Expand Down

0 comments on commit a660068

Please sign in to comment.