diff --git a/.changeset/stream-filter-values.md b/.changeset/stream-filter-values.md new file mode 100644 index 0000000000..d9d7ab082e --- /dev/null +++ b/.changeset/stream-filter-values.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/app': patch +'@hyperdx/common-utils': patch +--- + +perf: stream filter values into the UI as each query finishes instead of +waiting for all of them diff --git a/packages/app/src/components/DBSearchPageFilters.tsx b/packages/app/src/components/DBSearchPageFilters.tsx index 4ac0ea29e7..0286d75517 100644 --- a/packages/app/src/components/DBSearchPageFilters.tsx +++ b/packages/app/src/components/DBSearchPageFilters.tsx @@ -83,6 +83,7 @@ import { } from './DBSearchPageFilters/PinShareMenu'; import { SharedFiltersSection } from './DBSearchPageFilters/SharedFilters'; import { + type FacetEntry, getFilterStateEntry, groupFacetsByBaseName, toQuotedClickHouseKeyExpression, @@ -1016,7 +1017,7 @@ export const FilterGroup = ({ chevron: 'm-0', label: 'p-0', }} - className={hasOptions ? '' : 'opacity-50'} + className={hasOptions || optionsLoading ? '' : 'opacity-50'} > 26 ? 0 : 1500} @@ -1028,12 +1029,21 @@ export const FilterGroup = ({ > {displayName} - {showFilterCounts && ( - {` (${totalAppliedFiltersSize > 0 ? totalAppliedFiltersSize : options.length})`} + {totalAppliedFiltersSize === 0 && optionsLoading ? ( + + ) : ( + showFilterCounts && ( + {` (${totalAppliedFiltersSize > 0 ? totalAppliedFiltersSize : options.length})`} + ) )} @@ -1232,7 +1242,7 @@ const DBSearchPageFiltersComponent = ({ filterState, showMoreFields, }); - const facets = fetchFacetsData.keyValues; + const { keyValues: facets, pendingKeys } = fetchFacetsData; useEffect(() => { if (error) { @@ -1246,7 +1256,7 @@ const DBSearchPageFiltersComponent = ({ }, [error]); // Merge pinned filter values into the queried facets, so that pinned values are always available - const facetsWithPinnedValues = useMemo(() => { + const facetsWithPinnedValues = useMemo((): FacetEntry[] => { const facetsMap = new Map((facets ?? []).map(f => [f.key, f.value])); const mergedKeys = new Set([ ...facetsMap.keys(), @@ -1262,9 +1272,13 @@ const DBSearchPageFiltersComponent = ({ ...(pinnedValues ?? []), ]); - return { key, value: Array.from(mergedValues) }; + return { + key, + value: Array.from(mergedValues), + isLoading: pendingKeys.has(key), + }; }); - }, [facets, pinnedFilters, getPinnedFields]); + }, [facets, pinnedFilters, getPinnedFields, pendingKeys]); // Build the set of team-pinned fields for the Shared Filters section, // so we can avoid duplicating them in the regular Filters list below. @@ -1278,7 +1292,7 @@ const DBSearchPageFiltersComponent = ({ // Build the facet list for the Shared Filters section. // For each team-pinned field: merge pinned values with dynamic facet values. - const sharedFacets = useMemo(() => { + const sharedFacets = useMemo((): FacetEntry[] => { if (sharedFilterKeys.size === 0) return []; const facetMap = new Map( @@ -1288,6 +1302,7 @@ const DBSearchPageFiltersComponent = ({ return Array.from(sharedFilterKeys).map(key => { const teamVals = pinnedFiltersApiData?.team?.filters[key] ?? []; const dynamicValues = facetMap.get(key) ?? []; + const isLoading = pendingKeys.has(key); let merged: (string | boolean)[]; if (teamVals.length > 0) { @@ -1302,12 +1317,17 @@ const DBSearchPageFiltersComponent = ({ merged = [...dynamicValues]; } - return { key, value: merged }; + return { key, value: merged, isLoading }; }); - }, [sharedFilterKeys, facetsWithPinnedValues, pinnedFiltersApiData]); + }, [ + sharedFilterKeys, + facetsWithPinnedValues, + pinnedFiltersApiData, + pendingKeys, + ]); const shownFacets = useMemo(() => { - const _facets: { key: string; value: (string | boolean)[] }[] = []; + const _facets: FacetEntry[] = []; for (const _facet of facetsWithPinnedValues ?? []) { const facet = structuredClone(_facet); if (jsonColumns?.some(col => facet.key.startsWith(col))) { @@ -1319,12 +1339,18 @@ const DBSearchPageFiltersComponent = ({ continue; } - // don't include empty facets, unless they are already selected or pinned + // don't include empty facets, unless they are already selected, pinned, + // or still waiting on their values const filter = filterState[facet.key]; const hasSelectedValues = filter && (filter.included.size > 0 || filter.excluded.size > 0); const isPinned = isFieldPinned(facet.key); - if (facet.value?.length > 0 || hasSelectedValues || isPinned) { + if ( + facet.value?.length > 0 || + hasSelectedValues || + isPinned || + facet.isLoading + ) { _facets.push(facet); } } @@ -1466,7 +1492,7 @@ const DBSearchPageFiltersComponent = ({ */ const renderFacetList = useCallback( ( - facets: { key: string; value: (string | boolean)[] }[], + facets: FacetEntry[], options?: { keyPrefix?: string; isDefaultExpanded?: boolean }, ) => { const { keyPrefix = '', isDefaultExpanded: forceExpanded } = @@ -1582,7 +1608,7 @@ const DBSearchPageFiltersComponent = ({ value, label: value.toString(), }))} - optionsLoading={isFacetsLoading} + optionsLoading={isFacetsLoading || !!facet.isLoading} selectedValues={ getFilterStateEntry(filterState, facet.key) ?? { included: new Set(), @@ -1876,16 +1902,15 @@ const DBSearchPageFiltersComponent = ({ /> )} - {isFacetsLoading ? ( - - - - ) : ( - shownFacets.length === 0 && ( + {shownFacets.length === 0 && + (isFacetsLoading ? ( + + + + ) : ( No filters available - ) - )} - {/* Show facets even when loading to ensure pinned filters are visible while loading */} + ))} + {/* Filters show their own loader until their values arrive */} {renderFacetList(shownFacets)}