Skip to content

Commit

Permalink
fixing more bugs, adding no time field prop for unsupported languages
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Li <[email protected]>
  • Loading branch information
sejli committed Sep 17, 2024
1 parent 3b77d5b commit e8b244e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
DataStructure,
IndexPatternSpec,
DEFAULT_DATA,
IFieldType,
UI_SETTINGS,
DataStorage,
CachedDataStructure,
Expand Down Expand Up @@ -64,14 +63,11 @@ export class DatasetService {

public async cacheDataset(dataset: Dataset): Promise<void> {
const type = this.getType(dataset.type);
if (dataset) {
if (dataset && dataset.type !== DEFAULT_DATA.SET_TYPES.INDEX_PATTERN) {
const spec = {
id: dataset.id,
title: dataset.title,
timeFieldName: {
name: dataset.timeFieldName,
type: 'date',
} as Partial<IFieldType>,
timeFieldName: dataset.timeFieldName,
fields: await type?.fetchFields(dataset),
dataSourceRef: dataset.dataSource
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const indexTypeConfig: DatasetTypeConfig = {
return fields.map((field: any) => ({
name: field.name,
type: field.type,
aggregatable: field?.aggregatable,
}));
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ export interface LanguageConfig {
showDocLinks?: boolean;
editorSupportedAppNames?: string[];
supportedAppNames?: string[];
noTimeField?: boolean;
}
37 changes: 31 additions & 6 deletions src/plugins/data/public/ui/dataset_selector/configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export const Configurator = ({
const languages = type?.supportedLanguages(baseDataset) || [];

const [dataset, setDataset] = useState<Dataset>(baseDataset);
const [timeFields, setTimeFields] = useState<DatasetField[]>();
const [timeFields, setTimeFields] = useState<DatasetField[]>([]);
const [timeFieldName, setTimeFieldName] = useState<string | undefined>(dataset.timeFieldName);
const noTimeFilter = 'I dont want to use the time filter';
const [language, setLanguage] = useState<string>(() => {
const currentLanguage = queryString.getQuery().language;
if (languages.includes(currentLanguage)) {
Expand All @@ -51,6 +52,18 @@ export const Configurator = ({
return languages[0];
});

const requiresTimeField = (ds: Dataset, lang: string, fields: DatasetField[]) => {
if (
languageService.getLanguage(lang)?.noTimeField ||
ds.type === DEFAULT_DATA.SET_TYPES.INDEX_PATTERN
) {
return false;
}
if (fields && fields.length > 0) {
return true;
}
};

useEffect(() => {
const fetchFields = async () => {
const datasetFields = await queryString
Expand Down Expand Up @@ -97,7 +110,20 @@ export const Configurator = ({
>
<EuiFieldText disabled value={dataset.title} />
</EuiFormRow>
{timeFields && timeFields.length > 0 && (
{dataset.type === DEFAULT_DATA.SET_TYPES.INDEX_PATTERN &&
!languageService.getLanguage(language)?.noTimeField && (
<EuiFormRow
label={i18n.translate(
'data.explorer.datasetSelector.advancedSelector.configurator.datasetLabel',
{
defaultMessage: 'Time field',
}
)}
>
<EuiFieldText disabled value={dataset.timeFieldName ?? 'No time field'} />
</EuiFormRow>
)}
{requiresTimeField(dataset, language, timeFields) && (
<EuiFormRow
label={i18n.translate(
'data.explorer.datasetSelector.advancedSelector.configurator.timeFieldLabel',
Expand All @@ -113,16 +139,15 @@ export const Configurator = ({
value: field.name,
})),
{ text: '-----', value: '-----', disabled: true },
{ text: 'I dont want to use time filter', value: '' },
{ text: noTimeFilter, value: noTimeFilter },
]}
value={timeFieldName}
onChange={(e) => {
const value = e.target.value === noTimeFilter ? undefined : e.target.value;
setTimeFieldName(e.target.value);
const value = e.target.value === '' ? undefined : e.target.value;
setDataset({ ...dataset, timeFieldName: value });
}}
hasNoInitialSelection={dataset.type === DEFAULT_DATA.SET_TYPES.INDEX}
disabled={dataset.type === DEFAULT_DATA.SET_TYPES.INDEX_PATTERN}
/>
</EuiFormRow>
)}
Expand Down Expand Up @@ -167,7 +192,7 @@ export const Configurator = ({
onConfirm(dataset);
}}
fill
disabled={timeFieldName === undefined && dataset.type === DEFAULT_DATA.SET_TYPES.INDEX}
disabled={timeFieldName === undefined && requiresTimeField(dataset, language, timeFields)}
>
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.confirm"
Expand Down
1 change: 1 addition & 0 deletions src/plugins/query_enhancements/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class QueryEnhancementsPlugin
editor: enhancedSQLQueryEditor,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'data-explorer'],
noTimeField: true,
};
queryString.getLanguageService().registerLanguage(sqlLanguageConfig);

Expand Down

0 comments on commit e8b244e

Please sign in to comment.