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

Move generateFilters ⇒ NP #50118

Merged
merged 14 commits into from
Nov 14, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import { IInjector } from 'ui/chrome';
// @ts-ignore
import * as filterActions from 'plugins/kibana/discover/doc_table/actions/filter';

// @ts-ignore
import { getFilterGenerator } from 'ui/filter_manager';

import {
AppStateClass as TAppStateClass,
AppState as TAppState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function createIndexPatternsStub() {
get: sinon.spy(indexPatternId =>
Promise.resolve({
id: indexPatternId,
isTimeNanosBased: () => false
isTimeNanosBased: () => false,
popularizeField: () => {},
})
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,33 @@

import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import sinon from 'sinon';
import { getServices } from '../../../../kibana_services';
import { createStateStub } from './_utils';
import { QueryParameterActionsProvider } from '../actions';

import { createIndexPatternsStub } from '../../api/__tests__/_stubs';
import { npStart } from 'ui/new_platform';

describe('context app', function () {
beforeEach(ngMock.module('kibana'));

beforeEach(ngMock.module(function createServiceStubs($provide) {
$provide.value('indexPatterns', createIndexPatternsStub());
}));

describe('action addFilter', function () {
let filterManagerStub;
let addFilter;

beforeEach(ngMock.inject(function createPrivateStubs(Private) {
filterManagerStub = createQueryFilterStub();
Private.stub(getServices().FilterBarQueryFilterProvider, filterManagerStub);

Private.stub(getServices().FilterBarQueryFilterProvider);
addFilter = Private(QueryParameterActionsProvider).addFilter;
}));

it('should pass the given arguments to the filterManager', function () {
const state = createStateStub();
const filterManagerAddStub = npStart.plugins.data.query.filterManager.addFilters;

addFilter(state)('FIELD_NAME', 'FIELD_VALUE', 'FILTER_OPERATION');

const filterManagerAddStub = filterManagerStub.addFilters;
//get the generated filter
const generatedFilter = filterManagerAddStub.firstCall.args[0][0];
const queryKeys = Object.keys(generatedFilter.query.match_phrase);
Expand All @@ -55,20 +56,12 @@ describe('context app', function () {

it('should pass the index pattern id to the filterManager', function () {
const state = createStateStub();
const filterManagerAddStub = npStart.plugins.data.query.filterManager.addFilters;

addFilter(state)('FIELD_NAME', 'FIELD_VALUE', 'FILTER_OPERATION');

const filterManagerAddStub = filterManagerStub.addFilters;
const generatedFilter = filterManagerAddStub.firstCall.args[0][0];
expect(filterManagerAddStub.calledOnce).to.be(true);
expect(generatedFilter.meta.index).to.eql('INDEX_PATTERN_ID');
});
});
});

function createQueryFilterStub() {
return {
addFilters: sinon.stub(),
getAppFilters: sinon.stub(),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import _ from 'lodash';
import { getServices, getFilterGenerator } from '../../../kibana_services';
import { generateFilters } from '../../../../../../../../plugins/data/public';
import { npStart } from 'ui/new_platform';

import {
MAX_CONTEXT_SIZE,
Expand All @@ -27,9 +28,8 @@ import {
} from './constants';


export function QueryParameterActionsProvider(indexPatterns, Private) {
const queryFilter = Private(getServices().FilterBarQueryFilterProvider);
const filterGen = getFilterGenerator(queryFilter);
export function QueryParameterActionsProvider(indexPatterns) {
const { filterManager } = npStart.plugins.data.query;

const setPredecessorCount = (state) => (predecessorCount) => (
state.queryParameters.predecessorCount = clamp(
Expand All @@ -55,13 +55,13 @@ export function QueryParameterActionsProvider(indexPatterns, Private) {
);

const updateFilters = () => filters => {
queryFilter.setFilters(filters);
filterManager.setFilters(filters);
};

const addFilter = (state) => async (field, values, operation) => {
const indexPatternId = state.queryParameters.indexPatternId;
const newFilters = filterGen.generate(field, values, operation, indexPatternId);
queryFilter.addFilters(newFilters);
const newFilters = generateFilters(filterManager, field, values, operation, indexPatternId);
filterManager.addFilters(newFilters);
const indexPattern = await indexPatterns.get(indexPatternId);
indexPattern.popularizeField(field.name, 1);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import './doc_table';
import { getSort } from './doc_table/lib/get_sort';
import { getSortForSearchSource } from './doc_table/lib/get_sort_for_search_source';
import * as columnActions from './doc_table/actions/columns';
import * as filterActions from './doc_table/actions/filter';

import indexTemplate from './discover.html';
import { showOpenSearchPanel } from '../top_nav/show_open_search_panel';
Expand All @@ -41,7 +40,6 @@ import { getPainlessError } from './get_painless_error';
import {
angular,
buildVislibDimensions,
getFilterGenerator,
getRequestInspectorStats,
getResponseInspectorStats,
getServices,
Expand Down Expand Up @@ -76,7 +74,7 @@ const {
import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../breadcrumbs';
import { extractTimeFilter, changeTimeFilter } from '../../../../data/public';
import { start as data } from '../../../../data/public/legacy';

import { generateFilters } from '../../../../../../plugins/data/public';

const { savedQueryService } = data.search.services;

Expand Down Expand Up @@ -196,7 +194,6 @@ function discoverController(
const shareContextMenuExtensions = Private(ShareContextMenuExtensionsRegistryProvider);

const queryFilter = Private(FilterBarQueryFilterProvider);
const filterGen = getFilterGenerator(queryFilter);

const inspectorAdapters = {
requests: new RequestAdapter()
Expand Down Expand Up @@ -901,7 +898,8 @@ function discoverController(
// TODO: On array fields, negating does not negate the combination, rather all terms
$scope.filterQuery = function (field, values, operation) {
$scope.indexPattern.popularizeField(field, 1);
filterActions.addFilter(field, values, operation, $scope.indexPattern.id, $scope.state, filterGen);
const newFilters = generateFilters(queryFilter, field, values, operation, $scope.indexPattern.id);
return queryFilter.addFilters(newFilters);
};

$scope.addColumn = function addColumn(columnName) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import { npStart } from 'ui/new_platform';
import {
esFilters,
TimeRange,
FilterManager,
onlyDisabledFiltersChanged,
generateFilters,
getTime,
} from '../../../../../../plugins/data/public';
import { Query } from '../../../../data/public';
Expand All @@ -43,7 +45,6 @@ import { getSortForSearchSource } from '../angular/doc_table/lib/get_sort_for_se
import {
Adapters,
angular,
getFilterGenerator,
getRequestInspectorStats,
getResponseInspectorStats,
getServices,
Expand Down Expand Up @@ -72,18 +73,6 @@ interface SearchScope extends ng.IScope {
isLoading?: boolean;
}

export interface FilterManager {
generate: (
field: {
name: string;
scripted: boolean;
},
values: string | string[],
operation: string,
index: number
) => esFilters.Filter[];
}

interface SearchEmbeddableConfig {
$rootScope: ng.IRootScopeService;
$compile: ng.ICompileService;
Expand All @@ -107,7 +96,7 @@ export class SearchEmbeddable extends Embeddable<SearchInput, SearchOutput>
private autoRefreshFetchSubscription?: Subscription;
private subscription?: Subscription;
public readonly type = SEARCH_EMBEDDABLE_TYPE;
private filterGen: FilterManager;
private filterManager: FilterManager;
private abortController?: AbortController;

private prevTimeRange?: TimeRange;
Expand All @@ -134,7 +123,7 @@ export class SearchEmbeddable extends Embeddable<SearchInput, SearchOutput>
parent
);

this.filterGen = getFilterGenerator(queryFilter);
this.filterManager = queryFilter as FilterManager;
this.savedSearch = savedSearch;
this.$rootScope = $rootScope;
this.$compile = $compile;
Expand Down Expand Up @@ -251,7 +240,7 @@ export class SearchEmbeddable extends Embeddable<SearchInput, SearchOutput>
};

searchScope.filter = async (field, value, operator) => {
let filters = this.filterGen.generate(field, value, operator, indexPattern.id);
let filters = generateFilters(this.filterManager, field, value, operator, indexPattern.id);
filters = filters.map(filter => ({
...filter,
$state: { store: esFilters.FilterStateStore.APP_STATE },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export { angular };
export { buildVislibDimensions } from 'ui/visualize/loader/pipeline_helpers/build_pipeline';
// @ts-ignore
export { callAfterBindingsWorkaround } from 'ui/compat';
// @ts-ignore
export { getFilterGenerator } from 'ui/filter_manager';
export {
getRequestInspectorStats,
getResponseInspectorStats,
Expand Down
Loading