Skip to content

Commit

Permalink
Handle element changing into a filter (elastic#97890)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
Corey Robertson and kibanamachine committed Jun 22, 2021
1 parent cf97abe commit dd86829
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ export const dropdownFilter: RendererFactory<Config> = () => ({
reuseDomNode: true,
height: 50,
render(domNode, config, handlers) {
const filterExpression = handlers.getFilter();
let filterExpression = handlers.getFilter();

if (filterExpression !== '') {
if (filterExpression === undefined || filterExpression.indexOf('exactly')) {
filterExpression = '';
handlers.setFilter(filterExpression);
} else if (filterExpression !== '') {
// NOTE: setFilter() will cause a data refresh, avoid calling unless required
// compare expression and filter, update filter if needed
const { changed, newAst } = syncFilterExpression(config, filterExpression, ['filterGroup']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { RendererFactory } from '../../../../types';

const { timeFilter: strings } = RendererStrings;

const defaultTimeFilterExpression = 'timefilter column=@timestamp from=now-24h to=now';

export const timeFilterFactory: StartInitializer<RendererFactory<Arguments>> = (core, plugins) => {
const { uiSettings } = core;

Expand All @@ -38,9 +40,12 @@ export const timeFilterFactory: StartInitializer<RendererFactory<Arguments>> = (
help: strings.getHelpDescription(),
reuseDomNode: true, // must be true, otherwise popovers don't work
render: async (domNode: HTMLElement, config: Arguments, handlers: RendererHandlers) => {
const filterExpression = handlers.getFilter();
let filterExpression = handlers.getFilter();

if (filterExpression !== '') {
if (filterExpression === undefined || filterExpression.indexOf('timefilter') !== 0) {
filterExpression = defaultTimeFilterExpression;
handlers.setFilter(filterExpression);
} else if (filterExpression !== '') {
// NOTE: setFilter() will cause a data refresh, avoid calling unless required
// compare expression and filter, update filter if needed
const { changed, newAst } = syncFilterExpression(config, filterExpression, [
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/public/lib/create_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const createDispatchedHandlerFactory = (
},

getFilter() {
return element.filter;
return element.filter || '';
},

onComplete(fn: () => void) {
Expand Down

0 comments on commit dd86829

Please sign in to comment.