Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into newplatform/misc/…
Browse files Browse the repository at this point in the history
…storage
  • Loading branch information
Liza K committed Oct 29, 2019
2 parents 89f4513 + 19c4f87 commit 06bcd0a
Show file tree
Hide file tree
Showing 81 changed files with 307 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
createAction,
IncompatibleActionError,
} from '../../../../../../plugins/ui_actions/public';
import { changeTimeFilter, extractTimeFilter, FilterManager } from '../filter_manager';
import { TimefilterContract } from '../../timefilter';
import { FilterManager } from '../../../../../../plugins/data/public';
import { TimefilterContract, changeTimeFilter, extractTimeFilter } from '../../timefilter';
import { applyFiltersPopover } from '../apply_filters/apply_filters_popover';
import { IndexPatternsStart } from '../../index_patterns';
export const GLOBAL_APPLY_FILTER_ACTION = 'GLOBAL_APPLY_FILTER_ACTION';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import React, { Component } from 'react';
import { IndexPattern } from '../../index_patterns';
import { getFilterDisplayText } from '../filter_bar/filter_editor/lib/get_filter_display_text';
import { mapAndFlattenFilters } from '../filter_manager/lib/map_and_flatten_filters';
import { mapAndFlattenFilters } from '../../../../../../plugins/data/public';
import { getDisplayValueFromFilter } from '../filter_bar/filter_editor/lib/get_display_value';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { FilterStateManager } from './filter_state_manager';

import { StubState } from './test_helpers/stub_state';
import { getFilter } from './test_helpers/get_stub_filter';
import { FilterManager } from './filter_manager';
import { FilterManager } from '../../../../../../plugins/data/public';

import { coreMock } from '../../../../../../core/public/mocks';
const setupMock = coreMock.createSetup();
Expand Down Expand Up @@ -101,25 +101,29 @@ describe('filter_state_manager', () => {
});

test('should update filter manager global filters', done => {
const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
globalStateStub.filters.push(f1);

setTimeout(() => {
const updateSubscription = filterManager.getUpdates$().subscribe(() => {
expect(filterManager.getGlobalFilters()).toHaveLength(1);
if (updateSubscription) {
updateSubscription.unsubscribe();
}
done();
}, 100);
});

const f1 = getFilter(FilterStateStore.GLOBAL_STATE, true, true, 'age', 34);
globalStateStub.filters.push(f1);
});

