From 2e4b9d2844894c6dad18e2e540d5db4fa9d018ad Mon Sep 17 00:00:00 2001 From: Justin Kambic Date: Wed, 17 Oct 2018 14:24:00 -0400 Subject: [PATCH] Update tag disable logic to check for uniqueness requirements. --- .../public/pages/main/beats.tsx | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/beats_management/public/pages/main/beats.tsx b/x-pack/plugins/beats_management/public/pages/main/beats.tsx index a67d320a28e16..c032986814e66 100644 --- a/x-pack/plugins/beats_management/public/pages/main/beats.tsx +++ b/x-pack/plugins/beats_management/public/pages/main/beats.tsx @@ -14,12 +14,15 @@ import { EuiModalHeaderTitle, EuiOverlayMask, } from '@elastic/eui'; -import { flatten, sortBy } from 'lodash'; +import { flatten, intersection, sortBy } from 'lodash'; import moment from 'moment'; import React from 'react'; import { RouteComponentProps } from 'react-router'; -import { ConfigurationBlockTypes } from 'x-pack/plugins/beats_management/common/constants'; -import { BeatTag, CMPopulatedBeat } from '../../../common/domain_types'; +import { + ConfigurationBlockTypes, + UNIQUENESS_ENFORCING_TYPES, +} from 'x-pack/plugins/beats_management/common/constants'; +import { BeatTag, CMPopulatedBeat, ConfigurationBlock } from '../../../common/domain_types'; import { BeatsTagAssignment } from '../../../server/lib/adapters/beats/adapter_types'; import { AppURLState } from '../../app'; import { BeatsTableType, Table } from '../../components/table'; @@ -295,25 +298,27 @@ export class BeatsPage extends React.PureComponent - tag.configuration_blocks.some(config => config.type === ConfigurationBlockTypes.Output) && + private configBlocksRequireUniqueness = (configurationBlocks: ConfigurationBlock[]) => + intersection(UNIQUENESS_ENFORCING_TYPES, configurationBlocks.map(block => block.type)) + .length !== 0; + + private disableTagForUniquenessEnforcement = (tag: BeatTag) => + this.configBlocksRequireUniqueness(tag.configuration_blocks) && // if > 0 beats are associated with the tag, it will result in disassociation, so do not disable it !this.getSelectedBeats().some(beat => beat.full_tags.some(({ id }) => id === tag.id)) ? { ...tag, disabled: true } : tag; - private selectedBeatsContainOutput = () => + private selectedBeatConfigsRequireUniqueness = () => // union beat tags flatten(this.getSelectedBeats().map(({ full_tags }) => full_tags)) // map tag list to bool - .map(({ configuration_blocks }) => - configuration_blocks.some(config => config.type === ConfigurationBlockTypes.Output) - ) + .map(({ configuration_blocks }) => this.configBlocksRequireUniqueness(configuration_blocks)) // reduce to result .reduce((acc, cur) => acc || cur, false); }