Skip to content
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

Fix 37422 #64215

Merged
merged 7 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/plugins/expressions/common/expression_types/specs/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@
* under the License.
*/

import { ExpressionTypeDefinition } from '../types';

const name = 'filter';
import { ExpressionTypeDefinition, ExpressionValueBoxed } from '../types';

/**
* Represents an object that is a Filter.
*/
export interface Filter {
type?: string;
value?: string;
column?: string;
and: Filter[];
to?: string;
from?: string;
query?: string | null;
}
export type ExpressionValueFilter = ExpressionValueBoxed<
'filter',
{
filterType?: string;
value?: string;
column?: string;
and: ExpressionValueFilter[];
to?: string;
from?: string;
query?: string | null;
}
>;

export const filter: ExpressionTypeDefinition<typeof name, Filter> = {
name,
export const filter: ExpressionTypeDefinition<'filter', ExpressionValueFilter> = {
name: 'filter',
from: {
null: () => {
return {
type: name,
type: 'filter',
filterType: 'filter',
// Any meta data you wish to pass along.
meta: {},
// And filters. If you need an "or", create a filter type for it.
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export {
ExpressionValueRender,
ExpressionValueSearchContext,
ExpressionValueUnboxed,
Filter,
ExpressionValueFilter,
Font,
FontLabel,
FontStyle,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export {
ExpressionValueRender,
ExpressionValueSearchContext,
ExpressionValueUnboxed,
Filter,
ExpressionValueFilter,
Font,
FontLabel,
FontStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('exactly', () => {

it("adds an exactly object to 'and'", () => {
const result = fn(emptyFilter, { column: 'name', value: 'product2' });
expect(result.and[0]).toHaveProperty('type', 'exactly');
expect(result.and[0]).toHaveProperty('filterType', 'exactly');
});

describe('args', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Filter, ExpressionFunctionDefinition } from '../../../types';
import { ExpressionValueFilter, ExpressionFunctionDefinition } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

interface Arguments {
Expand All @@ -13,7 +13,12 @@ interface Arguments {
filterGroup: string;
}

export function exactly(): ExpressionFunctionDefinition<'exactly', Filter, Arguments, Filter> {
export function exactly(): ExpressionFunctionDefinition<
'exactly',
ExpressionValueFilter,
Arguments,
ExpressionValueFilter
> {
const { help, args: argHelp } = getFunctionHelp().exactly;

return {
Expand Down Expand Up @@ -43,8 +48,9 @@ export function exactly(): ExpressionFunctionDefinition<'exactly', Filter, Argum
fn: (input, args) => {
const { value, column } = args;

const filter = {
type: 'exactly',
const filter: ExpressionValueFilter = {
type: 'filter',
filterType: 'exactly',
value,
column,
and: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
jest.mock('ui/new_platform');
import { savedLens } from './saved_lens';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { ExpressionValueFilter } from '../../../types';

const filterContext = {
const filterContext: ExpressionValueFilter = {
type: 'filter',
and: [
{ and: [], value: 'filter-value', column: 'filter-column', type: 'exactly' },
{
type: 'filter',
and: [],
value: 'filter-value',
column: 'filter-column',
filterType: 'exactly',
},
{
type: 'filter',
and: [],
column: 'time-column',
type: 'time',
filterType: 'time',
from: '2019-06-04T04:00:00.000Z',
to: '2019-06-05T04:00:00.000Z',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { TimeRange, Filter as DataFilter } from 'src/plugins/data/public';
import { EmbeddableInput } from 'src/plugins/embeddable/public';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter, TimeRange as TimeRangeArg } from '../../../types';
import { ExpressionValueFilter, TimeRange as TimeRangeArg } from '../../../types';
import {
EmbeddableTypes,
EmbeddableExpressionType,
Expand Down Expand Up @@ -37,7 +37,7 @@ type Return = EmbeddableExpression<SavedLensInput>;

export function savedLens(): ExpressionFunctionDefinition<
'savedLens',
Filter | null,
ExpressionValueFilter | null,
Arguments,
Return
> {
Expand All @@ -63,8 +63,8 @@ export function savedLens(): ExpressionFunctionDefinition<
},
},
type: EmbeddableExpressionType,
fn: (context, args) => {
const filters = context ? context.and : [];
fn: (input, args) => {
const filters = input ? input.and : [];

return {
type: EmbeddableExpressionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
jest.mock('ui/new_platform');
import { savedMap } from './saved_map';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { ExpressionValueFilter } from '../../../types';

const filterContext = {
const filterContext: ExpressionValueFilter = {
type: 'filter',
and: [
{ and: [], value: 'filter-value', column: 'filter-column', type: 'exactly' },
{
type: 'filter',
and: [],
value: 'filter-value',
column: 'filter-column',
filterType: 'exactly',
},
{
type: 'filter',
and: [],
column: 'time-column',
type: 'time',
filterType: 'time',
from: '2019-06-04T04:00:00.000Z',
to: '2019-06-05T04:00:00.000Z',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter, MapCenter, TimeRange as TimeRangeArg } from '../../../types';
import { ExpressionValueFilter, MapCenter, TimeRange as TimeRangeArg } from '../../../types';
import {
EmbeddableTypes,
EmbeddableExpressionType,
Expand All @@ -32,7 +32,7 @@ type Output = EmbeddableExpression<MapEmbeddableInput>;

export function savedMap(): ExpressionFunctionDefinition<
'savedMap',
Filter | null,
ExpressionValueFilter | null,
Arguments,
Output
> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
jest.mock('ui/new_platform');
import { savedSearch } from './saved_search';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
import { ExpressionValueFilter } from '../../../types';

const filterContext = {
const filterContext: ExpressionValueFilter = {
type: 'filter',
and: [
{ and: [], value: 'filter-value', column: 'filter-column', type: 'exactly' },
{
type: 'filter',
and: [],
value: 'filter-value',
column: 'filter-column',
filterType: 'exactly',
},
{
type: 'filter',
and: [],
column: 'time-column',
type: 'time',
filterType: 'time',
from: '2019-06-04T04:00:00.000Z',
to: '2019-06-05T04:00:00.000Z',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../../expression_types';

import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter } from '../../../types';
import { ExpressionValueFilter } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

interface Arguments {
Expand All @@ -24,7 +24,7 @@ type Output = EmbeddableExpression<Partial<SearchInput> & { id: SearchInput['id'

export function savedSearch(): ExpressionFunctionDefinition<
'savedSearch',
Filter | null,
ExpressionValueFilter | null,
Arguments,
Output
> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
jest.mock('ui/new_platform');
import { savedVisualization } from './saved_visualization';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { ExpressionValueFilter } from '../../../types';

const filterContext = {
const filterContext: ExpressionValueFilter = {
type: 'filter',
and: [
{ and: [], value: 'filter-value', column: 'filter-column', type: 'exactly' },
{
type: 'filter',
and: [],
value: 'filter-value',
column: 'filter-column',
filterType: 'exactly',
},
{
type: 'filter',
and: [],
column: 'time-column',
type: 'time',
filterType: 'time',
from: '2019-06-04T04:00:00.000Z',
to: '2019-06-05T04:00:00.000Z',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EmbeddableExpression,
} from '../../expression_types';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter, TimeRange as TimeRangeArg, SeriesStyle } from '../../../types';
import { ExpressionValueFilter, TimeRange as TimeRangeArg, SeriesStyle } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

interface Arguments {
Expand All @@ -31,7 +31,7 @@ const defaultTimeRange = {

export function savedVisualization(): ExpressionFunctionDefinition<
'savedVisualization',
Filter | null,
ExpressionValueFilter | null,
Arguments,
Output
> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('timefilter', () => {
from: fromDate,
to: toDate,
}).and[0]
).toHaveProperty('type', 'time');
).toHaveProperty('filterType', 'time');
});

describe('args', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import dateMath from '@elastic/datemath';
import { Filter, ExpressionFunctionDefinition } from '../../../types';
import { ExpressionValueFilter, ExpressionFunctionDefinition } from '../../../types';
import { getFunctionHelp, getFunctionErrors } from '../../../i18n';

interface Arguments {
Expand All @@ -17,9 +17,9 @@ interface Arguments {

export function timefilter(): ExpressionFunctionDefinition<
'timefilter',
Filter,
ExpressionValueFilter,
Arguments,
Filter
ExpressionValueFilter
> {
const { help, args: argHelp } = getFunctionHelp().timefilter;
const errors = getFunctionErrors().timefilter;
Expand Down Expand Up @@ -58,8 +58,9 @@ export function timefilter(): ExpressionFunctionDefinition<
}

const { from, to, column } = args;
const filter: Filter = {
type: 'time',
const filter: ExpressionValueFilter = {
type: 'filter',
filterType: 'time',
column,
and: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
*/

import { demodata } from './demodata';
import { ExpressionValueFilter } from '../../../types';

const nullFilter = {
const nullFilter: ExpressionValueFilter = {
type: 'filter',
meta: {},
size: null,
sort: [],
filterType: 'filter',
and: [],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions';
import { queryDatatable } from '../../../../common/lib/datatable/query';
import { DemoRows } from './demo_rows_types';
import { getDemoRows } from './get_demo_rows';
import { Filter, Datatable, DatatableColumn, DatatableRow } from '../../../../types';
import { ExpressionValueFilter, Datatable, DatatableColumn, DatatableRow } from '../../../../types';
import { getFunctionHelp } from '../../../../i18n';

interface Arguments {
type: string;
}

export function demodata(): ExpressionFunctionDefinition<'demodata', Filter, Arguments, Datatable> {
export function demodata(): ExpressionFunctionDefinition<
'demodata',
ExpressionValueFilter,
Arguments,
Datatable
> {
const { help, args: argHelp } = getFunctionHelp().demodata;

return {
Expand Down
Loading