Skip to content

Commit

Permalink
Move apply filters action to NP (#52156) (#52519)
Browse files Browse the repository at this point in the history
* move action

* attach action in start

* Remove uiActions from core_plugins/data

* Don't export apply filters popup

* import DataPublicPlugin after all other deps have loaded

* lint

* Remove unused import
  • Loading branch information
Liza Katz authored Dec 9, 2019
1 parent f12d3a4 commit 0e2c3bc
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ import { setup, start } from '../core_plugins/visualizations/public/legacy';
| Legacy Platform | New Platform | Notes |
| ------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `import 'ui/apply_filters'` | `import { applyFiltersPopover } from '../data/public'` | Directive is deprecated. |
| `import 'ui/apply_filters'` | N/A. Replaced by triggering an APPLY_FILTER_TRIGGER trigger. | Directive is deprecated. |
| `import 'ui/filter_bar'` | `import { FilterBar } from '../data/public'` | Directive is deprecated. |
| `import 'ui/query_bar'` | `import { QueryStringInput } from '../data/public'` | Directives are deprecated. |
| `import 'ui/search_bar'` | `import { SearchBar } from '../data/public'` | Directive is deprecated. |
Expand Down
1 change: 0 additions & 1 deletion src/legacy/core_plugins/data/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ export const setup = dataPlugin.setup(npSetup.core);

export const start = dataPlugin.start(npStart.core, {
data: npStart.plugins.data,
uiActions: npSetup.plugins.uiActions,
});
20 changes: 1 addition & 19 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@ import { createSearchBar, StatetfulSearchBarProps } from './search';
import { Storage, IStorageWrapper } from '../../../../../src/plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
import { initLegacyModule } from './shim/legacy_module';
import { IUiActionsSetup } from '../../../../plugins/ui_actions/public';
import {
createFilterAction,
GLOBAL_APPLY_FILTER_ACTION,
} from './filter/action/apply_filter_action';
import { APPLY_FILTER_TRIGGER } from '../../../../plugins/embeddable/public';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setFieldFormats } from '../../../../plugins/data/public/services';

export interface DataPluginStartDependencies {
data: DataPublicPluginStart;
uiActions: IUiActionsSetup;
}

/**
Expand Down Expand Up @@ -67,7 +60,7 @@ export class DataPlugin implements Plugin<void, DataStart, {}, DataPluginStartDe
this.storage = new Storage(window.localStorage);
}

public start(core: CoreStart, { data, uiActions }: DataPluginStartDependencies): DataStart {
public start(core: CoreStart, { data }: DataPluginStartDependencies): DataStart {
// This is required for when Angular code uses Field and FieldList.
setFieldFormats(data.fieldFormats);
initLegacyModule(data.indexPatterns);
Expand All @@ -78,17 +71,6 @@ export class DataPlugin implements Plugin<void, DataStart, {}, DataPluginStartDe
storage: this.storage,
});

uiActions.registerAction(
createFilterAction(
core.overlays,
data.query.filterManager,
data.query.timefilter.timefilter,
data.indexPatterns
)
);

uiActions.attachAction(APPLY_FILTER_TRIGGER, GLOBAL_APPLY_FILTER_ACTION);

return {
ui: {
SearchBar,
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": "data",
"version": "kibana",
"server": true,
"ui": true
"ui": true,
"requiredPlugins": ["uiActions"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@
*/

import { i18n } from '@kbn/i18n';
import { CoreStart } from 'src/core/public';
import { toMountPoint } from '../../../../../../plugins/kibana_react/public';
import {
IAction,
createAction,
IncompatibleActionError,
} from '../../../../../../plugins/ui_actions/public';
import { toMountPoint } from '../../../kibana_react/public';
import { IAction, createAction, IncompatibleActionError } from '../../../ui_actions/public';
import { getOverlays, getIndexPatterns } from '../services';
import { applyFiltersPopover } from '../ui/apply_filters';
import {
esFilters,
FilterManager,
TimefilterContract,
applyFiltersPopover,
changeTimeFilter,
extractTimeFilter,
IndexPatternsContract,
} from '../../../../../../plugins/data/public';
} from '..';

export const GLOBAL_APPLY_FILTER_ACTION = 'GLOBAL_APPLY_FILTER_ACTION';

Expand All @@ -47,10 +42,8 @@ async function isCompatible(context: ActionContext) {
}

