diff --git a/src/plugins/discover/public/application/main/hooks/use_saved_search.ts b/src/plugins/discover/public/application/main/hooks/use_saved_search.ts index 2f097daac982d..72396c0578db0 100644 --- a/src/plugins/discover/public/application/main/hooks/use_saved_search.ts +++ b/src/plugins/discover/public/application/main/hooks/use_saved_search.ts @@ -78,8 +78,6 @@ export interface DataDocumentsMsg extends DataMsg { } export interface DataTotalHitsMsg extends DataMsg { - fetchStatus: FetchStatus; - error?: Error; result?: number; } diff --git a/src/plugins/discover/public/application/main/utils/fetch_all.ts b/src/plugins/discover/public/application/main/utils/fetch_all.ts index d530da1492fac..213bdca335e1a 100644 --- a/src/plugins/discover/public/application/main/utils/fetch_all.ts +++ b/src/plugins/discover/public/application/main/utils/fetch_all.ts @@ -164,12 +164,6 @@ export function fetchAll( charts ?.then((chart) => { - dataSubjects.totalHits$.next({ - fetchStatus: FetchStatus.COMPLETE, - result: chart.totalHits, - recordRawType, - }); - dataSubjects.charts$.next({ fetchStatus: FetchStatus.COMPLETE, response: chart.response, diff --git a/src/plugins/unified_histogram/public/chart/chart.tsx b/src/plugins/unified_histogram/public/chart/chart.tsx index 7db78b67b153d..342603dde99a5 100644 --- a/src/plugins/unified_histogram/public/chart/chart.tsx +++ b/src/plugins/unified_histogram/public/chart/chart.tsx @@ -100,6 +100,12 @@ export function Chart({ onResetChartHeight, }); + const [totalHits, setTotalHits] = useState(); + + const onTotalHitsChange = useCallback((newTotalHits: number) => { + setTotalHits(newTotalHits); + }, []); + const chartVisible = chart && !chart.hidden; const { euiTheme } = useEuiTheme(); @@ -158,7 +164,7 @@ export function Chart({ className="eui-textTruncate eui-textNoWrap" css={resultCountTitleCss} > - {hits && } + {hits && } {chart && ( @@ -245,6 +251,7 @@ export function Chart({ dataView={dataView} chart={chart} breakdown={breakdown} + onTotalHitsChange={onTotalHitsChange} /> {appendHistogram} diff --git a/src/plugins/unified_histogram/public/chart/get_lens_attributes.ts b/src/plugins/unified_histogram/public/chart/get_lens_attributes.ts index 25300de632db0..a630633012012 100644 --- a/src/plugins/unified_histogram/public/chart/get_lens_attributes.ts +++ b/src/plugins/unified_histogram/public/chart/get_lens_attributes.ts @@ -96,7 +96,7 @@ export const getLensAttributes = ({ }, { id: dataView.id ?? '', - name: 'indexpattern-datasource-layer-layer1', + name: 'indexpattern-datasource-layer-unifiedHistogram', type: 'index-pattern', }, ], @@ -104,7 +104,7 @@ export const getLensAttributes = ({ datasourceStates: { formBased: { layers: { - layer1: { columnOrder, columns }, + unifiedHistogram: { columnOrder, columns }, }, }, }, @@ -114,7 +114,7 @@ export const getLensAttributes = ({ layers: [ { accessors: ['count_column'], - layerId: 'layer1', + layerId: 'unifiedHistogram', layerType: 'data', seriesType: 'bar_stacked', xAccessor: 'date_column', diff --git a/src/plugins/unified_histogram/public/chart/histogram.tsx b/src/plugins/unified_histogram/public/chart/histogram.tsx index dc542ea4fbf1d..a172ad4e455f1 100644 --- a/src/plugins/unified_histogram/public/chart/histogram.tsx +++ b/src/plugins/unified_histogram/public/chart/histogram.tsx @@ -13,6 +13,7 @@ import { css } from '@emotion/react'; import React, { useCallback, useMemo } from 'react'; import { ViewMode } from '@kbn/embeddable-plugin/public'; import type { DataView } from '@kbn/data-views-plugin/public'; +import type { DefaultInspectorAdapters } from '@kbn/expressions-plugin/common'; import type { UnifiedHistogramBreakdownContext, UnifiedHistogramChartContext, @@ -25,6 +26,7 @@ export interface HistogramProps { dataView: DataView; chart: UnifiedHistogramChartContext; breakdown?: UnifiedHistogramBreakdownContext; + onTotalHitsChange: (totalHits: number) => void; } export function Histogram({ @@ -32,6 +34,7 @@ export function Histogram({ dataView, chart: { timeInterval, bucketInterval, data: chartData }, breakdown: { field: breakdownField } = {}, + onTotalHitsChange, }: HistogramProps) { const filters = data.query.filterManager.getFilters(); const query = data.query.queryString.getQuery(); @@ -77,6 +80,17 @@ export function Histogram({ return `${toMoment(timeRange.from)} - ${toMoment(timeRange.to)} ${intervalText}`; }, [from, to, timeInterval, bucketInterval?.description, toMoment]); + const onLoad = useCallback( + (_, adapters: Partial | undefined) => { + const totalHits = adapters?.tables?.tables?.unifiedHistogram?.meta?.statistics?.totalCount; + + if (totalHits) { + onTotalHitsChange(totalHits); + } + }, + [onTotalHitsChange] + ); + const { euiTheme } = useEuiTheme(); const chartCss = css` position: relative; @@ -164,6 +178,7 @@ export function Histogram({ timeRange={{ from, to }} attributes={attributes} noPadding + onLoad={onLoad} /> {timeRange} diff --git a/src/plugins/unified_histogram/public/hits_counter/hits_counter.tsx b/src/plugins/unified_histogram/public/hits_counter/hits_counter.tsx index 39df40650557c..e6296429576a8 100644 --- a/src/plugins/unified_histogram/public/hits_counter/hits_counter.tsx +++ b/src/plugins/unified_histogram/public/hits_counter/hits_counter.tsx @@ -16,21 +16,24 @@ import type { UnifiedHistogramHitsContext } from '../types'; export interface HitsCounterProps { hits: UnifiedHistogramHitsContext; + totalHits?: number; append?: ReactElement; } -export function HitsCounter({ hits, append }: HitsCounterProps) { - if (!hits.total && hits.status === 'loading') { +export function HitsCounter({ hits, totalHits, append }: HitsCounterProps) { + if (!hits.total && hits.status === 'loading' && !totalHits) { return null; } const formattedHits = ( - + ); @@ -48,23 +51,23 @@ export function HitsCounter({ hits, append }: HitsCounterProps) { > - {hits.status === 'partial' && ( + {hits.status === 'partial' && !totalHits && ( )} - {hits.status !== 'partial' && ( + {(hits.status !== 'partial' || totalHits) && ( )} - {hits.status === 'partial' && ( + {hits.status === 'partial' && !totalHits && (