-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Beats/update #21702
Beats/update #21702
Changes from all commits
ae0f496
dc0b707
4cf3308
88dcee6
cc7759f
7468f99
4193a51
29c9876
88a0e56
75cf004
3d8ca8a
66eb24c
02ee43c
c5cbf11
fbfbeba
1d766e3
d2ec2b7
29e8cf2
7338f13
c4d0776
f0d8c97
d2aa659
afdca74
94be8ff
d632dca
4025917
87a8991
1369e68
93dac60
1e8415d
d7d6839
e9dab95
ad79998
8d1030a
013b5cc
f07e713
c27491e
c5fc941
f7c01fe
f8faae9
e270774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,10 +79,16 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat | |
this.loadBeats(); | ||
}; | ||
|
||
// TODO: call delete endpoint | ||
private deleteSelected = async () => { | ||
// const selected = this.getSelectedBeats(); | ||
// await this.props.libs.beats.delete(selected); | ||
const selected = this.getSelectedBeats(); | ||
for (const beat of selected) { | ||
await this.props.libs.beats.update(beat.id, { active: false }); | ||
} | ||
// because the compile code above has a very minor race condition, we wait, | ||
// the max race condition time is really 10ms but doing 100 to be safe | ||
setTimeout(async () => { | ||
await this.loadBeats(); | ||
}, 100); | ||
}; | ||
|
||
private async loadBeats() { | ||
|
@@ -110,7 +116,7 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat | |
<EuiFlexItem key={tag.id}> | ||
<EuiBadge | ||
color={tag.color} | ||
iconType={hasMatches ? 'cross' : null} | ||
iconType={hasMatches ? 'cross' : undefined} | ||
onClick={ | ||
hasMatches | ||
? () => this.removeTagsFromBeats(selectedBeats, tag) | ||
|
@@ -143,7 +149,7 @@ export class BeatsPage extends React.PureComponent<BeatsPageProps, BeatsPageStat | |
this.loadBeats(); | ||
}; | ||
|
||
private getSelectedBeats = () => { | ||
private getSelectedBeats = (): CMPopulatedBeat[] => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
return this.state.tableRef.current.state.selection; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,15 @@ import { flatten, get as _get, omit } from 'lodash'; | |
import { INDEX_NAMES } from '../../../../common/constants'; | ||
import { CMBeat } from '../../../../common/domain_types'; | ||
import { DatabaseAdapter } from '../database/adapter_types'; | ||
import { BackendFrameworkAdapter } from '../framework/adapter_types'; | ||
|
||
import { FrameworkUser } from '../framework/adapter_types'; | ||
import { BeatsTagAssignment, CMBeatsAdapter } from './adapter_types'; | ||
|
||
export class ElasticsearchBeatsAdapter implements CMBeatsAdapter { | ||
private database: DatabaseAdapter; | ||
private framework: BackendFrameworkAdapter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the inclusion of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
constructor(database: DatabaseAdapter, framework: BackendFrameworkAdapter) { | ||
constructor(database: DatabaseAdapter) { | ||
this.database = database; | ||
this.framework = framework; | ||
} | ||
|
||
public async get(user: FrameworkUser, id: string) { | ||
|
@@ -37,13 +35,13 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter { | |
return _get<CMBeat>(response, '_source.beat'); | ||
} | ||
|
||
public async insert(beat: CMBeat) { | ||
public async insert(user: FrameworkUser, beat: CMBeat) { | ||
const body = { | ||
beat, | ||
type: 'beat', | ||
}; | ||
|
||
await this.database.create(this.framework.internalUser, { | ||
await this.database.index(user, { | ||
body, | ||
id: `beat:${beat.id}`, | ||
index: INDEX_NAMES.BEATS, | ||
|
@@ -52,7 +50,7 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter { | |
}); | ||
} | ||
|
||
public async update(beat: CMBeat) { | ||
public async update(user: FrameworkUser, beat: CMBeat) { | ||
const body = { | ||
beat, | ||
type: 'beat', | ||
|
@@ -65,7 +63,7 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter { | |
refresh: 'wait_for', | ||
type: '_doc', | ||
}; | ||
await this.database.index(this.framework.internalUser, params); | ||
await this.database.index(user, params); | ||
} | ||
|
||
public async getWithIds(user: FrameworkUser, beatIds: string[]) { | ||
|
@@ -115,11 +113,12 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter { | |
const params = { | ||
index: INDEX_NAMES.BEATS, | ||
q: 'type:beat', | ||
size: 10000, | ||
type: '_doc', | ||
}; | ||
const response = await this.database.search(user, params); | ||
|
||
const beats = _get<any>(response, 'hits.hits', []); | ||
|
||
return beats.map((beat: any) => omit(beat._source.beat, ['access_token'])); | ||
} | ||
|
||
|
@@ -129,16 +128,15 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter { | |
): Promise<BeatsTagAssignment[]> { | ||
const body = flatten( | ||
removals.map(({ beatId, tag }) => { | ||
const script = | ||
'' + | ||
'def beat = ctx._source.beat; ' + | ||
'if (beat.tags != null) { ' + | ||
' beat.tags.removeAll([params.tag]); ' + | ||
'}'; | ||
const script = ` | ||
def beat = ctx._source.beat; | ||
if (beat.tags != null) { | ||
beat.tags.removeAll([params.tag]); | ||
}`; | ||
|
||
return [ | ||
{ update: { _id: `beat:${beatId}` } }, | ||
{ script: { source: script, params: { tag } } }, | ||
{ script: { source: script.replace(' ', ''), params: { tag } } }, | ||
]; | ||
}) | ||
); | ||
|
@@ -162,19 +160,18 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter { | |
): Promise<BeatsTagAssignment[]> { | ||
const body = flatten( | ||
assignments.map(({ beatId, tag }) => { | ||
const script = | ||
'' + | ||
'def beat = ctx._source.beat; ' + | ||
'if (beat.tags == null) { ' + | ||
' beat.tags = []; ' + | ||
'} ' + | ||
'if (!beat.tags.contains(params.tag)) { ' + | ||
' beat.tags.add(params.tag); ' + | ||
'}'; | ||
const script = ` | ||
def beat = ctx._source.beat; | ||
if (beat.tags == null) { | ||
beat.tags = []; | ||
} | ||
if (!beat.tags.contains(params.tag)) { | ||
beat.tags.add(params.tag); | ||
}`; | ||
|
||
return [ | ||
{ update: { _id: `beat:${beatId}` } }, | ||
{ script: { source: script, params: { tag } } }, | ||
{ script: { source: script.replace(' ', ''), params: { tag } } }, | ||
]; | ||
}) | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