Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Footer count render independent of logs table #423

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/hooks/useQueryResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -83,6 +84,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}\"`;
Expand Down Expand Up @@ -110,13 +112,10 @@ export const useFetchCount = () => {
endTime: timeRange.endTime,
access: [],
};
const {
isLoading: isCountLoading,
isRefetching: isCountRefetching,
refetch: refetchCount,
} = useQuery(
const { 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));
Expand All @@ -127,12 +126,17 @@ export const useFetchCount = () => {
refetchOnWindowFocus: false,
retry: false,
enabled: false,
onSuccess: () => {
setCountLoading(false);
},
onError: () => {
setCountLoading(false);
},
},
);

return {
isCountLoading,
isCountRefetching,
countLoading,
refetchCount,
};
};
6 changes: 2 additions & 4 deletions src/pages/Stream/Views/Explore/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const TotalLogsCount = (props: { hasTableLoaded: boolean; isFetchingCount: boole
if (typeof totalCount !== 'number' || typeof displayedCount !== 'number') return <Stack />;
return (
<Stack style={{ alignItems: 'center', justifyContent: 'center', flexDirection: 'row' }} gap={6}>
{props.hasTableLoaded ? (
{!props.isTableEmpty ? (
props.isFetchingCount ? (
<Loader type="dots" />
) : (
Expand All @@ -37,9 +37,7 @@ const TotalLogsCount = (props: { hasTableLoaded: boolean; isFetchingCount: boole
<Text style={{ fontSize: '0.7rem' }}>records</Text>
</>
)
) : props.isTableEmpty ? null : (
<Loader type="dots" />
)}
) : null}
</Stack>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Stream/Views/Explore/useLogsFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +55,7 @@ const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean })
hasContentLoaded,
hasNoData,
showTable,
isFetchingCount: isCountLoading || isCountRefetching,
isFetchingCount: countLoading,
};
};

Expand Down
Loading