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

[discover] data type overrides language config and if includes time filter then don't modify query #8917

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,16 @@ export interface DatasetField {

export interface DatasetSearchOptions {
strategy?: string;
/*
* Whether to include the raw time filter in the search
* defaults to false and if the dataset type supportsTimeFilter
* then the time filter will be included automatically into the query.
* If true, the time filter will be included in the search request as
* a param but leave the query unchanged.
*
* Using this will override the time filter in the query.
* Using this will disable aggregation based on the time filter automatically.
* Search strategy will need to handle the logic for that and ensure consistency.
*/
includeTimeFilter?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export interface LanguageConfig {
};
editorSupportedAppNames?: string[];
supportedAppNames?: string[];
/**
* @deprecated
*
* Use `datasetTypeConfig.supportsTimeFilter` instead
*/
hideDatePicker?: boolean;
sampleQueries?: SampleQuery[];
}
16 changes: 15 additions & 1 deletion src/plugins/data/public/ui/dataset_selector/configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@
};
}, [indexedViewsService, selectedIndexedView, dataset]);

const shouldRenderDatePickerField = useCallback(() => {
const datasetType = queryString.getDatasetService().getType(dataset.type);

// Check dataset type configuration first
const supportsTimeFilter = datasetType?.meta?.supportsTimeFilter;
if (supportsTimeFilter !== undefined) {
return Boolean(supportsTimeFilter);

Check warning on line 161 in src/plugins/data/public/ui/dataset_selector/configurator.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/dataset_selector/configurator.tsx#L161

Added line #L161 was not covered by tests
}

// Fall back to language configuration
const languageConfig = languageService.getLanguage(language);
return !languageConfig?.hideDatePicker;
}, [dataset.type, language, queryString, languageService]);

return (
<>
<EuiModalHeader>
Expand Down Expand Up @@ -256,7 +270,7 @@
data-test-subj="advancedSelectorLanguageSelect"
/>
</EuiFormRow>
{!languageService.getLanguage(language)?.hideDatePicker &&
{shouldRenderDatePickerField() &&
(dataset.type === DEFAULT_DATA.SET_TYPES.INDEX_PATTERN ? (
<EuiFormRow
label={i18n.translate(
Expand Down
60 changes: 50 additions & 10 deletions src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,58 @@
);
}

/**
* Determines if the date picker should be rendered based on UI settings, dataset configuration, and language settings.
*
* @returns {boolean} Whether the date picker should be rendered
*
* UI Settings permutations (isDatePickerEnabled):
* - showDatePicker=true || showAutoRefreshOnly=true => true
* - showDatePicker=false && showAutoRefreshOnly=false => false
* - both undefined => true (default)
* If isDatePickerEnabled is false, returns false immediately
*
* Dataset Type permutations (datasetType?.meta?.supportsTimeFilter):
* - supportsTimeFilter=true => true
* - supportsTimeFilter=false => false
* - supportsTimeFilter=undefined && dataset exists => falls through to language check
* - no dataset => falls through to language check
*
* Language permutations (when dataset.meta.supportsTimeFilter is undefined):
* - queryLanguage=undefined => true (shows date picker)
* - queryLanguage exists:
* - hideDatePicker=true => false
* - hideDatePicker=false => true
* - hideDatePicker=undefined => true
*
* Example scenarios:
* 1. {showDatePicker: false} => false
* 2. {dataset: {type: 'x', meta: {supportsTimeFilter: true}}} => true
* 3. {dataset: {type: 'x', meta: {supportsTimeFilter: false}}} => false
* 4. {dataset: {type: 'x'}, queryLanguage: 'sql', hideDatePicker: true} => false
* 5. {dataset: {type: 'x'}, queryLanguage: 'sql', hideDatePicker: false} => true
* 6. {dataset: {type: 'x'}, queryLanguage: undefined} => true (no language restrictions)
* 7. No configuration => true (default behavior shows date picker)
*/
function shouldRenderDatePicker(): boolean {
return (
Boolean((props.showDatePicker || props.showAutoRefreshOnly) ?? true) &&
!(
queryLanguage &&
data.query.queryString.getLanguageService().getLanguage(queryLanguage)?.hideDatePicker
) &&
(props.query?.dataset
? data.query.queryString.getDatasetService().getType(props.query.dataset.type)?.meta
?.supportsTimeFilter !== false
: true)
const { queryString } = data.query;
const datasetService = queryString.getDatasetService();
const languageService = queryString.getLanguageService();
const isDatePickerEnabled = Boolean(
(props.showDatePicker || props.showAutoRefreshOnly) ?? true
);
if (!isDatePickerEnabled) return false;

// Get dataset type configuration
const datasetType = props.query?.dataset
? datasetService.getType(props.query?.dataset.type)
: undefined;
// Check if dataset type explicitly configures the `supportsTimeFilter` option
if (datasetType?.meta?.supportsTimeFilter !== undefined) {
return Boolean(datasetType?.meta?.supportsTimeFilter);

Check warning on line 275 in src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx#L275

Added line #L275 was not covered by tests
}

return Boolean(!(queryLanguage && languageService.getLanguage(queryLanguage)?.hideDatePicker));
}

function shouldRenderQueryEditor(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,29 @@ export class PPLSearchInterceptor extends SearchInterceptor {
.getDatasetService()
.getType(datasetType);
strategy = datasetTypeConfig?.getSearchOptions?.().strategy ?? strategy;

if (datasetTypeConfig?.getSearchOptions?.().includeTimeFilter) {
request.params = {
...request.params,
body: {
...request.params.body,
timeRange: this.queryService.timefilter.timefilter.getTime(),
},
};
}
}

return this.runSearch(request, options.abortSignal, strategy);
}

private buildQuery() {
const query: Query = this.queryService.queryString.getQuery();
const { queryString } = this.queryService;
const query: Query = queryString.getQuery();
const dataset = query.dataset;
if (!dataset || !dataset.timeFieldName) return query;
const datasetService = queryString.getDatasetService();
if (datasetService.getType(dataset.type)?.getSearchOptions?.().includeTimeFilter) return query;

const [baseQuery, ...afterPipeParts] = query.query.split('|');
const afterPipe = afterPipeParts.length > 0 ? ` | ${afterPipeParts.join('|').trim()}` : '';
const timeFilter = this.getTimeFilter(dataset.timeFieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ export class SQLSearchInterceptor extends SearchInterceptor {
.getDatasetService()
.getType(datasetType);
strategy = datasetTypeConfig?.getSearchOptions?.().strategy ?? strategy;

if (datasetTypeConfig?.getSearchOptions?.().includeTimeFilter) {
request.params = {
...request.params,
body: {
Copy link
Member Author

Choose a reason for hiding this comment

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

should be accessible in the search strategy like

request.body.timeRange;

...request.params.body,
timeRange: this.queryService.timefilter.timefilter.getTime(),
},
};
}
}

return this.runSearch(request, options.abortSignal, strategy);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/query_enhancements/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function defineSearchStrategyRouteProvider(logger: Logger, router: IRoute
sessionId: schema.maybe(schema.string()),
})
),
timeRange: schema.maybe(schema.object({}, { unknowns: 'allow' })),
}),
},
},
Expand Down
Loading