diff --git a/x-pack/plugins/beats_management/public/components/table/table.tsx b/x-pack/plugins/beats_management/public/components/table/table.tsx index dc3e39ee0748c..7bfcd2c97de32 100644 --- a/x-pack/plugins/beats_management/public/components/table/table.tsx +++ b/x-pack/plugins/beats_management/public/components/table/table.tsx @@ -47,6 +47,7 @@ export class Table extends React.Component { }; public render() { + const { actionHandler, assignmentOptions, 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 e8524299a0afe..7854e3336f070 100644 --- a/x-pack/plugins/beats_management/public/pages/main/beats.tsx +++ b/x-pack/plugins/beats_management/public/pages/main/beats.tsx @@ -11,7 +11,7 @@ import { } from '@elastic/eui'; import React from 'react'; -import { BeatTag, CMPopulatedBeat } from '../../../common/domain_types'; +import { BeatTag, CMBeat, CMPopulatedBeat } from '../../../common/domain_types'; import { BeatsTagAssignment } from '../../../server/lib/adapters/beats/adapter_types'; import { BeatsTableType, Table } from '../../components/table'; import { FrontendLibs } from '../../lib/lib'; @@ -23,19 +23,19 @@ interface BeatsPageProps { } interface BeatsPageState { - beats: CMPopulatedBeat[]; + beats: CMBeat[]; + tableRef: any; tags: any[] | null; } export class BeatsPage extends React.PureComponent { public static ActionArea = BeatsActionArea; - private tableRef = React.createRef(); - constructor(props: BeatsPageProps) { super(props); this.state = { beats: [], + tableRef: React.createRef(), tags: null, }; @@ -51,32 +51,9 @@ export class BeatsPage extends React.PureComponent { - const selectedBeats = this.getSelectedBeats(); - const hasMatches = selectedBeats.some((beat: any) => - (beat.tags || []).some((t: string) => t === tag.id) - ); - - return ( - - this.removeTagsFromBeats(selectedBeats, tag) - : () => this.assignTagsToBeats(selectedBeats, tag) - } - onClickAriaLabel={tag.id} - > - {tag.id} - - - ); - }} assignmentTitle="Set tags" items={this.state.beats || []} - ref={this.tableRef} + ref={this.state.tableRef} showAssignmentOptions={true} type={BeatsTableType} /> @@ -111,9 +88,6 @@ export class BeatsPage extends React.PureComponent { await this.loadBeats(); - if (this.tableRef && this.tableRef.current) { - this.tableRef.current.resetSelection(); - } }, 100); }; @@ -124,16 +98,39 @@ export class BeatsPage extends React.PureComponent { // await this.props.libs.beats.searach(query); }; private loadTags = async () => { const tags = await this.props.libs.tags.getAll(); + const selectedBeats = this.getSelectedBeats(); + + const renderedTags = tags.map((tag: BeatTag) => { + const hasMatches = selectedBeats.some((beat: any) => + beat.full_tags.some((t: any) => t.id === tag.id) + ); + return ( + + this.removeTagsFromBeats(selectedBeats, tag) + : () => this.assignTagsToBeats(selectedBeats, tag) + } + onClickAriaLabel={tag.id} + > + {tag.id} + + + ); + }); this.setState({ - tags, + tags: renderedTags, }); }; @@ -149,16 +146,10 @@ export class BeatsPage extends React.PureComponent { await this.props.libs.beats.assignTagsToBeats(this.createBeatTagAssignments(beats, tag)); - await this.loadBeats(); - await this.loadTags(); + this.loadBeats(); }; private getSelectedBeats = (): CMPopulatedBeat[] => { - if (this.tableRef && this.tableRef.current) { - return this.tableRef.current.state.selection.map( - (beat: CMPopulatedBeat) => this.state.beats.find(b => b.id === beat.id) || beat - ); - } - return []; + return this.state.tableRef.current.state.selection; }; } diff --git a/x-pack/plugins/beats_management/public/pages/main/tags.tsx b/x-pack/plugins/beats_management/public/pages/main/tags.tsx index 73b39a215a46d..9c8c0ac2347b1 100644 --- a/x-pack/plugins/beats_management/public/pages/main/tags.tsx +++ b/x-pack/plugins/beats_management/public/pages/main/tags.tsx @@ -4,15 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - EuiButton, - EuiButtonEmpty, - EuiFlexGroup, - EuiFlexItem, - EuiIcon, - // @ts-ignore EuiToolTip has no typings in current version - EuiToolTip, -} from '@elastic/eui'; + +// @ts-ignore EuiToolTip has no typings in current version +import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiIcon, EuiToolTip } from '@elastic/eui'; import React from 'react'; import { BeatTag, CMBeat } from '../../../common/domain_types'; import { BeatsTagAssignment } from '../../../server/lib/adapters/beats/adapter_types'; @@ -25,27 +19,17 @@ interface TagsPageProps { interface TagsPageState { beats: any; + tableRef: any; tags: BeatTag[]; } export class TagsPage extends React.PureComponent { - public static ActionArea = ({ history }: any) => ( - { - history.push(`/tag/create`); - }} - > - Create Tag - - ); - public tableRef = React.createRef
(); constructor(props: TagsPageProps) { super(props); this.state = { beats: [], + tableRef: React.createRef(), tags: [], }; @@ -57,34 +41,20 @@ export class TagsPage extends React.PureComponent
); } - private handleTagsAction = async (action: string) => { + private handleTagsAction = (action: string, payload: any) => { switch (action) { case 'loadAssignmentOptions': this.loadBeats(); break; - case 'delete': - const tags = this.getSelectedTags().map(tag => tag.id); - const success = await this.props.libs.tags.delete(tags); - if (!success) { - alert( - 'Some of these tags might be assigned to beats. Please ensure tags being removed are not activly assigned' - ); - } else { - this.loadTags(); - if (this.tableRef && this.tableRef.current) { - this.tableRef.current.resetSelection(); - } - } - break; } this.loadTags(); @@ -166,10 +136,7 @@ export class TagsPage extends React.PureComponent await this.props.libs.beats.assignTagsToBeats(assignments); }; - private getSelectedTags = (): BeatTag[] => { - if (this.tableRef && this.tableRef.current) { - return this.tableRef.current.state.selection; - } - return []; + private getSelectedTags = () => { + return this.state.tableRef.current.state.selection; }; } diff --git a/x-pack/plugins/beats_management/server/lib/domains/beats.ts b/x-pack/plugins/beats_management/server/lib/domains/beats.ts index bd04b60aa6468..199077d8570c3 100644 --- a/x-pack/plugins/beats_management/server/lib/domains/beats.ts +++ b/x-pack/plugins/beats_management/server/lib/domains/beats.ts @@ -49,11 +49,6 @@ export class CMBeatsDomain { return beat && beat.active ? beat : null; } - public async getAllWithTags(user: FrameworkUser, tagIds: string[], justActive = true) { - const beats = await this.adapter.getAllWithTags(user, tagIds); - return justActive ? beats.filter((beat: CMBeat) => beat.active === true) : beats; - } - public async update(userOrToken: UserOrToken, beatId: string, beatData: Partial) { const beat = await this.adapter.get(this.framework.internalUser, beatId); diff --git a/x-pack/plugins/beats_management/server/utils/index_templates/beats_template.json b/x-pack/plugins/beats_management/server/utils/index_templates/beats_template.json new file mode 100644 index 0000000000000..0442c31fd7c2d --- /dev/null +++ b/x-pack/plugins/beats_management/server/utils/index_templates/beats_template.json @@ -0,0 +1,99 @@ +{ + "index_patterns": [".management-beats"], + "version": 65000, + "settings": { + "index": { + "number_of_shards": 1, + "auto_expand_replicas": "0-1", + "codec": "best_compression" + } + }, + "mappings": { + "_doc": { + "dynamic": "strict", + "properties": { + "type": { + "type": "keyword" + }, + "enrollment_token": { + "properties": { + "token": { + "type": "keyword" + }, + "expires_on": { + "type": "date" + } + } + }, + "tag": { + "properties": { + "id": { + "type": "keyword" + }, + "color": { + "type": "keyword" + }, + "configuration_blocks": { + "type": "nested", + "properties": { + "type": { + "type": "keyword" + }, + "block_yml": { + "type": "text" + } + } + } + } + }, + "beat": { + "properties": { + "id": { + "type": "keyword" + }, + "active": { + "type": "boolean" + }, + "enrollment_token": { + "type": "keyword" + }, + "access_token": { + "type": "keyword" + }, + "verified_on": { + "type": "date" + }, + "type": { + "type": "keyword" + }, + "version": { + "type": "keyword" + }, + "host_ip": { + "type": "ip" + }, + "host_name": { + "type": "keyword" + }, + "ephemeral_id": { + "type": "keyword" + }, + "local_configuration_yml": { + "type": "text" + }, + "tags": { + "type": "keyword" + }, + "orig_configuration_yml": { + "type": "text" + }, + "metadata": { + "dynamic": "true", + "type": "object" + } + } + } + } + } + } +} diff --git a/x-pack/yarn.lock b/x-pack/yarn.lock index c7a1d0ec50830..e155c728b20ca 100644 --- a/x-pack/yarn.lock +++ b/x-pack/yarn.lock @@ -123,10 +123,18 @@ version "4.3.10" resolved "https://registry.yarnpkg.com/@types/boom/-/boom-4.3.10.tgz#39dad8c0614c26b91ef016a57d7eee4ffe4f8a25" +"@types/chance@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@types/chance/-/chance-1.0.1.tgz#c10703020369602c40dd9428cc6e1437027116df" + "@types/delay@^2.0.1": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/delay/-/delay-2.0.1.tgz#61bcf318a74b61e79d1658fbf054f984c90ef901" +"@types/elasticsearch@^5.0.24": + version "5.0.25" + resolved "https://registry.yarnpkg.com/@types/elasticsearch/-/elasticsearch-5.0.25.tgz#717255a52acd9fa3ba165072d43a242283b1c898" + "@types/events@*": version "1.2.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86" @@ -163,6 +171,12 @@ version "10.6.2" resolved "https://registry.yarnpkg.com/@types/joi/-/joi-10.6.2.tgz#0e7d632fe918c337784e87b16c7cc0098876179a" +"@types/jsonwebtoken@^7.2.7": + version "7.2.8" + resolved "https://registry.yarnpkg.com/@types/jsonwebtoken/-/jsonwebtoken-7.2.8.tgz#8d199dab4ddb5bba3234f8311b804d2027af2b3a" + dependencies: + "@types/node" "*" + "@types/lodash@^3.10.0": version "3.10.2" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-3.10.2.tgz#c1fbda1562ef5603c8192fe1fe65b017849d5873" @@ -203,6 +217,10 @@ version "0.10.2" resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.10.2.tgz#bd1740c4ad51966609b058803ee6874577848b37" +"@types/sinon@^5.0.1": + version "5.0.1" + resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-5.0.1.tgz#a15b36ec42f1f53166617491feabd1734cb03e21" + "@types/url-join@^0.8.2": version "0.8.2" resolved "https://registry.yarnpkg.com/@types/url-join/-/url-join-0.8.2.tgz#1181ecbe1d97b7034e0ea1e35e62e86cc26b422d" @@ -1211,6 +1229,10 @@ buffer-crc32@~0.2.3: version "0.2.13" resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" +buffer-equal-constant-time@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" + buffer-equal@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/buffer-equal/-/buffer-equal-0.0.1.tgz#91bc74b11ea405bc916bc6aa908faafa5b4aac4b" @@ -2151,6 +2173,12 @@ ecc-jsbn@~0.1.1: dependencies: jsbn "~0.1.0" +ecdsa-sig-formatter@1.0.10: + version "1.0.10" + resolved "https://registry.yarnpkg.com/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.10.tgz#1c595000f04a8897dfb85000892a0f4c33af86c3" + dependencies: + safe-buffer "^5.0.1" + elasticsearch@^14.1.0: version "14.2.2" resolved "https://registry.yarnpkg.com/elasticsearch/-/elasticsearch-14.2.2.tgz#6bbb63b19b17fa97211b22eeacb0f91197f4d6b6" @@ -4479,6 +4507,20 @@ jsonpointer@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9" +jsonwebtoken@^8.3.0: + version "8.3.0" + resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.3.0.tgz#056c90eee9a65ed6e6c72ddb0a1d325109aaf643" + dependencies: + jws "^3.1.5" + lodash.includes "^4.3.0" + lodash.isboolean "^3.0.3" + lodash.isinteger "^4.0.4" + lodash.isnumber "^3.0.3" + lodash.isplainobject "^4.0.6" + lodash.isstring "^4.0.1" + lodash.once "^4.0.0" + ms "^2.1.1" + jsprim@^1.2.2: version "1.4.1" resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" @@ -4496,6 +4538,21 @@ just-extend@^1.1.27: version "1.1.27" resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-1.1.27.tgz#ec6e79410ff914e472652abfa0e603c03d60e905" +jwa@^1.1.5: + version "1.1.6" + resolved "https://registry.yarnpkg.com/jwa/-/jwa-1.1.6.tgz#87240e76c9808dbde18783cf2264ef4929ee50e6" + dependencies: + buffer-equal-constant-time "1.0.1" + ecdsa-sig-formatter "1.0.10" + safe-buffer "^5.0.1" + +jws@^3.1.5: + version "3.1.5" + resolved "https://registry.yarnpkg.com/jws/-/jws-3.1.5.tgz#80d12d05b293d1e841e7cb8b4e69e561adcf834f" + dependencies: + jwa "^1.1.5" + safe-buffer "^5.0.1" + keymirror@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/keymirror/-/keymirror-0.1.1.tgz#918889ea13f8d0a42e7c557250eee713adc95c35" @@ -4747,6 +4804,10 @@ lodash.get@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" +lodash.includes@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -4755,6 +4816,10 @@ lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" +lodash.isboolean@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" + lodash.isempty@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e" @@ -4763,10 +4828,26 @@ lodash.isequal@^4.1.1, lodash.isequal@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" +lodash.isinteger@^4.0.4: + version "4.0.4" + resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" + +lodash.isnumber@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" + lodash.isobject@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-3.0.2.tgz#3c8fb8d5b5bf4bf90ae06e14f2a530a4ed935e1d" +lodash.isplainobject@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" + +lodash.isstring@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" + lodash.istypedarray@^3.0.0: version "3.0.6" resolved "https://registry.yarnpkg.com/lodash.istypedarray/-/lodash.istypedarray-3.0.6.tgz#c9a477498607501d8e8494d283b87c39281cef62" @@ -4787,6 +4868,10 @@ lodash.mergewith@^4.6.0: version "4.6.1" resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927" +lodash.once@^4.0.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" + lodash.orderby@4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.orderby/-/lodash.orderby-4.6.0.tgz#e697f04ce5d78522f54d9338b32b81a3393e4eb3" @@ -5204,7 +5289,7 @@ ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" -ms@^2.0.0: +ms@^2.0.0, ms@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"