Skip to content

Commit 897d152

Browse files
authored
fix: footer count render independent of log table (#423)
1 parent b27789b commit 897d152

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/hooks/useQueryResult.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useFilterStore, filterStoreReducers } from '@/pages/Stream/providers/Fi
99
import _ from 'lodash';
1010
import { useAppStore } from '@/layouts/MainLayout/providers/AppProvider';
1111
import { notifyError } from '@/utils/notification';
12+
import { useState } from 'react';
1213

1314
const { parseQuery } = filterStoreReducers;
1415

@@ -83,6 +84,7 @@ export const useFetchCount = () => {
8384
const [, setLogsStore] = useLogsStore(() => null);
8485
const { isQuerySearchActive, custSearchQuery, activeMode } = custQuerySearchState;
8586
const [appliedQuery] = useFilterStore((store) => store.appliedQuery);
87+
const [countLoading, setCountLoading] = useState(true);
8688

8789
/* eslint-disable no-useless-escape */
8890
const defaultQuery = `select count(*) as count from \"${currentStream}\"`;
@@ -110,13 +112,10 @@ export const useFetchCount = () => {
110112
endTime: timeRange.endTime,
111113
access: [],
112114
};
113-
const {
114-
isLoading: isCountLoading,
115-
isRefetching: isCountRefetching,
116-
refetch: refetchCount,
117-
} = useQuery(
115+
const { refetch: refetchCount } = useQuery(
118116
['fetchCount', logsQuery],
119117
async () => {
118+
setCountLoading(true);
120119
const data = await getQueryResult(logsQuery, query);
121120
const count = _.first(data.data)?.count;
122121
typeof count === 'number' && setLogsStore((store) => setTotalCount(store, count));
@@ -127,12 +126,17 @@ export const useFetchCount = () => {
127126
refetchOnWindowFocus: false,
128127
retry: false,
129128
enabled: false,
129+
onSuccess: () => {
130+
setCountLoading(false);
131+
},
132+
onError: () => {
133+
setCountLoading(false);
134+
},
130135
},
131136
);
132137

133138
return {
134-
isCountLoading,
135-
isCountRefetching,
139+
countLoading,
136140
refetchCount,
137141
};
138142
};

src/pages/Stream/Views/Explore/Footer.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const TotalLogsCount = (props: { hasTableLoaded: boolean; isFetchingCount: boole
2727
if (typeof totalCount !== 'number' || typeof displayedCount !== 'number') return <Stack />;
2828
return (
2929
<Stack style={{ alignItems: 'center', justifyContent: 'center', flexDirection: 'row' }} gap={6}>
30-
{props.hasTableLoaded ? (
30+
{!props.isTableEmpty ? (
3131
props.isFetchingCount ? (
3232
<Loader type="dots" />
3333
) : (
@@ -37,9 +37,7 @@ const TotalLogsCount = (props: { hasTableLoaded: boolean; isFetchingCount: boole
3737
<Text style={{ fontSize: '0.7rem' }}>records</Text>
3838
</>
3939
)
40-
) : props.isTableEmpty ? null : (
41-
<Loader type="dots" />
42-
)}
40+
) : null}
4341
</Stack>
4442
);
4543
};

src/pages/Stream/Views/Explore/useLogsFetcher.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean })
2121
const [{ info }] = useStreamStore((store) => store);
2222
const firstEventAt = 'first-event-at' in info ? info['first-event-at'] : undefined;
2323

24-
const { refetchCount, isCountLoading, isCountRefetching } = useFetchCount();
24+
const { refetchCount, countLoading } = useFetchCount();
2525
const hasContentLoaded = schemaLoading === false && logsLoading === false;
2626
const hasNoData = hasContentLoaded && !queryLogsError && pageData.length === 0;
2727
const showTable = hasContentLoaded && !hasNoData && !queryLogsError;
@@ -55,7 +55,7 @@ const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean })
5555
hasContentLoaded,
5656
hasNoData,
5757
showTable,
58-
isFetchingCount: isCountLoading || isCountRefetching,
58+
isFetchingCount: countLoading,
5959
};
6060
};
6161

0 commit comments

Comments
 (0)