export function createFilterAction(
overlays: CoreStart['overlays'],
filterManager: FilterManager,
timeFilter: TimefilterContract,
indexPatternsService: IndexPatternsContract
timeFilter: TimefilterContract
): IAction<ActionContext> {
return createAction<ActionContext>({
type: GLOBAL_APPLY_FILTER_ACTION,
Expand All @@ -75,12 +68,12 @@ export function createFilterAction(
if (selectedFilters.length > 1) {
const indexPatterns = await Promise.all(
filters.map(filter => {
return indexPatternsService.get(filter.meta.index!);
return getIndexPatterns().get(filter.meta.index!);
})
);

const filterSelectionPromise: Promise<esFilters.Filter[]> = new Promise(resolve => {
const overlay = overlays.openModal(
const overlay = getOverlays().openModal(
toMountPoint(
applyFiltersPopover(
filters,
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/data/public/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { GLOBAL_APPLY_FILTER_ACTION, createFilterAction } from './apply_filter_action';
8 changes: 4 additions & 4 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
*/

import { PluginInitializerContext } from '../../../core/public';
import { DataPublicPlugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
return new DataPublicPlugin(initializerContext);
}

export { DataPublicPlugin as Plugin };

export * from '../common';

export * from './autocomplete_provider';
Expand All @@ -39,3 +35,7 @@ export * from './search';
export * from './query';

export * from './ui';

// Export plugin after all other imports
import { DataPublicPlugin } from './plugin';
export { DataPublicPlugin as Plugin };
34 changes: 25 additions & 9 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@

import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'src/core/public';
import { Storage } from '../../kibana_utils/public';
import { DataPublicPluginSetup, DataPublicPluginStart } from './types';
import {
DataPublicPluginSetup,
DataPublicPluginStart,
DataSetupDependencies,
DataStartDependencies,
} from './types';
import { AutocompleteProviderRegister } from './autocomplete_provider';
import { getSuggestionsProvider } from './suggestions_provider';
import { SearchService } from './search/search_service';
import { FieldFormatsService } from './field_formats_provider';
import { QueryService } from './query';
import { createIndexPatternSelect } from './ui/index_pattern_select';
import { IndexPatterns } from './index_patterns';
import { setNotifications, setFieldFormats } from './services';
import { setNotifications, setFieldFormats, setOverlays, setIndexPatterns } from './services';
import { createFilterAction, GLOBAL_APPLY_FILTER_ACTION } from './actions';
import { APPLY_FILTER_TRIGGER } from '../../embeddable/public';

export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPublicPluginStart> {
private readonly autocomplete = new AutocompleteProviderRegister();
Expand All @@ -41,27 +48,36 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
this.fieldFormatsService = new FieldFormatsService();
}

public setup(core: CoreSetup): DataPublicPluginSetup {
public setup(core: CoreSetup, { uiActions }: DataSetupDependencies): DataPublicPluginSetup {
const storage = new Storage(window.localStorage);
const queryService = this.queryService.setup({
uiSettings: core.uiSettings,
storage,
});

uiActions.registerAction(
createFilterAction(queryService.filterManager, queryService.timefilter.timefilter)
);

return {
autocomplete: this.autocomplete,
search: this.searchService.setup(core),
fieldFormats: this.fieldFormatsService.setup(core),
query: this.queryService.setup({
uiSettings: core.uiSettings,
storage,
}),
query: queryService,
};
}

public start(core: CoreStart): DataPublicPluginStart {
const { uiSettings, http, notifications, savedObjects } = core;
public start(core: CoreStart, { uiActions }: DataStartDependencies): DataPublicPluginStart {
const { uiSettings, http, notifications, savedObjects, overlays } = core;
const fieldFormats = this.fieldFormatsService.start();
setNotifications(notifications);
setFieldFormats(fieldFormats);
setOverlays(overlays);

const indexPatternsService = new IndexPatterns(uiSettings, savedObjects.client, http);
setIndexPatterns(indexPatternsService);

uiActions.attachAction(APPLY_FILTER_TRIGGER, GLOBAL_APPLY_FILTER_ACTION);

return {
autocomplete: this.autocomplete,
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/data/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
*/

import { NotificationsStart, HttpStart } from 'src/core/public';
import { CoreStart } from 'kibana/public';
import { FieldFormatsStart } from '.';
import { createGetterSetter } from '../../kibana_utils/public';
import { IndexPatternsContract } from './index_patterns';

export const [getNotifications, setNotifications] = createGetterSetter<NotificationsStart>(
'Notifications'
Expand All @@ -30,3 +32,8 @@ export const [getFieldFormats, setFieldFormats] = createGetterSetter<FieldFormat
);

export const [getHttp, setHttp] = createGetterSetter<HttpStart>('Http');
export const [getOverlays, setOverlays] = createGetterSetter<CoreStart['overlays']>('Overlays');

export const [getIndexPatterns, setIndexPatterns] = createGetterSetter<IndexPatternsContract>(
'IndexPatterns'
);
9 changes: 9 additions & 0 deletions src/plugins/data/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { CoreStart } from 'src/core/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { IUiActionsSetup, IUiActionsStart } from 'src/plugins/ui_actions/public';
import { AutocompletePublicPluginSetup, AutocompletePublicPluginStart } from '.';
import { FieldFormatsSetup, FieldFormatsStart } from './field_formats_provider';
import { ISearchSetup, ISearchStart } from './search';
Expand All @@ -27,6 +28,14 @@ import { QuerySetup, QueryStart } from './query';
import { IndexPatternSelectProps } from './ui/index_pattern_select';
import { IndexPatternsContract } from './index_patterns';

export interface DataSetupDependencies {
uiActions: IUiActionsSetup;
}

export interface DataStartDependencies {
uiActions: IUiActionsStart;
}

export interface DataPublicPluginSetup {
autocomplete: AutocompletePublicPluginSetup;
search: ISearchSetup;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
export { SuggestionsComponent } from './typeahead/suggestions_component';
export { IndexPatternSelect } from './index_pattern_select';
export { FilterBar } from './filter_bar';
export { applyFiltersPopover } from './apply_filters';
export { QueryStringInput } from './query_string_input/query_string_input';

// temp export - will be removed as final components are migrated to NP
Expand Down

0 comments on commit 0e2c3bc

Please sign in to comment.