From 890c486136a37ebbbdc49239f83f2cb51b48ce06 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Tue, 26 Mar 2024 17:03:45 -0700 Subject: [PATCH] Allow multiple aliases to same field when creating/editing mappings for detector (#973) * allow same log field to be mapped for multiple aliases Signed-off-by: Amardeepsingh Siglani * updated snapshots Signed-off-by: Amardeepsingh Siglani --------- Signed-off-by: Amardeepsingh Siglani --- .../FieldMappingsTable.tsx | 11 +++----- .../FieldNameSelector.tsx | 9 ++----- .../containers/ConfigureFieldMapping.tsx | 25 ----------------- .../FieldMappings/EditFieldMapping.tsx | 27 +------------------ .../EditFieldMappings.test.tsx.snap | 1 - 5 files changed, 6 insertions(+), 67 deletions(-) diff --git a/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldMappingsTable.tsx b/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldMappingsTable.tsx index 0f6254300..6d2877bbc 100644 --- a/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldMappingsTable.tsx +++ b/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldMappingsTable.tsx @@ -32,7 +32,6 @@ export interface MappingProps { [MappingViewType.Edit]: { type: MappingViewType.Edit; existingMappings: ruleFieldToIndexFieldMap; - invalidMappingFieldNames: string[]; onMappingCreation: (fieldName: string, aliasName: string) => void; }; } @@ -98,7 +97,7 @@ export default class FieldMappingsTable extends Compo width: '45%', render: (logFieldName: string, entry: FieldMappingsTableItem) => { if (this.props.mappingProps.type === MappingViewType.Edit) { - const { onMappingCreation, invalidMappingFieldNames, existingMappings } = this.props + const { onMappingCreation, existingMappings } = this.props .mappingProps as MappingProps[MappingViewType.Edit]; const onMappingSelected = (selectedField: string) => { onMappingCreation(entry.ruleFieldName, selectedField); @@ -107,7 +106,6 @@ export default class FieldMappingsTable extends Compo ); @@ -131,14 +129,11 @@ export default class FieldMappingsTable extends Compo align: 'center', width: '15%', render: (_status: 'mapped' | 'unmapped', entry: FieldMappingsTableItem) => { - const { existingMappings: createdMappings, invalidMappingFieldNames } = this.props + const { existingMappings: createdMappings } = this.props .mappingProps as MappingProps[MappingViewType.Edit]; let iconProps = STATUS_ICON_PROPS['unmapped']; let iconTooltip = 'This field needs to be mapped with a field from your log source.'; - if ( - createdMappings[entry.ruleFieldName] && - !invalidMappingFieldNames.includes(entry.ruleFieldName) - ) { + if (createdMappings[entry.ruleFieldName]) { iconProps = STATUS_ICON_PROPS['mapped']; iconTooltip = 'This field has been mapped.'; } diff --git a/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldNameSelector.tsx b/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldNameSelector.tsx index c2c7fb722..fd76a30c9 100644 --- a/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldNameSelector.tsx +++ b/public/pages/CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldNameSelector.tsx @@ -8,7 +8,6 @@ import { EuiComboBox, EuiComboBoxOptionOption, EuiFormRow } from '@elastic/eui'; interface SIEMFieldNameProps { fieldNameOptions: string[]; - isInvalid: boolean; selectedField: string; onChange: (option: string) => void; } @@ -51,18 +50,14 @@ export default class FieldNameSelector extends Component ({ label: option, })); return ( - + @@ -220,7 +216,6 @@ export default class ConfigureFieldMapping extends Component< mappingProps={{ type: MappingViewType.Edit, existingMappings, - invalidMappingFieldNames, onMappingCreation: this.onMappingCreation, }} /> @@ -321,24 +316,6 @@ export default class ConfigureFieldMapping extends Component< } }; - /** - * Returns the fieldName(s) that have duplicate alias assigned to them - */ - getInvalidMappingFieldNames(mappings: ruleFieldToIndexFieldMap): string[] { - const seenAliases = new Set(); - const invalidFields: string[] = []; - - Object.entries(mappings).forEach((entry) => { - if (seenAliases.has(entry[1])) { - invalidFields.push(entry[0]); - } - - seenAliases.add(entry[1]); - }); - - return invalidFields; - } - onMappingCreation = (ruleFieldName: string, indexFieldName: string): void => { const newMappings: ruleFieldToIndexFieldMap = { ...this.state.createdMappings, @@ -349,10 +326,8 @@ export default class ConfigureFieldMapping extends Component< delete newMappings[ruleFieldName]; } - const invalidMappingFieldNames = this.getInvalidMappingFieldNames(newMappings); this.setState({ createdMappings: newMappings, - invalidMappingFieldNames: invalidMappingFieldNames, }); this.updateMappingSharedState(newMappings); this.context.metrics.detectorMetricsManager.sendMetrics( diff --git a/public/pages/Detectors/containers/FieldMappings/EditFieldMapping.tsx b/public/pages/Detectors/containers/FieldMappings/EditFieldMapping.tsx index a7ed79344..b40d257b2 100644 --- a/public/pages/Detectors/containers/FieldMappings/EditFieldMapping.tsx +++ b/public/pages/Detectors/containers/FieldMappings/EditFieldMapping.tsx @@ -40,7 +40,6 @@ interface EditFieldMappingsProps extends RouteComponentProps { interface EditFieldMappingsState { loading: boolean; createdMappings: ruleFieldToIndexFieldMap; - invalidMappingFieldNames: string[]; mappedRuleFields: string[]; unmappedRuleFields: string[]; logFieldOptions: string[]; @@ -61,7 +60,6 @@ export default class EditFieldMappings extends Component< ruleQueryFields: props.ruleQueryFields ? props.ruleQueryFields : new Set(), loading: props.loading || false, createdMappings, - invalidMappingFieldNames: [], mappedRuleFields: [], unmappedRuleFields: [], logFieldOptions: [], @@ -126,7 +124,7 @@ export default class EditFieldMappings extends Component< }); items.forEach((ruleField) => { - existingMappings[ruleField.ruleFieldName] = ruleField.logFieldName; + existingMappings[ruleField.ruleFieldName] = ruleField.logFieldName || ''; }); for (let key in existingMappings) { @@ -167,24 +165,6 @@ export default class EditFieldMappings extends Component< this.setState({ loading: false }); }; - /** - * Returns the fieldName(s) that have duplicate alias assigned to them - */ - getInvalidMappingFieldNames(mappings: ruleFieldToIndexFieldMap): string[] { - const seenAliases = new Set(); - const invalidFields: string[] = []; - - Object.entries(mappings).forEach((entry) => { - if (seenAliases.has(entry[1])) { - invalidFields.push(entry[0]); - } - - seenAliases.add(entry[1]); - }); - - return invalidFields; - } - onMappingCreation = (ruleFieldName: string, indexFieldName: string): void => { const newMappings: ruleFieldToIndexFieldMap = { ...this.state.createdMappings, @@ -193,10 +173,8 @@ export default class EditFieldMappings extends Component< if (!indexFieldName) { delete newMappings[ruleFieldName]; } - const invalidMappingFieldNames = this.getInvalidMappingFieldNames(newMappings); this.setState({ createdMappings: newMappings, - invalidMappingFieldNames: invalidMappingFieldNames, }); this.updateMappingSharedState(newMappings); }; @@ -216,7 +194,6 @@ export default class EditFieldMappings extends Component< const { loading, createdMappings, - invalidMappingFieldNames, mappedRuleFields, unmappedRuleFields, logFieldOptions, @@ -253,7 +230,6 @@ export default class EditFieldMappings extends Component< mappingProps={{ type: MappingViewType.Edit, existingMappings, - invalidMappingFieldNames, onMappingCreation: this.onMappingCreation, }} /> @@ -286,7 +262,6 @@ export default class EditFieldMappings extends Component< mappingProps={{ type: MappingViewType.Edit, existingMappings, - invalidMappingFieldNames, onMappingCreation: this.onMappingCreation, }} /> diff --git a/public/pages/Detectors/containers/FieldMappings/__snapshots__/EditFieldMappings.test.tsx.snap b/public/pages/Detectors/containers/FieldMappings/__snapshots__/EditFieldMappings.test.tsx.snap index df17d96d4..2bce03557 100644 --- a/public/pages/Detectors/containers/FieldMappings/__snapshots__/EditFieldMappings.test.tsx.snap +++ b/public/pages/Detectors/containers/FieldMappings/__snapshots__/EditFieldMappings.test.tsx.snap @@ -499,7 +499,6 @@ exports[` spec renders the component 1`] = ` mappingProps={ Object { "existingMappings": Object {}, - "invalidMappingFieldNames": Array [], "onMappingCreation": [Function], "type": 1, }