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

add a new flag in timefilter service to disable time filter #8981

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions changelogs/fragments/8981.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Hide time filter when query assistant input is expanded ([#8981](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8981))
14 changes: 14 additions & 0 deletions src/plugins/data/public/query/timefilter/timefilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
private autoRefreshFetch$ = new Subject();
private fetch$ = new Subject();

private disabled$ = new BehaviorSubject(false);

private _time: TimeRange;
private _refreshInterval!: RefreshInterval;
private _history: TimeHistoryContract;
Expand Down Expand Up @@ -173,6 +175,18 @@
}
};

public setDisabled(val: boolean) {
this.disabled$.next(val);

Check warning on line 179 in src/plugins/data/public/query/timefilter/timefilter.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/timefilter/timefilter.ts#L179

Added line #L179 was not covered by tests
}

public getDisabled$() {
return this.disabled$;

Check warning on line 183 in src/plugins/data/public/query/timefilter/timefilter.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/timefilter/timefilter.ts#L183

Added line #L183 was not covered by tests
}

public isDisabled() {
return this.disabled$.value;

Check warning on line 187 in src/plugins/data/public/query/timefilter/timefilter.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/timefilter/timefilter.ts#L187

Added line #L187 was not covered by tests
}

public createFilter = (indexPattern: IndexPattern, timeRange?: TimeRange) => {
return getTime(indexPattern, timeRange ? timeRange : this._time, {
forceNow: this.getForceNow(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

import { TimefilterService, TimeHistoryContract, TimefilterContract } from '.';
import { Observable } from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';

export type TimefilterServiceClientContract = PublicMethodsOf<TimefilterService>;

Expand All @@ -56,6 +56,9 @@ const createSetupContractMock = () => {
createFilter: jest.fn(),
getRefreshIntervalDefaults: jest.fn(),
getTimeDefaults: jest.fn(),
getDisabled$: jest.fn(() => new BehaviorSubject<boolean>(false)),
setDisabled: jest.fn(),
isDisabled: jest.fn(),
};

const historyMock: jest.Mocked<TimeHistoryContract> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import classNames from 'classnames';
import React, { useState } from 'react';
import { createPortal } from 'react-dom';
import { useObservable } from 'react-use';
import {
DatasetSelector,
DatasetSelectorAppearance,
Expand Down Expand Up @@ -74,6 +75,8 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>();
const { uiSettings, storage, appName, data } = opensearchDashboards.services;

const timeFilterDisabled = useObservable(data.query.timefilter.timefilter.getDisabled$());

const queryLanguage = props.query && props.query.language;
const persistedLog: PersistedLog | undefined = React.useMemo(
() =>
Expand Down Expand Up @@ -309,6 +312,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
return (
<EuiFlexItem className={wrapperClasses}>
<EuiSuperDatePicker
isDisabled={timeFilterDisabled}
start={props.dateRangeFrom}
end={props.dateRangeTo}
isPaused={props.isRefreshPaused}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface QueryAssistInputProps {
export const QueryAssistBar: React.FC<QueryAssistInputProps> = (props) => {
const { services } = useOpenSearchDashboards<IDataPluginServices>();
const queryString = services.data.query.queryString;
const timefilter = services.data.query.timefilter;
const inputRef = useRef<HTMLInputElement>(null);
const storage = getStorage();
const persistedLog: PersistedLog = useMemo(
Expand All @@ -52,6 +53,17 @@ export const QueryAssistBar: React.FC<QueryAssistInputProps> = (props) => {
return () => subscription.unsubscribe();
}, [queryString]);

useEffect(() => {
// Disable time filter when the assistant query input is expanded
const disabled = !(props.dependencies.isCollapsed || isQueryAssistCollapsed);
timefilter.timefilter.setDisabled(disabled);
}, [props.dependencies.isCollapsed, isQueryAssistCollapsed, timefilter]);

useEffect(() => {
// reset the time filter state to false when query assist bar unmounted
return () => timefilter.timefilter.setDisabled(false);
}, [timefilter]);

const onSubmit = async (e: SyntheticEvent) => {
e.preventDefault();
if (!inputRef.current?.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ export class PPLSearchInterceptor extends SearchInterceptor {
private buildQuery() {
const query: Query = this.queryService.queryString.getQuery();
const dataset = query.dataset;
// If the dataset has no time field, so time filter is not supported, time filter should not be included in the query
if (!dataset || !dataset.timeFieldName) return query;

// If the time filter be disabled explicitly, time filter should not be included in the query
if (this.queryService.timefilter.timefilter.isDisabled()) {
return query;
}

const [baseQuery, ...afterPipeParts] = query.query.split('|');
const afterPipe = afterPipeParts.length > 0 ? ` | ${afterPipeParts.join('|').trim()}` : '';
const timeFilter = this.getTimeFilter(dataset.timeFieldName);
Expand Down
Loading