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 ui/value_suggestions ⇒ NP data plugin #45762

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e22d673
Bind search bar
Sep 25, 2019
0c7eebf
create prewired data components
Sep 25, 2019
41dd2ef
Pass NP data plugin to shim plugin, to access autocomplete
Sep 26, 2019
c4525e9
Use KibanaContextProvider in vis editor and graph
Sep 26, 2019
995bfeb
Use KibanaContextProvider in maps
Sep 26, 2019
1d09108
Use prewirted SearchBar in TopNavMenu
Sep 26, 2019
08fed2f
Use KibanaContextProbider in Lens
Sep 26, 2019
b4ce1f2
Fix appName usage in query bar input
Sep 26, 2019
7e2740c
fixed query bar top row appName
Sep 26, 2019
35d365e
update tests
Sep 26, 2019
4dd148d
fixed bind search bar bug
Sep 26, 2019
4913548
mock SearchBar
Sep 26, 2019
c836679
Removed unnecessary mocks
Sep 26, 2019
65b592e
Delete unused mock
Sep 26, 2019
8dbf164
Fixed exporting of data plugin types
Sep 26, 2019
b4a80f6
Merge remote-tracking branch 'upstream/master' into newplatform/data-…
Sep 26, 2019
1f84606
Updated maps snapshot
Sep 26, 2019
0f60094
Fixed some TS issues
Sep 26, 2019
b7935cd
Merge remote-tracking branch 'upstream/master' into newplatform/data-…
Sep 29, 2019
64b9ec6
Fixed jest tests
Sep 29, 2019
1fe975c
Context adjustments in TSVB
Sep 29, 2019
23ae2e7
componentWillMount
Sep 29, 2019
2eb5425
Merge remote-tracking branch 'upstream/master' into newplatform/data-…
Oct 2, 2019
0ca40af
Code review fixes
Oct 2, 2019
eaac39c
Pass dataTestSubj to query bar input
Oct 2, 2019
cc39f89
Graph data
Oct 2, 2019
89b72c7
- Pass NP data plugin to KibanaReactContext
Oct 2, 2019
b225dc5
- Pass NP data plugin to KibanaReactContext
Oct 2, 2019
d08b938
ts fixes
Oct 2, 2019
fff2186
Added karma getSuggestions fake
Oct 2, 2019
64f4566
Refactored kuery autocomplete tests to jest
Oct 3, 2019
99f67ae
Merge remote-tracking branch 'upstream/master' into newplatform/data-…
Oct 3, 2019
a992310
Filter bar context for directives
Oct 3, 2019
03cd33c
updated snapshot
Oct 3, 2019
dad955f
Merge remote-tracking branch 'upstream/master' into newplatform/data-…
Oct 3, 2019
6fe474c
Merge remote-tracking branch 'upstream/master' into newplatform/data-…
Oct 6, 2019
c719a2b
Merge remote-tracking branch 'upstream/master' into newplatform/data-…
Oct 6, 2019
f226ffa
Merge branch 'newplatform/data-plugin/value-suggesions' of github.com…
Oct 6, 2019
d7e3cd4
fix diffs
Oct 6, 2019
0d983f5
fixed lens test
Oct 6, 2019
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 @@ -120,7 +120,6 @@ function FilterBarUI(props: Props) {
onSubmit={onAdd}
onCancel={() => setIsAddFilterPopoverOpen(false)}
key={JSON.stringify(newFilter)}
uiSettings={uiSettings!}
/>
</div>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { get } from 'lodash';
import React, { Component } from 'react';
import { UiSettingsClientContract } from 'src/core/public';
import { Field, IndexPattern } from '../../../index_patterns';
import { GenericComboBox, GenericComboBoxProps } from './generic_combo_box';
import {
Expand All @@ -62,7 +61,6 @@ interface Props {
onSubmit: (filter: Filter) => void;
onCancel: () => void;
intl: InjectedIntl;
uiSettings: UiSettingsClientContract;
}

interface State {
Expand Down Expand Up @@ -343,7 +341,6 @@ class FilterEditorUI extends Component<Props, State> {
value={this.state.params}
onChange={this.onParamsChange}
data-test-subj="phraseValueInput"
uiSettings={this.props.uiSettings}
/>
);
case 'phrases':
Expand All @@ -353,7 +350,6 @@ class FilterEditorUI extends Component<Props, State> {
field={this.state.selectedField}
values={this.state.params}
onChange={this.onParamsChange}
uiSettings={this.props.uiSettings}
/>
);
case 'range':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
*/

import { Component } from 'react';
import { getSuggestions } from 'ui/value_suggestions';
import { UiSettingsClientContract } from 'src/core/public';
import { Field, IndexPattern } from '../../../index_patterns';
import {
withKibana,
KibanaReactContextValue,
} from '../../../../../../../plugins/kibana_react/public';
import { IDataPluginServices } from '../../../types';

export interface PhraseSuggestorProps {
kibana: KibanaReactContextValue<IDataPluginServices>;
indexPattern: IndexPattern;
field?: Field;
uiSettings: UiSettingsClientContract;
}

export interface PhraseSuggestorState {
Expand All @@ -38,10 +41,11 @@ export interface PhraseSuggestorState {
* aggregatable), we pull out the common logic for requesting suggestions into this component
* which both of them extend.
*/
export class PhraseSuggestor<T extends PhraseSuggestorProps> extends Component<
export class PhraseSuggestorUI<T extends PhraseSuggestorProps> extends Component<
T,
PhraseSuggestorState
> {
private services = this.props.kibana.services;
public state: PhraseSuggestorState = {
suggestions: [],
isLoading: false,
Expand All @@ -52,7 +56,7 @@ export class PhraseSuggestor<T extends PhraseSuggestorProps> extends Component<
}

protected isSuggestingValues() {
const shouldSuggestValues = this.props.uiSettings.get('filterEditor:suggestValues');
const shouldSuggestValues = this.services.uiSettings.get('filterEditor:suggestValues');
const { field } = this.props;
return shouldSuggestValues && field && field.aggregatable && field.type === 'string';
}
Expand All @@ -67,7 +71,9 @@ export class PhraseSuggestor<T extends PhraseSuggestorProps> extends Component<
return;
}
this.setState({ isLoading: true });
const suggestions = await getSuggestions(indexPattern.title, field, value);
const suggestions = await this.services.data.getSuggestions(indexPattern.title, field, value);
this.setState({ suggestions, isLoading: false });
}
}

export const PhraseSuggestor = withKibana(PhraseSuggestorUI);
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { uniq } from 'lodash';
import React from 'react';
import { GenericComboBox, GenericComboBoxProps } from './generic_combo_box';
import { PhraseSuggestor, PhraseSuggestorProps } from './phrase_suggestor';
import { PhraseSuggestorUI, PhraseSuggestorProps } from './phrase_suggestor';
import { ValueInputType } from './value_input_type';
import { withKibana } from '../../../../../../../plugins/kibana_react/public';

interface Props extends PhraseSuggestorProps {
value?: string;
onChange: (value: string | number | boolean) => void;
intl: InjectedIntl;
}

class PhraseValueInputUI extends PhraseSuggestor<Props> {
class PhraseValueInputUI extends PhraseSuggestorUI<Props> {
public render() {
return (
<EuiFormRow
Expand Down Expand Up @@ -87,4 +88,4 @@ function StringComboBox(props: GenericComboBoxProps<string>) {
return GenericComboBox(props);
}

export const PhraseValueInput = injectI18n(PhraseValueInputUI);
export const PhraseValueInput = injectI18n(withKibana(PhraseValueInputUI));
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { uniq } from 'lodash';
import React from 'react';
import { GenericComboBox, GenericComboBoxProps } from './generic_combo_box';
import { PhraseSuggestor, PhraseSuggestorProps } from './phrase_suggestor';
import { PhraseSuggestorUI, PhraseSuggestorProps } from './phrase_suggestor';
import { withKibana } from '../../../../../../../plugins/kibana_react/public';

interface Props extends PhraseSuggestorProps {
values?: string[];
onChange: (values: string[]) => void;
intl: InjectedIntl;
}

class PhrasesValuesInputUI extends PhraseSuggestor<Props> {
class PhrasesValuesInputUI extends PhraseSuggestorUI<Props> {
public render() {
const { suggestions } = this.state;
const { values, intl, onChange } = this.props;
Expand Down Expand Up @@ -64,4 +65,4 @@ function StringComboBox(props: GenericComboBoxProps<string>) {
return GenericComboBox(props);
}

export const PhrasesValuesInput = injectI18n(PhrasesValuesInputUI);
export const PhrasesValuesInput = injectI18n(withKibana(PhrasesValuesInputUI));
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class FilterItemUI extends Component<Props, State> {
indexPatterns={this.props.indexPatterns}
onSubmit={this.onSubmit}
onCancel={this.closePopover}
uiSettings={this.props.uiSettings}
/>
</div>
),
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ export class DataPlugin
public start(core: CoreStart, { __LEGACY, data }: DataPluginStartDependencies) {
const SearchBar = createSearchBar({
core,
data,
store: __LEGACY.storage,
timefilter: this.setupApi.timefilter,
filterManager: this.setupApi.filter.filterManager,
autocomplete: data.autocomplete,
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class QueryBarInputUI extends Component<Props, State> {

const recentSearchSuggestions = this.getRecentSearchSuggestions(queryString);

const autocompleteProvider = this.services.autocomplete.getProvider(language);
const autocompleteProvider = this.services.data.autocomplete.getProvider(language);
if (
!autocompleteProvider ||
!Array.isArray(this.state.indexPatterns) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ import React from 'react';
import { Filter } from '@kbn/es-query';
import { CoreStart } from 'src/core/public';
import { Storage } from 'ui/storage';
import { AutocompletePublicPluginStart } from 'src/plugins/data/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public';
import { TimefilterSetup } from '../../../timefilter';
import { FilterManager, SearchBar } from '../../../';
import { SearchBarOwnProps } from '.';

interface StatefulSearchBarDeps {
core: CoreStart;
data: DataPublicPluginStart;
store: Storage;
timefilter: TimefilterSetup;
filterManager: FilterManager;
autocomplete: AutocompletePublicPluginStart;
}

export type StatetfulSearchBarProps = SearchBarOwnProps & {
Expand All @@ -59,7 +59,7 @@ export function createSearchBar({
store,
timefilter,
filterManager,
autocomplete,
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.
Expand All @@ -71,7 +71,7 @@ export function createSearchBar({
<KibanaContextProvider
services={{
appName: props.appName,
autocomplete,
data,
store,
...core,
}}
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/data/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { UiSettingsClientContract, CoreStart } from 'src/core/public';
import { AutocompletePublicPluginStart } from 'src/plugins/data/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';

export interface IDataPluginServices extends Partial<CoreStart> {
appName: string;
Expand All @@ -27,5 +27,5 @@ export interface IDataPluginServices extends Partial<CoreStart> {
notifications: CoreStart['notifications'];
http: CoreStart['http'];
store: Storage;
autocomplete: AutocompletePublicPluginStart;
data: DataPublicPluginStart;
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class VisEditor extends Component {
services={{
appName: APP_NAME,
store: localStorage,
autocomplete: npStart.plugins.data.autocomplete,
data: npStart.plugins.data,
...npStart.core,
}}
>
Expand Down
4 changes: 3 additions & 1 deletion src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export const npStart = {
registerRenderer: sinon.fake(),
registerType: sinon.fake(),
},
data: {},
data: {
getSuggestions: sinon.fake(),
},
inspector: {
isAvailable: () => false,
open: () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function FilterRow({
services={{
appName: 'filtersAgg',
store: localStorage,
autocomplete: npStart.plugins.data.autocomplete,
data: npStart.plugins.data,
...npStart.core,
}}
>
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const createSetupContract = (): Setup => {
const createStartContract = (): Start => {
const startContract: Start = {
autocomplete: autocompleteMock as Start['autocomplete'],
getSuggestions: jest.fn(),
};
return startContract;
};
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { AutocompleteProviderRegister } from './autocomplete_provider';
import { DataPublicPluginSetup, DataPublicPluginStart } from './types';
import { getSuggestionsProvider } from './suggestions_provider';

export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPublicPluginStart> {
private readonly autocomplete = new AutocompleteProviderRegister();
Expand All @@ -35,6 +36,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
public start(core: CoreStart): DataPublicPluginStart {
return {
autocomplete: this.autocomplete,
getSuggestions: getSuggestionsProvider(core.uiSettings, core.http),
Comment on lines 38 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In data plugin we have this services pattern where each service is returned from life-cycles, here autocomplete and getSuggestions are some utilities. Should we collect them into a service, say suggestions?

Copy link
Contributor Author

@lizozom lizozom Oct 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought of placing it inside the autocomplete service.
I just wasn't sure and didn't want to create unnecessary code while not sure.
Until we have a good hunch, I think the services pattern is great for more complex things, than a single function.

};
}

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

import chrome from 'ui/chrome';
import { kfetch } from 'ui/kfetch';
import { getSuggestionsProvider } from './value_suggestions';

export const getSuggestions = getSuggestionsProvider(chrome.getUiSettingsClient(), kfetch);
export { getSuggestionsProvider } from './value_suggestions';
23 changes: 23 additions & 0 deletions src/plugins/data/public/suggestions_provider/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

// Should be import { Field } from './index_patterns';
export type Field = any;

export type IGetSuggestions = (index: string, field: Field, query: string, boolFilter?: any) => any;
Loading