Skip to content

Commit

Permalink
kuery_autocomplete -> convert remaining items to TS/Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Jan 30, 2020
1 parent 3e2e783 commit c0a582d
Show file tree
Hide file tree
Showing 31 changed files with 786 additions and 559 deletions.
2 changes: 2 additions & 0 deletions src/plugins/data/common/es_query/kuery/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface KueryParseOptions {
startRule: string;
allowLeadingWildcards: boolean;
errorOnLuceneSyntax: boolean;
cursorSymbol?: string;
parseCursor?: boolean;
}

export { nodeTypes } from './node_types';
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/data/public/autocomplete/autocomplete_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ export class AutocompleteService {
this.querySuggestionProviders.clear();
}
}

/** @public **/
export type AutocompleteSetup = ReturnType<AutocompleteService['setup']>;

/** @public **/
export type AutocompleteStart = ReturnType<AutocompleteService['start']>;
5 changes: 3 additions & 2 deletions src/plugins/data/public/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import * as autocomplete from './static';
export { AutocompleteService, AutocompleteSetup, AutocompleteStart } from './autocomplete_service';

export { AutocompleteService } from './autocomplete_service';
export { QuerySuggestion, QuerySuggestionType, QuerySuggestionsGetFn } from './types';
export { autocomplete };
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@

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

export type QuerySuggestionType = 'field' | 'value' | 'operator' | 'conjunction' | 'recentSearch';
export enum QuerySuggestionsTypes {
field = 'field',
value = 'value',
operator = 'operator',
conjunction = 'conjunction',
recentSearch = 'recentSearch',
}

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

interface QuerySuggestionsGetFnArgs {
/** @public **/
export interface QuerySuggestionsGetFnArgs {
language: string;
indexPatterns: IIndexPattern[];
query: string;
Expand All @@ -35,22 +42,21 @@ interface QuerySuggestionsGetFnArgs {
boolFilter?: any;
}

interface BasicQuerySuggestion {
type: QuerySuggestionType;
description?: string;
/** @public **/
export interface BasicQuerySuggestion {
type: QuerySuggestionsTypes;
description?: string | JSX.Element;
end: number;
start: number;
text: string;
cursorIndex?: number;
}

interface FieldQuerySuggestion extends BasicQuerySuggestion {
type: 'field';
/** @public **/
export interface FieldQuerySuggestion extends BasicQuerySuggestion {
type: QuerySuggestionsTypes.field;
field: IFieldType;
}

// A union type allows us to do easy type guards in the code. For example, if I want to ensure I'm
// working with a FieldAutocompleteSuggestion, I can just do `if ('field' in suggestion)` and the
// TypeScript compiler will narrow the type to the parts of the union that have a field prop.
/** @public **/
export type QuerySuggestion = BasicQuerySuggestion | FieldQuerySuggestion;
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@
* under the License.
*/

import { AutocompleteService } from './autocomplete_service';

/** @public **/
export type AutocompleteSetup = ReturnType<AutocompleteService['setup']>;

/** @public **/
export type AutocompleteStart = ReturnType<AutocompleteService['start']>;

/** @public **/
export {
QuerySuggestion,
QuerySuggestionsTypes,
QuerySuggestionsGetFn,
QuerySuggestionType,
QuerySuggestionsGetFnArgs,
BasicQuerySuggestion,
FieldQuerySuggestion,
} from './providers/query_suggestion_provider';
5 changes: 1 addition & 4 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { PluginInitializerContext } from '../../../core/public';
import * as autocomplete from './autocomplete';

export function plugin(initializerContext: PluginInitializerContext) {
return new DataPublicPlugin(initializerContext);
Expand All @@ -44,7 +43,7 @@ export {
RefreshInterval,
TimeRange,
} from '../common';

export { autocomplete } from './autocomplete';
export * from './field_formats';
export * from './index_patterns';
export * from './search';
Expand All @@ -70,5 +69,3 @@ export {
// Export plugin after all other imports
import { DataPublicPlugin } from './plugin';
export { DataPublicPlugin as Plugin };

export { autocomplete };
2 changes: 1 addition & 1 deletion src/plugins/data/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 { AutocompleteSetup, AutocompleteStart } from './autocomplete/types';
import { AutocompleteSetup, AutocompleteStart } from './autocomplete';
import { FieldFormatsSetup, FieldFormatsStart } from './field_formats';
import { ISearchSetup, ISearchStart } from './search';
import { QuerySetup, QueryStart } from './query';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ const KEY_CODES = {
END: 35,
};

const recentSearchType: autocomplete.QuerySuggestionType = 'recentSearch';

export class QueryStringInputUI extends Component<Props, State> {
public state: State = {
isSuggestionsVisible: false,
Expand Down Expand Up @@ -193,7 +191,7 @@ export class QueryStringInputUI extends Component<Props, State> {
const text = toUser(recentSearch);
const start = 0;
const end = query.length;
return { type: recentSearchType, text, start, end };
return { type: autocomplete.QuerySuggestionsTypes.recentSearch, text, start, end };
});
};

Expand Down Expand Up @@ -343,7 +341,7 @@ export class QueryStringInputUI extends Component<Props, State> {
selectionEnd: start + (cursorIndex ? cursorIndex : text.length),
});

if (type === recentSearchType) {
if (type === autocomplete.QuerySuggestionsTypes.recentSearch) {
this.setState({ isSuggestionsVisible: false, index: null });
this.onSubmit({ query: newQueryString, language: this.props.query.language });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const mockSuggestion: autocomplete.QuerySuggestion = {
end: 0,
start: 42,
text: 'as promised, not helpful',
type: 'value',
type: autocomplete.QuerySuggestionsTypes.value,
};

describe('SuggestionComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const mockSuggestions: autocomplete.QuerySuggestion[] = [
end: 0,
start: 42,
text: 'as promised, not helpful',
type: 'value',
type: autocomplete.QuerySuggestionsTypes.value,
},
{
description: 'This is another unhelpful suggestion',
end: 0,
start: 42,
text: 'yep',
type: 'field',
type: autocomplete.QuerySuggestionsTypes.field,
},
];

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit c0a582d

Please sign in to comment.