mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[OneDiscover][Tabs] Show the correct query in the unvisited tab preview (#225032)
- Closes https://github.com/elastic/kibana/issues/221507 ## Summary This PR fixes the query which is shown in the tab preview popover. Before it was working correctly only for already visited tab. Now it should work for all tabs (once they are restored from local storage after a page refresh). 
This commit is contained in:
parent
2ed4e8a341
commit
73be8df9db
1 changed files with 26 additions and 13 deletions
|
@ -16,24 +16,29 @@ import { TabStatus } from '@kbn/unified-tabs';
|
|||
import { isOfAggregateQueryType } from '@kbn/es-query';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { isEqual } from 'lodash';
|
||||
import type { RuntimeStateManager } from '../../state_management/redux';
|
||||
import { selectTabRuntimeState, useInternalStateSelector } from '../../state_management/redux';
|
||||
import type { RuntimeStateManager, TabState } from '../../state_management/redux';
|
||||
import {
|
||||
selectTabRuntimeState,
|
||||
useInternalStateSelector,
|
||||
selectAllTabs,
|
||||
} from '../../state_management/redux';
|
||||
import { FetchStatus } from '../../../types';
|
||||
|
||||
export const usePreviewData = (runtimeStateManager: RuntimeStateManager) => {
|
||||
const allTabIds = useInternalStateSelector((state) => state.tabs.allIds);
|
||||
const allTabs = useInternalStateSelector(selectAllTabs);
|
||||
|
||||
const previewDataMap$ = useMemo(
|
||||
() =>
|
||||
combineLatest(
|
||||
allTabIds.reduce<Record<string, Observable<TabPreviewData>>>(
|
||||
(acc, tabId) => ({
|
||||
allTabs.reduce<Record<string, Observable<TabPreviewData>>>((acc, tabState) => {
|
||||
const tabId = tabState.id;
|
||||
return {
|
||||
...acc,
|
||||
[tabId]: getPreviewDataObservable(runtimeStateManager, tabId),
|
||||
}),
|
||||
{}
|
||||
)
|
||||
[tabId]: getPreviewDataObservable(runtimeStateManager, tabId, tabState.initialAppState),
|
||||
};
|
||||
}, {})
|
||||
),
|
||||
[allTabIds, runtimeStateManager]
|
||||
[allTabs, runtimeStateManager]
|
||||
);
|
||||
const previewDataMap = useObservable(previewDataMap$);
|
||||
const getPreviewData = useCallback(
|
||||
|
@ -83,12 +88,20 @@ const getPreviewQuery = (query: TabPreviewData['query'] | undefined): TabPreview
|
|||
};
|
||||
};
|
||||
|
||||
const getPreviewDataObservable = (runtimeStateManager: RuntimeStateManager, tabId: string) =>
|
||||
const getPreviewDataObservable = (
|
||||
runtimeStateManager: RuntimeStateManager,
|
||||
tabId: string,
|
||||
initialAppState: TabState['initialAppState'] | undefined
|
||||
) =>
|
||||
selectTabRuntimeState(runtimeStateManager, tabId).stateContainer$.pipe(
|
||||
switchMap((tabStateContainer) => {
|
||||
if (!tabStateContainer) {
|
||||
// TODO: show the real query for tabs which are not yet initialized
|
||||
return of({ status: TabStatus.DEFAULT, query: DEFAULT_PREVIEW_QUERY });
|
||||
return of({
|
||||
status: TabStatus.DEFAULT,
|
||||
query: initialAppState?.query
|
||||
? getPreviewQuery(initialAppState.query)
|
||||
: DEFAULT_PREVIEW_QUERY,
|
||||
});
|
||||
}
|
||||
|
||||
const { appState } = tabStateContainer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue