diff --git a/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.ts b/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.ts
index 1ebeb8d7d1b7f..2994a54a3c645 100644
--- a/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.ts
+++ b/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.ts
@@ -42,13 +42,19 @@ import type { DiscoverStateContainer } from '../../state_management/discover_sta
import { addLog } from '../../../../utils/add_log';
import { useInternalStateSelector } from '../../state_management/discover_internal_state_container';
import type { DiscoverAppState } from '../../state_management/discover_app_state_container';
-import { DataDocumentsMsg } from '../../state_management/discover_data_state_container';
+import type { DataDocumentsMsg } from '../../state_management/discover_data_state_container';
import { useSavedSearch } from '../../state_management/discover_state_provider';
import { useIsEsqlMode } from '../../hooks/use_is_esql_mode';
const EMPTY_ESQL_COLUMNS: DatatableColumn[] = [];
const EMPTY_FILTERS: Filter[] = [];
+// enabled for debugging
+if (window) {
+ // @ts-ignore
+ window.ELASTIC_DISCOVER_LOGGER = `debug`;
+}
+
export interface UseDiscoverHistogramProps {
stateContainer: DiscoverStateContainer;
inspectorAdapters: InspectorAdapters;
@@ -180,17 +186,45 @@ export const useDiscoverHistogram = ({
totalHitsResult &&
typeof result !== 'number'
) {
- // ignore the histogram initial loading state if discover state already has a total hits value
+ addLog(
+ '[UnifiedHistogram] ignore the histogram initial loading state if discover state already has a total hits value',
+ { status, result }
+ );
return;
}
+ const fetchStatus = status.toString() as FetchStatus;
+ if (
+ fetchStatus === FetchStatus.COMPLETE &&
+ savedSearchData$.totalHits$.getValue().fetchStatus === FetchStatus.COMPLETE &&
+ result !== savedSearchData$.totalHits$.getValue().result
+ ) {
+ // this is a workaround to make sure the new total hits value is displayed
+ // a different value without a loading state in between would lead to be ignored by useDataState
+ addLog(
+ '[UnifiedHistogram] send loading state to total hits$ to make sure the new value is displayed',
+ { status, result }
+ );
+ savedSearchData$.totalHits$.next({
+ fetchStatus: FetchStatus.LOADING,
+ });
+ }
+
// Sync the totalHits$ observable with the unified histogram state
savedSearchData$.totalHits$.next({
- fetchStatus: status.toString() as FetchStatus,
+ fetchStatus,
result,
});
- if (status !== UnifiedHistogramFetchStatus.complete || typeof result !== 'number') {
+ if (
+ (status !== UnifiedHistogramFetchStatus.complete &&
+ status !== UnifiedHistogramFetchStatus.partial) ||
+ typeof result !== 'number'
+ ) {
+ addLog(
+ '[UnifiedHistogram] ignore the histogram complete/partial state if discover state already has a total hits value',
+ { status, result }
+ );
return;
}
diff --git a/src/plugins/discover/public/application/main/data_fetching/fetch_all.test.ts b/src/plugins/discover/public/application/main/data_fetching/fetch_all.test.ts
index 169a644e69499..c58417f818b28 100644
--- a/src/plugins/discover/public/application/main/data_fetching/fetch_all.test.ts
+++ b/src/plugins/discover/public/application/main/data_fetching/fetch_all.test.ts
@@ -69,6 +69,7 @@ describe('test fetchAll', () => {
getAppState: () => ({}),
getInternalState: () => ({
dataView: undefined,
+ isLoading: false,
isDataViewLoading: false,
savedDataViews: [],
adHocDataViews: [],
@@ -262,6 +263,7 @@ describe('test fetchAll', () => {
getInternalState: () => ({
dataView: undefined,
isDataViewLoading: false,
+ isLoading: false,
savedDataViews: [],
adHocDataViews: [],
expandedDoc: undefined,
@@ -384,6 +386,7 @@ describe('test fetchAll', () => {
getInternalState: () => ({
dataView: undefined,
isDataViewLoading: false,
+ isLoading: false,
savedDataViews: [],
adHocDataViews: [],
expandedDoc: undefined,
diff --git a/src/plugins/discover/public/application/main/discover_main_route.tsx b/src/plugins/discover/public/application/main/discover_main_route.tsx
index 57173717de2a2..26848ab20f853 100644
--- a/src/plugins/discover/public/application/main/discover_main_route.tsx
+++ b/src/plugins/discover/public/application/main/discover_main_route.tsx
@@ -369,14 +369,14 @@ export function DiscoverMainLoading({
mainContent: JSX.Element;
}) {
const loading = useInternalStateSelector((state) => state.isLoading);
- if (loading && !showNoDataPage) {
- return ;
- }
return (
<>
-
- {mainContent}
+
+ {loading && !showNoDataPage ? : mainContent}
>
);
}