Skip to content

Commit

Permalink
Merge branch 'master' into remove-canvas-injected-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Feb 10, 2020
2 parents bf123ba + 18a76c0 commit 803a844
Show file tree
Hide file tree
Showing 43 changed files with 171 additions and 162 deletions.
11 changes: 4 additions & 7 deletions src/plugins/data/public/autocomplete/autocomplete_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@
*/

import { CoreSetup } from 'src/core/public';
import { QuerySuggestionsGetFn } from './providers/query_suggestion_provider';
import { QuerySuggestionGetFn } from './providers/query_suggestion_provider';
import {
setupValueSuggestionProvider,
ValueSuggestionsGetFn,
} from './providers/value_suggestion_provider';

export class AutocompleteService {
private readonly querySuggestionProviders: Map<string, QuerySuggestionsGetFn> = new Map();
private readonly querySuggestionProviders: Map<string, QuerySuggestionGetFn> = new Map();
private getValueSuggestions?: ValueSuggestionsGetFn;

private addQuerySuggestionProvider = (
language: string,
provider: QuerySuggestionsGetFn
): void => {
private addQuerySuggestionProvider = (language: string, provider: QuerySuggestionGetFn): void => {
if (language && provider) {
this.querySuggestionProviders.set(language, provider);
}
};

private getQuerySuggestions: QuerySuggestionsGetFn = args => {
private getQuerySuggestions: QuerySuggestionGetFn = args => {
const { language } = args;
const provider = this.querySuggestionProviders.get(language);

Expand Down
13 changes: 10 additions & 3 deletions src/plugins/data/public/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
import * as autocomplete from './static';
export { AutocompleteService, AutocompleteSetup, AutocompleteStart } from './autocomplete_service';

export { autocomplete };
export {
QuerySuggestion,
QuerySuggestionTypes,
QuerySuggestionGetFn,
QuerySuggestionGetFnArgs,
QuerySuggestionBasic,
QuerySuggestionField,
} from './providers/query_suggestion_provider';

export { AutocompleteService, AutocompleteSetup, AutocompleteStart } from './autocomplete_service';
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

import { IFieldType, IIndexPattern } from '../../../common/index_patterns';

export enum QuerySuggestionsTypes {
export enum QuerySuggestionTypes {
Field = 'field',
Value = 'value',
Operator = 'operator',
Conjunction = 'conjunction',
RecentSearch = 'recentSearch',
}

export type QuerySuggestionsGetFn = (
args: QuerySuggestionsGetFnArgs
export type QuerySuggestionGetFn = (
args: QuerySuggestionGetFnArgs
) => Promise<QuerySuggestion[]> | undefined;

/** @public **/
export interface QuerySuggestionsGetFnArgs {
export interface QuerySuggestionGetFnArgs {
language: string;
indexPatterns: IIndexPattern[];
query: string;
Expand All @@ -43,8 +43,8 @@ export interface QuerySuggestionsGetFnArgs {
}

/** @public **/
export interface BasicQuerySuggestion {
type: QuerySuggestionsTypes;
export interface QuerySuggestionBasic {
type: QuerySuggestionTypes;
description?: string | JSX.Element;
end: number;
start: number;
Expand All @@ -53,10 +53,10 @@ export interface BasicQuerySuggestion {
}

/** @public **/
export interface FieldQuerySuggestion extends BasicQuerySuggestion {
type: QuerySuggestionsTypes.Field;
export interface QuerySuggestionField extends QuerySuggestionBasic {
type: QuerySuggestionTypes.Field;
field: IFieldType;
}

/** @public **/
export type QuerySuggestion = BasicQuerySuggestion | FieldQuerySuggestion;
export type QuerySuggestion = QuerySuggestionBasic | QuerySuggestionField;
27 changes: 0 additions & 27 deletions src/plugins/data/public/autocomplete/static.ts

This file was deleted.

12 changes: 11 additions & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ export {
FieldFormatConfig,
FieldFormatId,
} from '../common';
export { autocomplete } from './autocomplete';

export {
QuerySuggestion,
QuerySuggestionTypes,
QuerySuggestionGetFn,
QuerySuggestionGetFnArgs,
QuerySuggestionBasic,
QuerySuggestionField,
} from './autocomplete';

export * from './field_formats';
export * from './index_patterns';
export * from './search';
export * from './query';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { InjectedIntl, injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { debounce, compact, isEqual } from 'lodash';
import { Toast } from 'src/core/public';
import {
autocomplete,
IDataPluginServices,
IIndexPattern,
PersistedLog,
Expand All @@ -46,6 +45,8 @@ import {
getQueryLog,
Query,
} from '../..';
import { QuerySuggestion, QuerySuggestionTypes } from '../../autocomplete';

import { withKibana, KibanaReactContextValue, toMountPoint } from '../../../../kibana_react/public';
import { fetchIndexPatterns } from './fetch_index_patterns';
import { QueryLanguageSwitcher } from './language_switcher';
Expand All @@ -70,7 +71,7 @@ interface Props {
interface State {
isSuggestionsVisible: boolean;
index: number | null;
suggestions: autocomplete.QuerySuggestion[];
suggestions: QuerySuggestion[];
suggestionLimit: number;
selectionStart: number | null;
selectionEnd: number | null;
Expand Down Expand Up @@ -191,7 +192,7 @@ export class QueryStringInputUI extends Component<Props, State> {
const text = toUser(recentSearch);
const start = 0;
const end = query.length;
return { type: autocomplete.QuerySuggestionsTypes.RecentSearch, text, start, end };
return { type: QuerySuggestionTypes.RecentSearch, text, start, end };
});
};

Expand Down Expand Up @@ -317,7 +318,7 @@ export class QueryStringInputUI extends Component<Props, State> {
}
};

private selectSuggestion = (suggestion: autocomplete.QuerySuggestion) => {
private selectSuggestion = (suggestion: QuerySuggestion) => {
if (!this.inputRef) {
return;
}
Expand All @@ -341,13 +342,13 @@ export class QueryStringInputUI extends Component<Props, State> {
selectionEnd: start + (cursorIndex ? cursorIndex : text.length),
});

if (type === autocomplete.QuerySuggestionsTypes.RecentSearch) {
if (type === QuerySuggestionTypes.RecentSearch) {
this.setState({ isSuggestionsVisible: false, index: null });
this.onSubmit({ query: newQueryString, language: this.props.query.language });
}
};

private handleNestedFieldSyntaxNotification = (suggestion: autocomplete.QuerySuggestion) => {
private handleNestedFieldSyntaxNotification = (suggestion: QuerySuggestion) => {
if (
'field' in suggestion &&
suggestion.field.subType &&
Expand Down Expand Up @@ -449,7 +450,7 @@ export class QueryStringInputUI extends Component<Props, State> {
}
};

private onClickSuggestion = (suggestion: autocomplete.QuerySuggestion) => {
private onClickSuggestion = (suggestion: QuerySuggestion) => {
if (!this.inputRef) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@

import { mount, shallow } from 'enzyme';
import React from 'react';
import { autocomplete } from '../..';
import { QuerySuggestion, QuerySuggestionTypes } from '../../autocomplete';
import { SuggestionComponent } from './suggestion_component';

const noop = () => {
return;
};

const mockSuggestion: autocomplete.QuerySuggestion = {
const mockSuggestion: QuerySuggestion = {
description: 'This is not a helpful suggestion',
end: 0,
start: 42,
text: 'as promised, not helpful',
type: autocomplete.QuerySuggestionsTypes.Value,
type: QuerySuggestionTypes.Value,
};

describe('SuggestionComponent', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data/public/ui/typeahead/suggestion_component.tsx
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 { autocomplete } from '../..';
import { QuerySuggestion } from '../../autocomplete';

function getEuiIconType(type: string) {
switch (type) {
Expand All @@ -40,10 +40,10 @@ function getEuiIconType(type: string) {
}

interface Props {
onClick: (suggestion: autocomplete.QuerySuggestion) => void;
onClick: (suggestion: QuerySuggestion) => void;
onMouseEnter: () => void;
selected: boolean;
suggestion: autocomplete.QuerySuggestion;
suggestion: QuerySuggestion;
innerRef: (node: HTMLDivElement) => void;
ariaId: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@

import { mount, shallow } from 'enzyme';
import React from 'react';
import { autocomplete } from '../..';
import { QuerySuggestion, QuerySuggestionTypes } from '../../autocomplete';
import { SuggestionComponent } from './suggestion_component';
import { SuggestionsComponent } from './suggestions_component';

const noop = () => {
return;
};

const mockSuggestions: autocomplete.QuerySuggestion[] = [
const mockSuggestions: QuerySuggestion[] = [
{
description: 'This is not a helpful suggestion',
end: 0,
start: 42,
text: 'as promised, not helpful',
type: autocomplete.QuerySuggestionsTypes.Value,
type: QuerySuggestionTypes.Value,
},
{
description: 'This is another unhelpful suggestion',
end: 0,
start: 42,
text: 'yep',
type: autocomplete.QuerySuggestionsTypes.Field,
type: QuerySuggestionTypes.Field,
},
];

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

import { isEmpty } from 'lodash';
import React, { Component } from 'react';
import { autocomplete } from '../..';
import { QuerySuggestion } from '../..';
import { SuggestionComponent } from './suggestion_component';

interface Props {
index: number | null;
onClick: (suggestion: autocomplete.QuerySuggestion) => void;
onClick: (suggestion: QuerySuggestion) => void;
onMouseEnter: (index: number) => void;
show: boolean;
suggestions: autocomplete.QuerySuggestion[];
suggestions: QuerySuggestion[];
loadMore: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { history } from '../../../utils/history';
import { useApmPluginContext } from '../../../hooks/useApmPluginContext';
import { useDynamicIndexPattern } from '../../../hooks/useDynamicIndexPattern';
import {
autocomplete,
QuerySuggestion,
esKuery,
IIndexPattern
} from '../../../../../../../../src/plugins/data/public';
Expand All @@ -28,7 +28,7 @@ const Container = styled.div`
`;

interface State {
suggestions: autocomplete.QuerySuggestion[];
suggestions: QuerySuggestion[];
isLoadingSuggestions: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import React from 'react';
import styled from 'styled-components';

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

import { composeStateUpdaters } from '../../utils/typed_react';
import { SuggestionItem } from './suggestion_item';
Expand All @@ -25,7 +25,7 @@ interface AutocompleteFieldProps {
onSubmit?: (value: string) => void;
onChange?: (value: string) => void;
placeholder?: string;
suggestions: autocomplete.QuerySuggestion[];
suggestions: QuerySuggestion[];
value: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { tint } from 'polished';
import React from 'react';
import styled from 'styled-components';

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

interface SuggestionItemProps {
isSelected?: boolean;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
suggestion: autocomplete.QuerySuggestion;
suggestion: QuerySuggestion;
}

export const SuggestionItem: React.FC<SuggestionItemProps> = props => {
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 { autocomplete } from '../../../../../../../src/plugins/data/public';
import { QuerySuggestion } from '../../../../../../../src/plugins/data/public';
import { TABLE_CONFIG } from '../../../common/constants';
import { AutocompleteField } from '../autocomplete_field/index';
import { ControlSchema } from './action_schema';
Expand All @@ -31,7 +31,7 @@ export interface KueryBarProps {
loadSuggestions: (value: string, cursorPosition: number, maxCount?: number) => void;
onChange?: (value: string) => void;
onSubmit?: (value: string) => void;
suggestions: autocomplete.QuerySuggestion[];
suggestions: QuerySuggestion[];
value: string;
}

Expand Down
Loading

0 comments on commit 803a844

Please sign in to comment.