Skip to content

Commit

Permalink
Update tag disable logic to check for uniqueness requirements.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Oct 17, 2018
1 parent 63f5d79 commit 2e4b9d2
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions x-pack/plugins/beats_management/public/pages/main/beats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -295,25 +298,27 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat
if (!this.state.tags) {
return [];
}
return this.selectedBeatsContainOutput()
? this.state.tags.map(this.mapTagToDisabled)
return this.selectedBeatConfigsRequireUniqueness()
? this.state.tags.map(this.disableTagForUniquenessEnforcement)
: this.state.tags;
};

private mapTagToDisabled = (tag: BeatTag) =>
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);
}

0 comments on commit 2e4b9d2

Please sign in to comment.