Move build_embeddable_filters into public (#59087)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Corey Robertson 2020-03-06 10:12:05 -05:00 committed by GitHub
parent 2e41a27c46
commit 9a3d0a5229
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 93 additions and 14 deletions

View file

@ -5,7 +5,7 @@
*/
jest.mock('ui/new_platform');
import { savedMap } from './saved_map';
import { getQueryFilters } from '../../../server/lib/build_embeddable_filters';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
const filterContext = {
and: [

View file

@ -7,7 +7,7 @@
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { TimeRange } from 'src/plugins/data/public';
import { EmbeddableInput } from 'src/legacy/core_plugins/embeddable_api/public/np_ready/public';
import { getQueryFilters } from '../../../server/lib/build_embeddable_filters';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter, MapCenter, TimeRange as TimeRangeArg } from '../../../types';
import {
EmbeddableTypes,

View file

@ -5,7 +5,7 @@
*/
jest.mock('ui/new_platform');
import { savedSearch } from './saved_search';
import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
const filterContext = {
and: [

View file

@ -12,7 +12,7 @@ import {
EmbeddableExpression,
} from '../../expression_types';
import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

View file

@ -5,7 +5,7 @@
*/
jest.mock('ui/new_platform');
import { savedVisualization } from './saved_visualization';
import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
const filterContext = {
and: [

View file

@ -11,7 +11,7 @@ import {
EmbeddableExpressionType,
EmbeddableExpression,
} from '../../expression_types';
import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

View file

@ -23,7 +23,7 @@ export const renderApp = (
canvasStore: Store
) => {
ReactDOM.render(
<KibanaContextProvider services={{ ...coreStart, ...plugins }}>
<KibanaContextProvider services={{ ...plugins, ...coreStart }}>
<I18nProvider>
<Provider store={canvasStore}>
<App />

View file

@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { getESFilter } from './get_es_filter';
const compact = arr => (Array.isArray(arr) ? arr.filter(val => Boolean(val)) : []);
export function buildBoolArray(canvasQueryFilterArray) {
return compact(
canvasQueryFilterArray.map(clause => {
try {
return getESFilter(clause);
} catch (e) {
return;
}
})
);
}

View file

@ -7,17 +7,11 @@
import { Filter } from '../../types';
// @ts-ignore Untyped Local
import { buildBoolArray } from './build_bool_array';
// TODO: We should be importing from `data/server` below instead of `data/common`, but
// need to keep `data/common` since the contents of this file are currently imported
// by the browser. This file should probably be refactored so that the pieces required
// on the client live in a `public` directory instead. See kibana/issues/52343
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import {
TimeRange,
esFilters,
Filter as DataFilter,
} from '../../../../../../src/plugins/data/server';
} from '../../../../../../src/plugins/data/public';
export interface EmbeddableFilterInput {
filters: DataFilter[];

View file

@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/*
TODO: This could be pluggable
*/
export function time(filter) {
if (!filter.column) {
throw new Error('column is required for Elasticsearch range filters');
}
return {
range: {
[filter.column]: { gte: filter.from, lte: filter.to },
},
};
}
export function luceneQueryString(filter) {
return {
query_string: {
query: filter.query || '*',
},
};
}
export function exactly(filter) {
return {
term: {
[filter.column]: {
value: filter.value,
},
},
};
}

View file

@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/*
boolArray is the array of bool filter clauses to push filters into. Usually this would be
the value of must, should or must_not.
filter is the abstracted canvas filter.
*/
/*eslint import/namespace: ['error', { allowComputed: true }]*/
import * as filters from './filters';
export function getESFilter(filter) {
if (!filters[filter.type]) {
throw new Error(`Unknown filter type: ${filter.type}`);
}
try {
return filters[filter.type](filter);
} catch (e) {
throw new Error(`Could not create elasticsearch filter from ${filter.type}`);
}
}