From e023b9ce5c3347a4f76d47a02b95ab57cf2a11af Mon Sep 17 00:00:00 2001 From: Koustav Date: Thu, 16 Jan 2025 17:02:12 +0530 Subject: [PATCH 1/2] Footer count render independent of logs table --- src/hooks/useQueryResult.tsx | 16 ++++++++++++---- src/pages/Stream/Views/Explore/Footer.tsx | 6 ++---- src/pages/Stream/Views/Explore/useLogsFetcher.ts | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/hooks/useQueryResult.tsx b/src/hooks/useQueryResult.tsx index 329ebbd2..05ebde57 100644 --- a/src/hooks/useQueryResult.tsx +++ b/src/hooks/useQueryResult.tsx @@ -9,6 +9,7 @@ import { useFilterStore, filterStoreReducers } from '@/pages/Stream/providers/Fi import _ from 'lodash'; import { useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; import { notifyError } from '@/utils/notification'; +import { useState } from 'react'; const { parseQuery } = filterStoreReducers; @@ -60,6 +61,7 @@ export const useFetchCount = () => { const [, setLogsStore] = useLogsStore(() => null); const { isQuerySearchActive, custSearchQuery, activeMode } = custQuerySearchState; const [appliedQuery] = useFilterStore((store) => store.appliedQuery); + const [countLoading, setCountLoading] = useState(true); /* eslint-disable no-useless-escape */ const defaultQuery = `select count(*) as count from \"${currentStream}\"`; @@ -88,12 +90,13 @@ export const useFetchCount = () => { access: [], }; const { - isLoading: isCountLoading, - isRefetching: isCountRefetching, + // isLoading: isCountLoading, + // isRefetching: isCountRefetching, refetch: refetchCount, } = useQuery( ['fetchCount', logsQuery], async () => { + setCountLoading(true); const data = await getQueryResult(logsQuery, query); const count = _.first(data.data)?.count; typeof count === 'number' && setLogsStore((store) => setTotalCount(store, count)); @@ -104,12 +107,17 @@ export const useFetchCount = () => { refetchOnWindowFocus: false, retry: false, enabled: false, + onSuccess: () => { + setCountLoading(false); + }, + onError: () => { + setCountLoading(false); + }, }, ); return { - isCountLoading, - isCountRefetching, + countLoading, refetchCount, }; }; diff --git a/src/pages/Stream/Views/Explore/Footer.tsx b/src/pages/Stream/Views/Explore/Footer.tsx index ca1f35e2..9b72c3e5 100644 --- a/src/pages/Stream/Views/Explore/Footer.tsx +++ b/src/pages/Stream/Views/Explore/Footer.tsx @@ -27,7 +27,7 @@ const TotalLogsCount = (props: { hasTableLoaded: boolean; isFetchingCount: boole if (typeof totalCount !== 'number' || typeof displayedCount !== 'number') return ; return ( - {props.hasTableLoaded ? ( + {!props.isTableEmpty ? ( props.isFetchingCount ? ( ) : ( @@ -37,9 +37,7 @@ const TotalLogsCount = (props: { hasTableLoaded: boolean; isFetchingCount: boole records ) - ) : props.isTableEmpty ? null : ( - - )} + ) : null} ); }; diff --git a/src/pages/Stream/Views/Explore/useLogsFetcher.ts b/src/pages/Stream/Views/Explore/useLogsFetcher.ts index 99ec6342..58433b6a 100644 --- a/src/pages/Stream/Views/Explore/useLogsFetcher.ts +++ b/src/pages/Stream/Views/Explore/useLogsFetcher.ts @@ -21,7 +21,7 @@ const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean }) const [{ info }] = useStreamStore((store) => store); const firstEventAt = 'first-event-at' in info ? info['first-event-at'] : undefined; - const { refetchCount, isCountLoading, isCountRefetching } = useFetchCount(); + const { refetchCount, countLoading } = useFetchCount(); const hasContentLoaded = schemaLoading === false && logsLoading === false; const hasNoData = hasContentLoaded && !queryLogsError && pageData.length === 0; const showTable = hasContentLoaded && !hasNoData && !queryLogsError; @@ -55,7 +55,7 @@ const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean }) hasContentLoaded, hasNoData, showTable, - isFetchingCount: isCountLoading || isCountRefetching, + isFetchingCount: countLoading, }; }; From 76d523d89a093f3c8151a496681be44851c4beb5 Mon Sep 17 00:00:00 2001 From: Koustav Date: Thu, 16 Jan 2025 17:12:02 +0530 Subject: [PATCH 2/2] removed unsed code --- src/hooks/useQueryResult.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/hooks/useQueryResult.tsx b/src/hooks/useQueryResult.tsx index 05ebde57..16e8cc7b 100644 --- a/src/hooks/useQueryResult.tsx +++ b/src/hooks/useQueryResult.tsx @@ -89,11 +89,7 @@ export const useFetchCount = () => { endTime: timeRange.endTime, access: [], }; - const { - // isLoading: isCountLoading, - // isRefetching: isCountRefetching, - refetch: refetchCount, - } = useQuery( + const { refetch: refetchCount } = useQuery( ['fetchCount', logsQuery], async () => { setCountLoading(true);