-
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
other bucket filter for table and vislib legend #24473
Changes from all commits
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 |
---|---|---|
|
@@ -76,8 +76,8 @@ const LegacyResponseHandlerProvider = function () { | |
const aggConfigResult = new AggConfigResult(column.aggConfig, previousSplitAgg, value, value); | ||
aggConfigResult.rawData = { | ||
table: table, | ||
columnIndex: table.columns.findIndex(c => c.id === column.id), | ||
rowIndex: rowIndex, | ||
column: table.columns.findIndex(c => c.id === column.id), | ||
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. nit: |
||
row: rowIndex, | ||
}; | ||
if (column.aggConfig.type.type === 'buckets') { | ||
previousSplitAgg = aggConfigResult; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import { FilterBarPushFiltersProvider } from '../filter_bar/push_filters'; | ||
import { FilterBarQueryFilterProvider } from '../filter_bar/query_filter'; | ||
|
||
const getTerms = (table, columnIndex, rowIndex) => { | ||
if (rowIndex === -1) { | ||
return []; | ||
} | ||
|
||
// get only rows where cell value matches current row for all the fields before columnIndex | ||
const rows = table.rows.filter(row => { | ||
return table.columns.every((column, i) => { | ||
return row[column.id] === table.rows[rowIndex][column.id] || i >= columnIndex; | ||
}); | ||
}); | ||
const terms = rows.map(row => row[table.columns[columnIndex].id]); | ||
|
||
return [...new Set(terms.filter(term => { | ||
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. is the spread operator necessary here or could you just 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. I think this is used to keep the same return signature: the spread operator transform the set into a standard array |
||
const notOther = term !== '__other__'; | ||
const notMissing = term !== '__missing__'; | ||
return notOther && notMissing; | ||
}))]; | ||
}; | ||
|
||
export function VisFiltersProvider(Private, getAppState) { | ||
const filterBarPushFilters = Private(FilterBarPushFiltersProvider); | ||
const queryFilter = Private(FilterBarQueryFilterProvider); | ||
|
||
const createFilter = (data, columnIndex, rowIndex, cellValue) => { | ||
const { aggConfig, id: columnId } = data.columns[columnIndex]; | ||
let filter = []; | ||
const value = rowIndex > -1 ? data.rows[rowIndex][columnId] : cellValue; | ||
if (value === null || value === undefined) { | ||
return; | ||
} | ||
if (aggConfig.type.name === 'terms' && aggConfig.params.otherBucket) { | ||
const terms = getTerms(data, columnIndex, rowIndex); | ||
filter = aggConfig.createFilter(value, { terms }); | ||
} else { | ||
filter = aggConfig.createFilter(value); | ||
} | ||
return filter; | ||
}; | ||
|
||
const filter = (event, { simulate } = {}) => { | ||
let data = event.datum.aggConfigResult; | ||
const filters = []; | ||
while (data) { | ||
if (data.type === 'bucket') { | ||
const { key, rawData } = data; | ||
const { table, column, row } = rawData; | ||
const filter = createFilter(table, column, row, key); | ||
if (event.negate) { | ||
if (Array.isArray(filter)) { | ||
filter.forEach(f => f.meta.negate = !f.meta.negate); | ||
} else { | ||
filter.meta.negate = !filter.meta.negate; | ||
} | ||
} | ||
filters.push(filter); | ||
} | ||
data = data.$parent; | ||
} | ||
if (!simulate) { | ||
const appState = getAppState(); | ||
filterBarPushFilters(appState)(_.flatten(filters)); | ||
} | ||
return filters; | ||
}; | ||
|
||
const addFilter = (data, columnIndex, rowIndex, cellValue) => { | ||
const filter = createFilter(data, columnIndex, rowIndex, cellValue); | ||
queryFilter.addFilters(filter); | ||
}; | ||
|
||
return { | ||
createFilter, | ||
addFilter, | ||
filter | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,22 +20,18 @@ | |
import _ from 'lodash'; | ||
import html from './vislib_vis_legend.html'; | ||
import { VislibLibDataProvider } from '../../vislib/lib/data'; | ||
import { FilterBarClickHandlerProvider } from '../../filter_bar/filter_bar_click_handler'; | ||
import { uiModules } from '../../modules'; | ||
import { htmlIdGenerator, keyCodes } from '@elastic/eui'; | ||
|
||
|
||
uiModules.get('kibana') | ||
.directive('vislibLegend', function (Private, getAppState, $timeout, i18n) { | ||
.directive('vislibLegend', function (Private, $timeout, i18n) { | ||
const Data = Private(VislibLibDataProvider); | ||
const filterBarClickHandler = Private(FilterBarClickHandlerProvider); | ||
|
||
return { | ||
restrict: 'E', | ||
template: html, | ||
link: function ($scope) { | ||
const $state = getAppState(); | ||
const clickHandler = filterBarClickHandler($state); | ||
$scope.legendId = htmlIdGenerator()('legend'); | ||
$scope.open = $scope.uiState.get('vis.legendOpen', true); | ||
|
||
|
@@ -104,11 +100,11 @@ uiModules.get('kibana') | |
}; | ||
|
||
$scope.filter = function (legendData, negate) { | ||
clickHandler({ point: legendData, negate: negate }); | ||
$scope.vis.API.events.filter({ datum: legendData.values, negate: negate }); | ||
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. nit: |
||
}; | ||
|
||
$scope.canFilter = function (legendData) { | ||
const filters = clickHandler({ point: legendData }, true) || []; | ||
const filters = $scope.vis.API.events.filter({ datum: legendData.values }, { simulate: true }); | ||
return filters.length; | ||
}; | ||
|
||
|
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.
nit:
{ aggConfigResult: aggConfigResult }
could be simplified to{ aggConfigResult }