Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .buildkite/ftr_platform_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enabled:
- src/platform/test/functional/apps/discover/group10/config.ts
- src/platform/test/functional/apps/discover/context_awareness/config.ts
- src/platform/test/functional/apps/discover/observability/config.ts
- src/platform/test/functional/apps/discover/query_mode/config.ts
- src/platform/test/functional/apps/discover/tabs/config.ts
- src/platform/test/functional/apps/discover/tabs2/config.ts
- src/platform/test/functional/apps/discover/tabs3/config.ts
Expand Down
3 changes: 3 additions & 0 deletions src/platform/plugins/shared/discover/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const getDefaultRowsPerPage = (uiSettings: IUiSettingsClient): number =>
// local storage key for the ES|QL to Dataviews transition modal
export const ESQL_TRANSITION_MODAL_KEY = 'data.textLangTransitionModal';

// local storage key for the query mode when starting a new discover session
export const DISCOVER_QUERY_MODE_KEY = 'discover.defaultQueryMode';

/**
* The id value used to indicate that a link should open in a new Discover tab.
* It will be used in the `_tab` URL param to indicate that a new tab should be created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export const initializeSingleTab = createInternalStateAsyncThunk(
// then get an updated copy of the saved search with the applied initial state
const initialAppState = getInitialAppState({
initialUrlState: urlAppState,
hasGlobalState: Object.keys(urlGlobalState || {}).length > 0,
persistedTab,
dataView,
services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
internalStateSlice,
type InternalStateThunkActionCreator,
type TabActionPayload,
transitionedFromEsqlToDataView,
transitionedFromDataViewToEsql,
} from '../internal_state';
import { selectTab } from '../selectors';
import { selectTabRuntimeState } from '../runtime_state';
Expand Down Expand Up @@ -206,6 +208,8 @@ export const transitionFromESQLToDataView: InternalStateThunkActionCreator<
},
})
);

dispatch(transitionedFromEsqlToDataView({ tabId }));
};

const clearTimeFieldFromSort = (
Expand Down Expand Up @@ -251,6 +255,8 @@ export const transitionFromDataViewToESQL: InternalStateThunkActionCreator<

// clears pinned filters
dispatch(updateGlobalState({ tabId, globalState: { filters: [] } }));

dispatch(transitionedFromDataViewToEsql({ tabId }));
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
import type { ESQLControlVariable } from '@kbn/esql-types';
import type { DiscoverSession } from '@kbn/saved-search-plugin/common';
import { isOfAggregateQueryType } from '@kbn/es-query';
import { DISCOVER_QUERY_MODE_KEY } from '../../../../../common/constants';
import type { DiscoverCustomizationContext } from '../../../../customizations';
import type { DiscoverServices } from '../../../../build_services';
import { type RuntimeStateManager, selectTabRuntimeInternalState } from './runtime_state';
Expand Down Expand Up @@ -446,6 +447,14 @@ export const syncLocallyPersistedTabState = createAction<TabActionPayload>(

export const discardFlyoutsOnTabChange = createAction('internalState/discardFlyoutsOnTabChange');

export const transitionedFromEsqlToDataView = createAction<TabActionPayload>(
'internalState/transitionedFromEsqlToDataView'
);

export const transitionedFromDataViewToEsql = createAction<TabActionPayload>(
'internalState/transitionedFromDataViewToEsql'
);

type InternalStateListenerEffect<
TActionCreator extends PayloadActionCreator<TPayload>,
TPayload = TActionCreator extends PayloadActionCreator<infer T> ? T : never
Expand Down Expand Up @@ -510,6 +519,28 @@ const createMiddleware = (options: InternalStateDependencies) => {
},
});

// This pair of listeners updates the default query mode based on the last used query type (ES|QL vs Data View), we use
// this so new discover sessions use that query mode as a default.
//
// NOTE: In the short term we will add a feature flag to default to ES|QL when there is no existing preference saved.
// Right now we use classic - this means that users will have to switch to ES|QL manually the first time if they already
// had classic stored as their last used mode.
startListening({
actionCreator: transitionedFromDataViewToEsql,
effect: (action, listenerApi) => {
const { services } = listenerApi.extra;
services.storage.set(DISCOVER_QUERY_MODE_KEY, 'esql');
},
});

startListening({
actionCreator: transitionedFromEsqlToDataView,
effect: (action, listenerApi) => {
const { services } = listenerApi.extra;
services.storage.set(DISCOVER_QUERY_MODE_KEY, 'classic');
},
});

return listenerMiddleware.middleware;
};

Expand Down
Loading
Loading