Skip to content

Commit

Permalink
Move saved queries service + language switcher ⇒ NP (#51812)
Browse files Browse the repository at this point in the history
* Move saved queries service + language switcher to NP

* test fixes

* test fix

* fix ts

* mock search service
  • Loading branch information
Liza Katz committed Nov 28, 2019
1 parent ffe067a commit 3a212f3
Show file tree
Hide file tree
Showing 39 changed files with 131 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { resolve } from 'path';
import { Legacy } from '../../../../kibana';
import { mappings } from './mappings';
import { SavedQuery } from './public';
import { SavedQuery } from '../../../plugins/data/public';

// eslint-disable-next-line import/no-default-export
export default function DataPlugin(kibana: any) {
Expand Down
7 changes: 6 additions & 1 deletion src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export {
StaticIndexPattern,
} from './index_patterns';
export { QueryStringInput } from './query';
export { SearchBar, SearchBarProps, SavedQueryAttributes, SavedQuery } from './search';
export { SearchBar, SearchBarProps } from './search';
export {
SavedQueryAttributes,
SavedQuery,
SavedQueryTimeFilter,
} from '../../../../plugins/data/public';

/** @public static code */
export * from '../common';
Expand Down
6 changes: 1 addition & 5 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { SearchService, SearchStart, createSearchBar, StatetfulSearchBarProps } from './search';
import { createSearchBar, StatetfulSearchBarProps } from './search';
import { IndexPatternsService, IndexPatternsSetup, IndexPatternsStart } from './index_patterns';
import { Storage, IStorageWrapper } from '../../../../../src/plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
Expand Down Expand Up @@ -51,7 +51,6 @@ export interface DataSetup {
*/
export interface DataStart {
indexPatterns: IndexPatternsStart;
search: SearchStart;
ui: {
SearchBar: React.ComponentType<StatetfulSearchBarProps>;
};
Expand All @@ -71,7 +70,6 @@ export interface DataStart {

export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginStartDependencies> {
private readonly indexPatterns: IndexPatternsService = new IndexPatternsService();
private readonly search: SearchService = new SearchService();

private setupApi!: DataSetup;
private storage!: IStorageWrapper;
Expand Down Expand Up @@ -119,7 +117,6 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt
return {
...this.setupApi!,
indexPatterns: indexPatternsService,
search: this.search.start(savedObjects.client),
ui: {
SearchBar,
},
Expand All @@ -128,6 +125,5 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt

public stop() {
this.indexPatterns.stop();
this.search.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {

import { EuiFieldText } from '@elastic/eui';
import React from 'react';
import { QueryLanguageSwitcher } from './language_switcher';
import { QueryLanguageSwitcher } from '../../../../../../../plugins/data/public';
import { QueryStringInput, QueryStringInputUI } from './query_string_input';
import { coreMock } from '../../../../../../../core/public/mocks';
const startMock = coreMock.createStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ import {
matchPairs,
getQueryLog,
Query,
QueryLanguageSwitcher,
} from '../../../../../../../plugins/data/public';
import {
withKibana,
KibanaReactContextValue,
toMountPoint,
} from '../../../../../../../plugins/kibana_react/public';
import { QueryLanguageSwitcher } from './language_switcher';
import { fetchIndexPatterns } from './fetch_index_patterns';

interface Props {
Expand Down
1 change: 0 additions & 1 deletion src/legacy/core_plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

export * from './search_service';
export * from './search_bar';
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { sortBy, isEqual } from 'lodash';
import { SavedQuery, SavedQueryAttributes } from '../../index';
import { SavedQueryService } from '../../lib/saved_query_service';
import {
SavedQuery,
SavedQueryAttributes,
SavedQueryService,
} from '../../../../../../../../plugins/data/public';

interface Props {
savedQuery?: SavedQueryAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EuiListGroupItem, EuiConfirmModal, EuiOverlayMask, EuiIconTip } from '@
import React, { Fragment, useState } from 'react';
import classNames from 'classnames';
import { i18n } from '@kbn/i18n';
import { SavedQuery } from '../../index';
import { SavedQuery } from '../../../../../../../../plugins/data/public';

interface Props {
savedQuery: SavedQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import {
import { i18n } from '@kbn/i18n';
import React, { FunctionComponent, useEffect, useState, Fragment } from 'react';
import { sortBy } from 'lodash';
import { SavedQuery } from '../../index';
import { SavedQueryService } from '../../lib/saved_query_service';
import { SavedQuery, SavedQueryService } from '../../../../../../../../plugins/data/public';
import { SavedQueryListItem } from './saved_query_list_item';

const perPage = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const mockTimeHistory = {
jest.mock('../../../../../../../plugins/data/public', () => {
return {
FilterBar: () => <div className="filterBar" />,
createSavedQueryService: () => {},
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ import { get, isEqual } from 'lodash';

import { IndexPattern } from '../../../../../data/public';
import { QueryBarTopRow } from '../../../query';
import { SavedQuery, SavedQueryAttributes } from '../index';
import { SavedQueryMeta, SaveQueryForm } from './saved_query_management/save_query_form';
import { SavedQueryManagementComponent } from './saved_query_management/saved_query_management_component';
import { SavedQueryService } from '../lib/saved_query_service';
import { createSavedQueryService } from '../lib/saved_query_service';

import {
withKibana,
KibanaReactContextValue,
Expand All @@ -42,6 +40,10 @@ import {
esFilters,
TimeHistoryContract,
FilterBar,
SavedQueryService,
createSavedQueryService,
SavedQuery,
SavedQueryAttributes,
} from '../../../../../../../plugins/data/public';

interface SearchBarInjectedDeps {
Expand Down
19 changes: 0 additions & 19 deletions src/legacy/core_plugins/data/public/search/search_bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,4 @@
* under the License.
*/

import { RefreshInterval, TimeRange, Query, esFilters } from 'src/plugins/data/public';

export * from './components';

export type SavedQueryTimeFilter = TimeRange & {
refreshInterval: RefreshInterval;
};

export interface SavedQuery {
id: string;
attributes: SavedQueryAttributes;
}

export interface SavedQueryAttributes {
title: string;
description: string;
query: Query;
filters?: esFilters.Filter[];
timefilter?: SavedQueryTimeFilter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface RenderDeps {
uiSettings: UiSettingsClientContract;
chrome: ChromeStart;
addBasePath: (path: string) => string;
savedQueryService: DataStart['search']['services']['savedQueryService'];
savedQueryService: NpDataStart['query']['savedQueries'];
embeddables: IEmbeddableStart;
localStorage: Storage;
share: SharePluginStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { StaticIndexPattern, SavedQuery } from 'plugins/data';
import { StaticIndexPattern } from 'plugins/data';
import moment from 'moment';
import { Subscription } from 'rxjs';

Expand All @@ -31,7 +31,7 @@ import {
import { ViewMode } from '../../../embeddable_api/public/np_ready/public';
import { SavedObjectDashboard } from './saved_dashboard/saved_dashboard';
import { DashboardAppState, SavedDashboardPanel, ConfirmModalFn } from './types';
import { TimeRange, Query, esFilters } from '../../../../../../src/plugins/data/public';
import { TimeRange, Query, esFilters, SavedQuery } from '../../../../../../src/plugins/data/public';

import { DashboardAppController } from './dashboard_app_controller';
import { RenderDeps } from './application';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {
SavedObjectFinder,
unhashUrl,
} from './legacy_imports';
import { FilterStateManager, IndexPattern, SavedQuery } from '../../../data/public';
import { Query } from '../../../../../plugins/data/public';
import { FilterStateManager, IndexPattern } from '../../../data/public';
import { Query, SavedQuery } from '../../../../../plugins/data/public';

import './dashboard_empty_screen_directive';

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class DashboardPlugin implements Plugin {
chrome: contextCore.chrome,
addBasePath: contextCore.http.basePath.prepend,
uiSettings: contextCore.uiSettings,
savedQueryService: dataStart.search.services.savedQueryService,
savedQueryService: npDataStart.query.savedQueries,
embeddables,
dashboardCapabilities: contextCore.application.capabilities.dashboard,
localStorage: new Storage(localStorage),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ const {
share,
StateProvider,
timefilter,
npData,
toastNotifications,
uiModules,
uiRoutes,
} = getServices();

import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../breadcrumbs';
import { start as data } from '../../../../data/public/legacy';
import { generateFilters } from '../../../../../../plugins/data/public';
import { start as data } from '../../../../data/public/legacy';

const { savedQueryService } = data.search.services;
const savedQueryService = npData.query.savedQueries;

const fetchStatuses = {
UNINITIALIZED: 'uninitialized',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { StateProvider } from 'ui/state_management/state';
import { SavedObjectProvider } from 'ui/saved_objects/saved_object';
import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { timefilter } from 'ui/timefilter';
// @ts-ignore
import { IndexPattern, IndexPatterns } from 'ui/index_patterns';
import { wrapInI18nContext } from 'ui/i18n';
Expand All @@ -58,7 +57,9 @@ const services = {
uiSettings: npStart.core.uiSettings,
uiActions: npStart.plugins.uiActions,
embeddable: npStart.plugins.embeddable,
npData: npStart.plugins.data,
share: npStart.plugins.share,
timefilter: npStart.plugins.data.query.timefilter.timefilter,
// legacy
docTitle,
docViewsRegistry,
Expand All @@ -70,7 +71,6 @@ const services = {
SavedObjectProvider,
SearchSource,
StateProvider,
timefilter,
uiModules,
uiRoutes,
wrapInI18nContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ const {
capabilities,
chrome,
chromeLegacy,
npData,
data,
docTitle,
FilterBarQueryFilterProvider,
getBasePath,
toastNotifications,
timefilter,
uiModules,
uiRoutes,
visualizations,
share,
} = getServices();

const { savedQueryService } = data.search.services;
const savedQueryService = npData.query.savedQueries;
const { timefilter } = npData.query.timefilter;

uiRoutes
.when(VisualizeConstants.CREATE_PATH, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { uiModules } from 'ui/modules';
import { FeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue';
import { timefilter } from 'ui/timefilter';

// Saved objects
import { SavedObjectsClientProvider } from 'ui/saved_objects';
Expand All @@ -46,8 +45,8 @@ import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_regis

import { createUiStatsReporter, METRIC_TYPE } from '../../../ui_metric/public';
import { start as visualizations } from '../../../visualizations/public/np_ready/public/legacy';
import { start as data } from '../../../data/public/legacy';
import { start as embeddables } from '../../../../core_plugins/embeddable_api/public/np_ready/public/legacy';
import { start as data } from '../../../data/public/legacy';

const services = {
// new platform
Expand All @@ -63,6 +62,7 @@ const services = {
core: npStart.core,

share: npStart.plugins.share,
npData: npStart.plugins.data,
data,
embeddables,
visualizations,
Expand All @@ -78,7 +78,7 @@ const services = {
SavedObjectProvider,
SavedObjectRegistryProvider,
SavedObjectsClientProvider,
timefilter,
timefilter: npStart.plugins.data.query.timefilter.timefilter,
uiModules,
uiRoutes,
wrapInI18nContext,
Expand Down
8 changes: 8 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ export const npSetup = {
timefilter: sinon.fake(),
history: sinon.fake(),
},
savedQueries: {
saveQuery: sinon.fake(),
getAllSavedQueries: sinon.fake(),
findSavedQueries: sinon.fake(),
getSavedQuery: sinon.fake(),
deleteSavedQuery: sinon.fake(),
getSavedQueryCount: sinon.fake(),
}
},
fieldFormats: getFieldFormatsRegistry(mockUiSettings),
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
getSuggestions: getSuggestionsProvider(core.uiSettings, core.http),
search: this.searchService.start(core),
fieldFormats: this.fieldFormatsService.start(),
query: this.queryService.start(),
query: this.queryService.start(core.savedObjects),
ui: {
IndexPatternSelect: createIndexPatternSelect(core.savedObjects.client),
},
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data/public/query/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export * from './lib';

export * from './query_service';
export * from './filter_manager';

export * from './timefilter';

export * from './saved_query';
export * from './persisted_log';
1 change: 1 addition & 0 deletions src/plugins/data/public/query/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const createStartContractMock = () => {
const startContract = {
filterManager: jest.fn() as any,
timefilter: timefilterServiceMock.createStartContract(),
savedQueries: jest.fn() as any,
};

return startContract;
Expand Down
Loading

0 comments on commit 3a212f3

Please sign in to comment.