Skip to content

Commit

Permalink
language switches and sets the query correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Aug 25, 2024
1 parent 2323d10 commit 910db55
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ export const getDQLLanguageConfig = (search: ISearchInterceptor): LanguageConfig
id: 'kuery',
title: 'DQL',
search,
getQueryString(_) {
return '';
},
searchBar: {
showDataSetsSelector: true,
showDataSourcesSelector: false,
showQueryInput: true,
showFilterBar: true,
showDatePicker: true,
showAutoRefreshOnly: false,
queryStringInput: {
initialValue: '',
},
},
fields: {
filterable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ export const getLuceneLanguageConfig = (search: ISearchInterceptor): LanguageCon
id: 'lucene',
title: 'Lucene',
search,
getQueryString(_) {
return '';
},
searchBar: {
showDataSetsSelector: true,
showDataSourcesSelector: false,
showQueryInput: true,
showFilterBar: true,
showDatePicker: true,
showAutoRefreshOnly: false,
queryStringInput: {
initialValue: '',
},
},
fields: {
filterable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
*/

import { ISearchInterceptor } from '../../../search';
import { Query } from '../../../../public';

export interface LanguageConfig {
id: string;
title: string;
search: ISearchInterceptor;
// Leave blank to support all data sources
// supportedDataSourceTypes?: Record<string, GenericDataSource>;
getQueryString: (query: Query) => string;
searchBar?: {
showDataSetsSelector?: boolean;
showDataSourcesSelector?: boolean;
showQueryInput?: boolean;
showFilterBar?: boolean;
showDatePicker?: boolean;
showAutoRefreshOnly?: boolean;
queryStringInput?: {
// will replace '<data_source>' with the data source name
initialValue?: string;
};
dateRange?: {
initialFrom?: string;
initialTo?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ export class QueryStringManager {
const curQuery = this.query$.getValue();
const language = this.languageService.getLanguage(languageId);
const dataset = curQuery.dataset;
const input = language?.searchBar?.queryStringInput?.initialValue || '';
const input = language?.getQueryString(curQuery) || '';

return {
query: input || input.replace('<data_source>', dataset?.title ?? ''),
query: input,
language: languageId,
dataset: curQuery.dataset,
dataset,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
prettyDuration,
} from '@elastic/eui';
import classNames from 'classnames';
import { isEqual } from 'lodash';
import React, { useState } from 'react';
import { createPortal } from 'react-dom';
import { IDataPluginServices, IIndexPattern, Query, TimeHistoryContract, TimeRange } from '../..';
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/query_enhancements/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
QueryEnhancementsPluginStart,
QueryEnhancementsPluginStartDependencies,
} from './types';
import { LanguageConfig } from '../../data/public';
import { LanguageConfig, Query } from '../../data/public';
import { s3TypeConfig } from './datasets';

export class QueryEnhancementsPlugin
Expand Down Expand Up @@ -61,15 +61,15 @@ export class QueryEnhancementsPlugin
id: 'PPL',
title: 'PPL',
search: pplSearchInterceptor,
getQueryString: (query: Query) => {
return `source = ${query.dataset?.title}`;
},
searchBar: {
queryStringInput: { initialValue: 'source=<data_source>' },
dateRange: {
initialFrom: moment().subtract(2, 'days').toISOString(),
initialTo: moment().add(2, 'days').toISOString(),
},
showFilterBar: false,
showDataSetsSelector: true,
showDataSourcesSelector: true,
},
fields: {
filterable: false,
Expand All @@ -85,12 +85,12 @@ export class QueryEnhancementsPlugin
id: 'SQL',
title: 'SQL',
search: sqlSearchInterceptor,
getQueryString: (query: Query) => {
return `SELECT * FROM ${queryString.getQuery().dataset?.title} LIMIT 10`;
},
searchBar: {
showDatePicker: false,
showFilterBar: false,
showDataSetsSelector: true,
showDataSourcesSelector: true,
queryStringInput: { initialValue: 'SELECT * FROM <data_source> LIMIT 10' },
},
fields: {
filterable: false,
Expand Down

0 comments on commit 910db55

Please sign in to comment.