test('should update filter manager app filters', done => {
expect(filterManager.getAppFilters()).toHaveLength(0);
test('should update filter manager app filter', done => {
const updateSubscription = filterManager.getUpdates$().subscribe(() => {
expect(filterManager.getAppFilters()).toHaveLength(1);
if (updateSubscription) {
updateSubscription.unsubscribe();
}
done();
});

const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
appStateStub.filters.push(f1);

setTimeout(() => {
expect(filterManager.getAppFilters()).toHaveLength(1);
done();
}, 100);
});

test('should update URL when filter manager filters are set', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { FilterStateStore } from '@kbn/es-query';

import _ from 'lodash';
import { State } from 'ui/state_management/state';
import { FilterManager } from './filter_manager';
import { FilterManager } from '../../../../../../plugins/data/public';

type GetAppStateFunc = () => State | undefined | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,4 @@
* under the License.
*/

export { FilterManager } from './filter_manager';
export { FilterStateManager } from './filter_state_manager';

export { uniqFilters } from './lib/uniq_filters';
export { extractTimeFilter } from './lib/extract_time_filter';
export { changeTimeFilter } from './lib/change_time_filter';
export { onlyDisabledFiltersChanged } from './lib/only_disabled';
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/data/public/filter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

export * from './filter_service';

export { FilterBar } from './filter_bar';

export { ApplyFiltersPopover } from './apply_filters';
18 changes: 9 additions & 9 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ export { SearchBar, SearchBarProps, SavedQueryAttributes, SavedQuery } from './s

/** @public static code */
export * from '../common';
export {
FilterManager,
FilterStateManager,
uniqFilters,
extractTimeFilter,
changeTimeFilter,
onlyDisabledFiltersChanged,
} from './filter/filter_manager';
export { FilterStateManager } from './filter/filter_manager';
export {
CONTAINS_SPACES,
getFromSavedObject,
Expand All @@ -69,4 +62,11 @@ export {
mockIndexPattern,
} from './index_patterns';

export { TimeHistoryContract, TimefilterContract, getTime, InputTimeRange } from './timefilter';
export {
TimeHistoryContract,
TimefilterContract,
getTime,
InputTimeRange,
extractTimeFilter,
changeTimeFilter,
} from './timefilter';
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
* under the License.
*/

import { filterServiceMock } from './filter/filter_service.mock';
import { indexPatternsServiceMock } from './index_patterns/index_patterns_service.mock';
import { queryServiceMock } from './query/query_service.mock';
import { timefilterServiceMock } from './timefilter/timefilter_service.mock';

function createDataSetupMock() {
return {
filter: filterServiceMock.createSetupContract(),
indexPatterns: indexPatternsServiceMock.createSetupContract(),
query: queryServiceMock.createSetupContract(),
timefilter: timefilterServiceMock.createSetupContract(),
Expand Down
14 changes: 2 additions & 12 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { SearchService, SearchStart, createSearchBar, StatetfulSearchBarProps } from './search';
import { QueryService, QuerySetup } from './query';
import { FilterService, FilterSetup, FilterStart } from './filter';
import { TimefilterService, TimefilterSetup } from './timefilter';
import { IndexPatternsService, IndexPatternsSetup, IndexPatternsStart } from './index_patterns';
import { Storage, IStorageWrapper } from '../../../../../src/plugins/kibana_utils/public';
Expand All @@ -47,7 +46,6 @@ export interface DataSetup {
query: QuerySetup;
timefilter: TimefilterSetup;
indexPatterns: IndexPatternsSetup;
filter: FilterSetup;
}

/**
Expand All @@ -59,7 +57,6 @@ export interface DataStart {
query: QuerySetup;
timefilter: TimefilterSetup;
indexPatterns: IndexPatternsStart;
filter: FilterStart;
search: SearchStart;
ui: {
SearchBar: React.ComponentType<StatetfulSearchBarProps>;
Expand All @@ -77,9 +74,8 @@ export interface DataStart {
* in the setup/start interfaces. The remaining items exported here are either types,
* or static code.
*/

export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginStartDependencies> {
// Exposed services, sorted alphabetically
private readonly filter: FilterService = new FilterService();
private readonly indexPatterns: IndexPatternsService = new IndexPatternsService();
private readonly query: QueryService = new QueryService();
private readonly search: SearchService = new SearchService();
Expand All @@ -97,14 +93,10 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt
uiSettings,
storage: this.storage,
});
const filterService = this.filter.setup({
uiSettings,
});
this.setupApi = {
indexPatterns: this.indexPatterns.setup(),
query: this.query.setup(),
timefilter: timefilterService,
filter: filterService,
};

return this.setupApi;
Expand All @@ -127,12 +119,11 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt
data,
storage: this.storage,
timefilter: this.setupApi.timefilter,
filterManager: this.setupApi.filter.filterManager,
});

uiActions.registerAction(
createFilterAction(
this.setupApi.filter.filterManager,
data.query.filterManager,
this.setupApi.timefilter.timefilter,
indexPatternsService
)
Expand All @@ -152,7 +143,6 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt

public stop() {
this.indexPatterns.stop();
this.filter.stop();
this.query.stop();
this.search.stop();
this.timefilter.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@ import { DataPublicPluginStart } from 'src/plugins/data/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public';
import { TimefilterSetup } from '../../../timefilter';
import { FilterManager, SearchBar } from '../../../';
import { SearchBar } from '../../../';
import { SearchBarOwnProps } from '.';

interface StatefulSearchBarDeps {
core: CoreStart;
data: DataPublicPluginStart;
storage: IStorageWrapper;
timefilter: TimefilterSetup;
filterManager: FilterManager;
}

export type StatetfulSearchBarProps = SearchBarOwnProps & {
appName: string;
};

const defaultFiltersUpdated = (filterManager: FilterManager) => {
const defaultFiltersUpdated = (data: DataPublicPluginStart) => {
return (filters: Filter[]) => {
filterManager.setFilters(filters);
data.query.filterManager.setFilters(filters);
};
};

Expand All @@ -55,16 +54,11 @@ const defaultOnRefreshChange = (timefilter: TimefilterSetup) => {
};
};

export function createSearchBar({
core,
storage,
timefilter,
filterManager,
data,
}: StatefulSearchBarDeps) {
export function createSearchBar({ core, storage, timefilter, data }: StatefulSearchBarDeps) {
// App name should come from the core application service.
// Until it's available, we'll ask the user to provide it for the pre-wired component.
return (props: StatetfulSearchBarProps) => {
const { filterManager } = data.query;
const tfRefreshInterval = timefilter.timefilter.getRefreshInterval();
const fmFilters = filterManager.getFilters();
const [refreshInterval, setRefreshInterval] = useState(tfRefreshInterval.value);
Expand Down Expand Up @@ -124,7 +118,7 @@ export function createSearchBar({
refreshInterval={refreshInterval}
isRefreshPaused={refreshPaused}
filters={filters}
onFiltersUpdated={defaultFiltersUpdated(filterManager)}
onFiltersUpdated={defaultFiltersUpdated(data)}
onRefreshChange={defaultOnRefreshChange(timefilter)}
{...props}
/>
Expand Down
3 changes: 0 additions & 3 deletions src/legacy/core_plugins/data/public/shim/legacy_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import { wrapInI18nContext } from 'ui/i18n';
import { uiModules } from 'ui/modules';
import { npStart } from 'ui/new_platform';
import { FilterBar, ApplyFiltersPopover } from '../filter';

// @ts-ignore
import { mapAndFlattenFilters } from '../filter/filter_manager/lib/map_and_flatten_filters';
import { IndexPatterns } from '../index_patterns/index_patterns';

/** @internal */
Expand Down
2 changes: 2 additions & 0 deletions src/legacy/core_plugins/data/public/timefilter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export * from './types';
export { Timefilter, TimefilterContract } from './timefilter';
export { TimeHistory, TimeHistoryContract } from './time_history';
export { getTime } from './get_time';
export { changeTimeFilter } from './lib/change_time_filter';
export { extractTimeFilter } from './lib/extract_time_filter';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { RangeFilter } from '@kbn/es-query';
import { changeTimeFilter } from './change_time_filter';
import { TimeRange } from 'src/plugins/data/public';
import { timefilterServiceMock } from '../../../timefilter/timefilter_service.mock';
import { timefilterServiceMock } from '../timefilter_service.mock';

const timefilterMock = timefilterServiceMock.createSetupContract();
const timefilter = timefilterMock.timefilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import moment from 'moment';
import { keys } from 'lodash';
import { RangeFilter } from '@kbn/es-query';
import { TimefilterContract } from '../../../timefilter';
import { TimefilterContract } from '../timefilter';

export function convertRangeFilterToTimeRange(filter: RangeFilter) {
const key = keys(filter.range)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { PhraseFilterManager } from './filter_manager/phrase_filter_manager';
import { createSearchSource } from './create_search_source';
import { i18n } from '@kbn/i18n';
import { npStart } from 'ui/new_platform';
import chrome from 'ui/chrome';
import { start as data } from '../../../../core_plugins/data/public/legacy';

Expand Down Expand Up @@ -187,9 +188,10 @@ export async function listControlFactory(controlParams, useTimeFilter, SearchSou
// ignore not found error and return control so it can be displayed in disabled state.
}

const { filterManager } = npStart.plugins.data.query;
return new ListControl(
controlParams,
new PhraseFilterManager(controlParams.id, controlParams.fieldName, indexPattern, data.filter.filterManager),
new PhraseFilterManager(controlParams.id, controlParams.fieldName, indexPattern, filterManager),
useTimeFilter,
SearchSource,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ jest.mock('ui/timefilter', () => ({
createFilter: jest.fn(),
}));

jest.mock('ui/new_platform', () => ({
npStart: {
plugins: {
data: {
query: {
filterManager: {
fieldName: 'myNumberField',
getIndexPattern: () => ({
fields: { getByName: name => {
const fields = { myField: { name: 'myField' } };
return fields[name];
} }
}),
getAppFilters: jest.fn().mockImplementation(() => ([])),
getGlobalFilters: jest.fn().mockImplementation(() => ([])),
}
}
}
},
},
}));

jest.mock('../../../../core_plugins/data/public/legacy', () => ({
start: {
indexPatterns: {
Expand All @@ -36,19 +58,6 @@ jest.mock('../../../../core_plugins/data/public/legacy', () => ({
}),
}
},
filter: {
filterManager: {
fieldName: 'myNumberField',
getIndexPattern: () => ({
fields: { getByName: name => {
const fields = { myField: { name: 'myField' } };
return fields[name];
} }
}),
getAppFilters: jest.fn().mockImplementation(() => ([])),
getGlobalFilters: jest.fn().mockImplementation(() => ([])),
}
}
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { RangeFilterManager } from './filter_manager/range_filter_manager';
import { createSearchSource } from './create_search_source';
import { i18n } from '@kbn/i18n';
import { start as data } from '../../../../core_plugins/data/public/legacy';
import { npStart } from 'ui/new_platform';

const minMaxAgg = (field) => {
const aggBody = {};
Expand Down Expand Up @@ -106,9 +107,10 @@ export async function rangeControlFactory(controlParams, useTimeFilter, SearchSo
} catch (err) {
// ignore not found error and return control so it can be displayed in disabled state.
}
const { filterManager } = npStart.plugins.data.query;
return new RangeControl(
controlParams,
new RangeFilterManager(controlParams.id, controlParams.fieldName, indexPattern, data.filter.filterManager),
new RangeFilterManager(controlParams.id, controlParams.fieldName, indexPattern, filterManager),
useTimeFilter,
SearchSource,
);
Expand Down
Loading

0 comments on commit 06bcd0a

Please sign in to comment.