diff --git a/x-pack/plugins/canvas/public/state/selectors/__tests__/workpad.js b/x-pack/plugins/canvas/public/state/selectors/__tests__/workpad.js index 5cfdf726dd258..bd56e1cd6e1d2 100644 --- a/x-pack/plugins/canvas/public/state/selectors/__tests__/workpad.js +++ b/x-pack/plugins/canvas/public/state/selectors/__tests__/workpad.js @@ -33,6 +33,39 @@ describe('workpad selectors', () => { }, ], }, + 'element-3': { + type: 'expression', + chain: [ + { + type: 'function', + function: 'demodata', + arguments: {}, + }, + { + type: 'function', + function: 'dropdownControl', + arguments: { + valueColumn: ['project'], + filterColumn: ['project'], + }, + }, + { + type: 'function', + function: 'render', + arguments: {}, + }, + ], + }, + 'element-4': { + type: 'expression', + chain: [ + { + type: 'function', + function: 'timefilterControl', + arguments: { compact: [true], column: ['@timestamp'] }, + }, + ], + }, }; state = { @@ -63,10 +96,23 @@ describe('workpad selectors', () => { { id: 'element-0', expression: 'markdown', + filter: '', }, { id: 'element-1', expression: 'demodata', + filter: '', + }, + { + id: 'element-3', + expression: + 'demodata | dropdownControl valueColumn=project filterColumn=project | render', + filter: 'exactly value="beats" column="project"', + }, + { + id: 'element-4', + expression: 'timefilterControl compact=true column=@timestamp', + filter: 'timefilter column=@timestamp from=now-24h to=now', }, ], }, @@ -135,6 +181,7 @@ describe('workpad selectors', () => { it('returns all elements on the page', () => { const { elements } = state.persistent.workpad.pages[0]; + const expected = elements.map(element => ({ ...element, ast: asts[element.id], @@ -198,6 +245,15 @@ describe('workpad selectors', () => { }); }); + describe('getGlobalFilterExpression', () => { + it('gets filters from all elements', () => { + const filters = selector.getGlobalFilterExpression(state); + expect(filters).to.equal( + 'exactly value="beats" column="project" | timefilter column=@timestamp from=now-24h to=now' + ); + }); + }); + describe('isWriteable', () => { it('returns boolean for if the workpad is writeable', () => { expect(selector.isWriteable(state)).to.equal(false); diff --git a/x-pack/plugins/canvas/public/state/selectors/workpad.js b/x-pack/plugins/canvas/public/state/selectors/workpad.js index 66e82f0cbab86..103bed6e52831 100644 --- a/x-pack/plugins/canvas/public/state/selectors/workpad.js +++ b/x-pack/plugins/canvas/public/state/selectors/workpad.js @@ -116,8 +116,14 @@ export function getElementStats(state) { export function getGlobalFilterExpression(state) { return getAllElements(state) - .map(el => el.filter) - .filter(str => str != null && str.length) + .reduce((acc, el) => { + // check that a filter is defined + if (el.filter != null && el.filter.length) { + return acc.concat(el.filter); + } + + return acc; + }, []) .join(' | '); }