-
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
fixes filtering on other bucket outside of vislib #19860
Changes from 2 commits
06e4b68
e0ae00e
32b9181
9986996
fd967c6
fcc9df6
eac9af5
adf08b9
6b6db61
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 |
---|---|---|
|
@@ -46,8 +46,9 @@ export class TagCloudVisualization { | |
if (!this._bucketAgg) { | ||
return; | ||
} | ||
const filter = this._bucketAgg.createFilter(event); | ||
this._vis.API.queryFilter.addFilters(filter); | ||
this._vis.API.events.filter( | ||
this._data, 0, this._data.rows.findIndex(row => row[0] === event) | ||
); | ||
}); | ||
this._renderComplete$ = Observable.fromEvent(this._tagCloud, 'renderComplete'); | ||
|
||
|
@@ -112,6 +113,7 @@ export class TagCloudVisualization { | |
} | ||
|
||
const data = response.tables[0]; | ||
this._data = data; | ||
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. Should be removed now (sorry was missing in my diff). |
||
const segmentAggs = this._vis.aggs.bySchemaName.segment; | ||
if (segmentAggs && segmentAggs.length > 0) { | ||
this._bucketAgg = segmentAggs[0]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ | |
|
||
import _ from 'lodash'; | ||
import { AggConfig } from '../../vis/agg_config'; | ||
import { buildPhrasesFilter } from '../../filter_manager/lib/phrases'; | ||
import { buildExistsFilter } from '../../filter_manager/lib/exists'; | ||
import { buildPhrasesFilter } from '../../filter_manager/lib/phrases'; | ||
import { buildQueryFromFilters } from '../../courier/data_source/build_query/from_filters'; | ||
|
||
/** | ||
|
@@ -102,6 +102,7 @@ const getOtherAggTerms = (requestAgg, key, otherAgg) => { | |
); | ||
}; | ||
|
||
|
||
const buildOtherBucketAgg = (aggConfigs, aggWithOtherBucket, response) => { | ||
const bucketAggs = aggConfigs.filter(agg => agg.type.type === 'buckets'); | ||
const index = bucketAggs.findIndex(agg => agg.id === aggWithOtherBucket.id); | ||
|
@@ -175,12 +176,11 @@ const mergeOtherBucketAggResponse = (aggsConfig, response, otherResponse, otherA | |
const phraseFilter = buildPhrasesFilter(otherAgg.params.field, requestFilterTerms, otherAgg.params.field.indexPattern); | ||
phraseFilter.meta.negate = true; | ||
bucket.filters = [ phraseFilter ]; | ||
bucket.key = otherAgg.params.otherBucketLabel; | ||
bucket.key = '__other__'; | ||
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. What about moving 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. Tim is gonna try with using symbols in a separate PR |
||
|
||
if (aggResultBuckets.some(bucket => bucket.key === '__missing__')) { | ||
bucket.filters.push(buildExistsFilter(otherAgg.params.field, otherAgg.params.field.indexPattern)); | ||
} | ||
|
||
aggResultBuckets.push(bucket); | ||
}); | ||
return updatedResponse; | ||
|
@@ -190,12 +190,13 @@ const updateMissingBucket = (response, aggConfigs, agg) => { | |
const updatedResponse = _.cloneDeep(response); | ||
const aggResultBuckets = getAggConfigResultMissingBuckets(updatedResponse.aggregations, agg.id); | ||
aggResultBuckets.forEach(bucket => { | ||
bucket.key = agg.params.missingBucketLabel; | ||
const existsFilter = buildExistsFilter(agg.params.field, agg.params.field.indexPattern); | ||
existsFilter.meta.negate = true; | ||
bucket.filters = [ existsFilter ]; | ||
bucket.key = '__missing__'; | ||
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. Same as comment above |
||
}); | ||
return updatedResponse; | ||
}; | ||
|
||
export { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket }; | ||
export { | ||
buildOtherBucketAgg, | ||
mergeOtherBucketAggResponse, | ||
updateMissingBucket, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,17 @@ export const termsBucketAgg = new BucketAggType({ | |
const params = agg.params; | ||
return agg.getFieldDisplayName() + ': ' + params.order.display; | ||
}, | ||
getFormat: function (bucket) { | ||
return { | ||
getConverterFor: (type) => { | ||
return (val) => { | ||
if (val === '__other__') return bucket.params.otherBucketLabel; | ||
if (val === '__missing__') return bucket.params.missingBucketLabel; | ||
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. Needs to follow styleguides on braces for conditionals |
||
return bucket.params.field.format.getConverterFor(type)(val); | ||
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. Slight performance improvement, move getFormat: function (bucket) {
return {
getConverterFor: (type) => {
const converter = bucket.params.field.format.getConverterFor(type);
return (val) => {
if (val === '__other__') return bucket.params.otherBucketLabel;
if (val === '__missing__') return bucket.params.missingBucketLabel;
return converter(val);
};
}
};
}, |
||
}; | ||
} | ||
}; | ||
}, | ||
createFilter: createFilterTerms, | ||
postFlightRequest: async (resp, aggConfigs, aggConfig, nestedSearchSource) => { | ||
if (aggConfig.params.otherBucket) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,15 @@ import { queryManagerFactory } from '../query_manager'; | |
import { SearchSourceProvider } from '../courier/data_source/search_source'; | ||
import { SavedObjectsClientProvider } from '../saved_objects'; | ||
|
||
const getTerms = (table, columnIndex, rowIndex) => { | ||
return [...new Set( | ||
table.rows.filter(row => { | ||
if (row[columnIndex] === '__other__') return false; | ||
return row.every((cell, i) => cell === table.rows[rowIndex][i] || i >= columnIndex); | ||
}).map(row => row[columnIndex]) | ||
)]; | ||
}; | ||
|
||
export function VisProvider(Private, Promise, indexPatterns, timefilter, getAppState) { | ||
const visTypes = Private(VisTypesRegistryProvider); | ||
const brushEvent = Private(UtilsBrushEventProvider); | ||
|
@@ -75,9 +84,21 @@ export function VisProvider(Private, Promise, indexPatterns, timefilter, getAppS | |
queryFilter: queryFilter, | ||
queryManager: queryManagerFactory(getAppState), | ||
events: { | ||
filter: (event) => { | ||
filter_legacy: (event) => { | ||
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. Could we please add a comment to this, why it's legacy, and that it should not be used anymore, because we will remove it at some point. |
||
const appState = getAppState(); | ||
filterBarClickHandler(appState)(event); | ||
}, | ||
filter: (data, columnIndex, rowIndex) => { | ||
const agg = data.columns[columnIndex].aggConfig; | ||
let filter = []; | ||
const value = data.rows[rowIndex][columnIndex]; | ||
if (agg.type.name === 'terms' && agg.params.otherBucket) { | ||
const terms = getTerms(data, columnIndex, rowIndex); | ||
filter = agg.createFilter(value, { terms }); | ||
} else { | ||
filter = agg.createFilter(value); | ||
} | ||
queryFilter.addFilters(filter); | ||
}, brush: (event) => { | ||
const appState = getAppState(); | ||
brushEvent(appState)(event); | ||
|
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.
I would suggest instead of trying to find the row, we change the tagcloud visualization to attach that data and pass it when clicking a 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.
Maybe we should even attach the data to each tag's
meta
and use that one instead of writing it tothis._data
, which I think could potentially in very bad timing not be thedata
that was used to render the tag anymore, since tag cloud does render async.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.
i.e.