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

Shim ui/autocomplete_providers into legacy data plugin #46138

Merged
merged 8 commits into from
Sep 24, 2019
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ export const mockPersistedLogFactory = jest.fn<jest.Mocked<typeof mockPersistedL
return mockPersistedLog;
});

export const mockGetAutocompleteSuggestions = jest.fn(() => Promise.resolve([]));
const mockAutocompleteProvider = jest.fn(() => mockGetAutocompleteSuggestions);
export const mockGetAutocompleteProvider = jest.fn(() => mockAutocompleteProvider);

export const mockFetchIndexPatterns = jest
.fn()
.mockReturnValue(Promise.resolve([mockIndexPattern]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ import React from 'react';
import { EuiFieldText, EuiOutsideClickDetector, PopoverAnchorPosition } from '@elastic/eui';

import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import {
AutocompleteSuggestion,
AutocompleteSuggestionType,
getAutocompleteProvider,
} from 'ui/autocomplete_providers';
import { debounce, compact, isEqual, omit } from 'lodash';
import { PersistedLog } from 'ui/persisted_log';
import { Storage } from 'ui/storage';
import { npSetup } from 'ui/new_platform';
alexwizp marked this conversation as resolved.
Show resolved Hide resolved
import {
UiSettingsClientContract,
SavedObjectsClientContract,
HttpServiceBase,
} from 'src/core/public';
import {
AutocompleteSuggestion,
AutocompleteSuggestionType,
} from '../../../../../../../plugins/data/public';
import { IndexPattern, StaticIndexPattern } from '../../../index_patterns';
import { Query } from '../index';
import { fromUser, matchPairs, toUser } from '../lib';
Expand All @@ -44,6 +44,9 @@ import { SuggestionsComponent } from './typeahead/suggestions_component';
import { getQueryLog } from '../lib/get_query_log';
import { fetchIndexPatterns } from '../lib/fetch_index_patterns';

const getAutocompleteProvider = (language: string) =>
npSetup.plugins.data.autocomplete.getProvider(language);

interface Props {
uiSettings: UiSettingsClientContract;
indexPatterns: Array<IndexPattern | string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { mount, shallow } from 'enzyme';
import React from 'react';
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public';
import { SuggestionComponent } from './suggestion_component';

const noop = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { EuiIcon } from '@elastic/eui';
import classNames from 'classnames';
import React, { FunctionComponent } from 'react';
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public';

function getEuiIconType(type: string) {
switch (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { mount, shallow } from 'enzyme';
import React from 'react';
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public';
import { SuggestionComponent } from './suggestion_component';
import { SuggestionsComponent } from './suggestions_component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { isEmpty } from 'lodash';
import React, { Component } from 'react';
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public';
import { SuggestionComponent } from './suggestion_component';

interface Props {
Expand Down
1 change: 0 additions & 1 deletion src/legacy/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import 'uiExports/embeddableFactories';
import 'uiExports/embeddableActions';
import 'uiExports/inspectorViews';
import 'uiExports/search';
import 'uiExports/autocompleteProviders';
import 'uiExports/shareContextMenuExtensions';

import 'ui/autoload/all';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import 'ui/registry/field_formats';
import 'uiExports/autocompleteProviders';
import 'uiExports/contextMenuActions';
import 'uiExports/devTools';
import 'uiExports/docViews';
Expand Down
1 change: 0 additions & 1 deletion src/legacy/ui/ui_exports/ui_export_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export {
aliases,
visualize,
search,
autocompleteProviders,
shareContextMenuExtensions,
} from './ui_app_extensions';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const appExtension = wrap(
export const visTypes = appExtension;

export const visEditorTypes = appExtension;
export const autocompleteProviders = appExtension;
export const savedObjectTypes = appExtension;
export const embeddableActions = appExtension;
export const embeddableFactories = appExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
import { AutocompleteProvider } from './types';
lizozom marked this conversation as resolved.
Show resolved Hide resolved

const autocompleteProviders = new Map();
export class AutocompleteProviderRegister {
private readonly registeredProviders: Map<string, AutocompleteProvider> = new Map();

export function addAutocompleteProvider(language, provider) {
autocompleteProviders.set(language, provider);
}
public addProvider(language: string, provider: AutocompleteProvider): void {
lizozom marked this conversation as resolved.
Show resolved Hide resolved
if (language && provider) {
this.registeredProviders.set(language, provider);
}
}

public getProvider(language: string): AutocompleteProvider | undefined {
return this.registeredProviders.get(language);
}

export function getAutocompleteProvider(language) {
return autocompleteProviders.get(language);
public clearProviders(): void {
lizozom marked this conversation as resolved.
Show resolved Hide resolved
this.registeredProviders.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* under the License.
*/

/**
* WARNING: these typings are incomplete
*/
import { StaticIndexPattern } from 'ui/index_patterns';

/** @public **/
export type AutocompleteProvider = (args: {
config: {
get(configKey: string): any;
Expand All @@ -30,27 +28,26 @@ export type AutocompleteProvider = (args: {
boolFilter?: any;
}) => GetSuggestions;

/** @public **/
export type GetSuggestions = (args: {
query: string;
selectionStart: number;
selectionEnd: number;
}) => Promise<AutocompleteSuggestion[]>;

/** @public **/
export type AutocompleteSuggestionType =
| 'field'
| 'value'
| 'operator'
| 'conjunction'
| 'recentSearch';

/** @public **/
export interface AutocompleteSuggestion {
description?: string;
end: number;
start: number;
text: string;
type: AutocompleteSuggestionType;
}

export function addAutocompleteProvider(language: string, provider: AutocompleteProvider): void;

export function getAutocompleteProvider(language: string): AutocompleteProvider | undefined;
6 changes: 4 additions & 2 deletions src/plugins/data/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

export * from './timefilter/types';
export * from './query/types';
export * from './query';
export * from './field_formats';
export * from './autocomplete_provider';

export * from './types';
5 changes: 4 additions & 1 deletion src/plugins/data/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
* under the License.
*/

export * from '.';
export * from './autocomplete_provider/types';
export * from './field_formats/types';
export * from './timefilter/types';
export * from './query/types';
13 changes: 11 additions & 2 deletions src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Plugin } from '.';
import { AutocompleteProviderRegister, Plugin } from '.';

export type Setup = jest.Mocked<ReturnType<Plugin['setup']>>;
export type Start = jest.Mocked<ReturnType<Plugin['start']>>;

const autocompleteMock: any = {
addProvider: jest.fn(),
getProvider: jest.fn(),
clearProviders: jest.fn(),
};

const createSetupContract = (): Setup => {
const setupContract: Setup = {};
const setupContract: Setup = {
autocomplete: autocompleteMock as AutocompleteProviderRegister,
};

return setupContract;
};

Expand Down
12 changes: 10 additions & 2 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@
*/

import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { AutocompleteProviderRegister } from '../common/autocomplete_provider';

export class DataPublicPlugin implements Plugin<{}> {
private readonly autocomplete = new AutocompleteProviderRegister();

constructor(initializerContext: PluginInitializerContext) {}

public setup(core: CoreSetup) {
return {};
return {
autocomplete: this.autocomplete,
};
}

public start(core: CoreStart) {}
alexwizp marked this conversation as resolved.
Show resolved Hide resolved
public stop() {}

public stop() {
this.autocomplete.clearProviders();
}
}
4 changes: 2 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { indexManagement } from './legacy/plugins/index_management';
import { indexLifecycleManagement } from './legacy/plugins/index_lifecycle_management';
import { consoleExtensions } from './legacy/plugins/console_extensions';
import { spaces } from './legacy/plugins/spaces';
import { kueryAutocomplete } from './legacy/plugins/kuery_autocomplete';
import { kueryAutocompleteInitializer } from './legacy/plugins/kuery_autocomplete';
import { canvas } from './legacy/plugins/canvas';
import { infra } from './legacy/plugins/infra';
import { taskManager } from './legacy/plugins/task_manager';
Expand Down Expand Up @@ -72,7 +72,7 @@ module.exports = function (kibana) {
indexManagement(kibana),
consoleExtensions(kibana),
indexLifecycleManagement(kibana),
kueryAutocomplete(kibana),
kueryAutocompleteInitializer(kibana),
infra(kibana),
taskManager(kibana),
rollup(kibana),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { EuiCallOut } from '@elastic/eui';
import styled from 'styled-components';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import {
AutocompleteSuggestion,
getAutocompleteProvider
} from 'ui/autocomplete_providers';
import { npSetup } from 'ui/new_platform';
import { StaticIndexPattern, getFromSavedObject } from 'ui/index_patterns';
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { fromQuery, toQuery } from '../Links/url_helpers';
Expand All @@ -29,11 +26,15 @@ import { useMatchedRoutes } from '../../../hooks/useMatchedRoutes';
import { RouteName } from '../../app/Main/route_config/route_names';
import { useKibanaCore } from '../../../../../observability/public';
import { getAPMIndexPattern } from '../../../services/rest/savedObjects';
import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public';

const Container = styled.div`
margin-bottom: 10px;
`;

const getAutocompleteProvider = (language: string) =>
npSetup.plugins.data.autocomplete.getProvider(language);

interface State {
indexPattern: StaticIndexPattern | null;
suggestions: AutocompleteSuggestion[];
Expand Down
1 change: 0 additions & 1 deletion x-pack/legacy/plugins/apm/public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'ui/autoload/styles';
import chrome from 'ui/chrome';
// @ts-ignore
import { uiModules } from 'ui/modules';
import 'uiExports/autocompleteProviders';
import { GlobalHelpExtension } from './components/app/GlobalHelpExtension';
import { plugin } from './new-platform';
import { REACT_APP_ROOT_ID } from './new-platform/plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
import React from 'react';
import styled from 'styled-components';

// @ts-ignore
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public';

import { composeStateUpdaters } from '../../utils/typed_react';
import { SuggestionItem } from './suggestion_item';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { EuiIcon } from '@elastic/eui';
import { tint } from 'polished';
import React from 'react';
import styled from 'styled-components';
// @ts-ignore
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';

import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public';

interface SuggestionItemProps {
isSelected?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EuiBasicTable, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eu
import { i18n } from '@kbn/i18n';
import React from 'react';
import styled from 'styled-components';
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public';
import { TABLE_CONFIG } from '../../../common/constants';
import { AutocompleteField } from '../autocomplete_field/index';
import { ControlSchema } from './action_schema';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';

import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../src/plugins/data/public';

import { FrontendLibs } from '../lib/types';
import { RendererFunction } from '../utils/typed_react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public';

export interface ElasticsearchAdapter {
convertKueryToEsQuery: (kuery: string) => Promise<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public';
import { ElasticsearchAdapter } from './adapter_types';

export class MemoryElasticsearchAdapter implements ElasticsearchAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { isEmpty } from 'lodash';
import { AutocompleteSuggestion, getAutocompleteProvider } from 'ui/autocomplete_providers';
import { npSetup } from 'ui/new_platform';
import { RestAPIAdapter } from '../rest_api/adapter_types';
import { ElasticsearchAdapter } from './adapter_types';
import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public';

const getAutocompleteProvider = (language: string) =>
npSetup.plugins.data.autocomplete.getProvider(language);

export class RestElasticsearchAdapter implements ElasticsearchAdapter {
private cachedIndexPattern: any = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { AutocompleteSuggestion } from 'ui/autocomplete_providers';
import 'ui/autoload/all';
// @ts-ignore: path dynamic for kibana
import { management } from 'ui/management';
Expand All @@ -26,6 +24,7 @@ import { TagsLib } from '../tags';
import { FrontendLibs } from '../types';
import { MemoryElasticsearchAdapter } from './../adapters/elasticsearch/memory';
import { ElasticsearchLib } from './../elasticsearch';
import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public';

const onKibanaReady = uiModules.get('kibana').run;

Expand Down
Loading