Move build_embeddable_filters into public (#59087)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
2e41a27c46
commit
9a3d0a5229
|
@ -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: [
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ export const renderApp = (
|
|||
canvasStore: Store
|
||||
) => {
|
||||
ReactDOM.render(
|
||||
<KibanaContextProvider services={{ ...coreStart, ...plugins }}>
|
||||
<KibanaContextProvider services={{ ...plugins, ...coreStart }}>
|
||||
<I18nProvider>
|
||||
<Provider store={canvasStore}>
|
||||
<App />
|
||||
|
|
21
x-pack/legacy/plugins/canvas/public/lib/build_bool_array.js
Normal file
21
x-pack/legacy/plugins/canvas/public/lib/build_bool_array.js
Normal 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;
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
|
@ -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[];
|
38
x-pack/legacy/plugins/canvas/public/lib/filters.js
Normal file
38
x-pack/legacy/plugins/canvas/public/lib/filters.js
Normal 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,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
26
x-pack/legacy/plugins/canvas/public/lib/get_es_filter.js
Normal file
26
x-pack/legacy/plugins/canvas/public/lib/get_es_filter.js
Normal 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}`);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue