From 290fbb7e0f661b4955114c5aa7d16042badf995b Mon Sep 17 00:00:00 2001 From: Praveen K B <30530587+praveen5959@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:20:16 +0530 Subject: [PATCH] fix: Retry on error should show success data (#406) --- src/hooks/useQueryLogs.ts | 34 +++---------------- src/pages/Stream/Views/Explore/JSONView.tsx | 5 +-- src/pages/Stream/Views/Explore/LogsView.tsx | 5 +-- .../Stream/Views/Explore/StaticLogTable.tsx | 5 +-- .../Stream/Views/Explore/useLogsFetcher.ts | 9 ++--- 5 files changed, 19 insertions(+), 39 deletions(-) diff --git a/src/hooks/useQueryLogs.ts b/src/hooks/useQueryLogs.ts index 863b8baa..9ec7e5fe 100644 --- a/src/hooks/useQueryLogs.ts +++ b/src/hooks/useQueryLogs.ts @@ -1,13 +1,11 @@ -import { SortOrder, type Log, type LogsData, type LogsSearch } from '@/@types/parseable/api/query'; +import { type Log } from '@/@types/parseable/api/query'; import { getQueryLogsWithHeaders, getQueryResultWithHeaders } from '@/api/query'; import { StatusCodes } from 'http-status-codes'; -import useMountedState from './useMountedState'; import { useQuery } from 'react-query'; import { useCallback, useRef } from 'react'; import { useLogsStore, logsStoreReducers, LOAD_LIMIT, isJqSearch } from '@/pages/Stream/providers/LogsProvider'; import { useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; import _ from 'lodash'; -import { AxiosError } from 'axios'; import jqSearch from '@/utils/jqSearch'; import { useGetStreamSchema } from '@/hooks/useGetLogStreamSchema'; import { useStreamStore } from '@/pages/Stream/providers/StreamProvider'; @@ -33,16 +31,7 @@ export const useQueryLogs = () => { // data ref will always have the unfiltered data. // Only mutate it when data is fetched, otherwise read only const _dataRef = useRef(null); - const [error, setError] = useMountedState(null); - const [pageLogData, setPageLogData] = useMountedState(null); - const [querySearch, setQuerySearch] = useMountedState({ - search: '', - filters: {}, - sort: { - key: 'p_timestamp', - order: SortOrder.DESCENDING, - }, - }); + const [queryEngine] = useAppStore((store) => store.instanceConfig?.queryEngine); const [streamInfo] = useStreamStore((store) => store.info); const [currentStream] = useAppStore((store) => store.currentStream); const timePartitionColumn = _.get(streamInfo, 'time_partition', 'p_timestamp'); @@ -92,6 +81,7 @@ export const useQueryLogs = () => { const { isLoading: logsLoading, isRefetching: logsRefetching, + error: queryLogsError, refetch: getQueryData, } = useQuery( ['fetch-logs', defaultQueryOpts], @@ -123,33 +113,19 @@ export const useQueryLogs = () => { onSuccess: async (data) => { const logs = data.data; const isInvalidResponse = _.isEmpty(logs) || _.isNil(logs) || data.status !== StatusCodes.OK; - if (isInvalidResponse) return setError('Failed to query logs'); + if (isInvalidResponse) return; const { records, fields } = logs; const jqFilteredData = isJqSearch(instantSearchValue) ? await jqSearch(records, instantSearchValue) : []; setLogsStore((store) => setLogData(store, records, fields, jqFilteredData)); }, - onError: (data: AxiosError) => { - const errorMessage = data.response?.data as string; - setError(_.isString(errorMessage) && !_.isEmpty(errorMessage) ? errorMessage : 'Failed to query logs'); - }, }, ); - const resetData = () => { - _dataRef.current = null; - setPageLogData(null); - setError(null); - }; - return { - pageLogData, - setQuerySearch, getColumnFilters, - sort: querySearch.sort, - error, + queryLogsError, loading: logsLoading || logsRefetching, getQueryData, - resetData, }; }; diff --git a/src/pages/Stream/Views/Explore/JSONView.tsx b/src/pages/Stream/Views/Explore/JSONView.tsx index 2ccb7552..058459f4 100644 --- a/src/pages/Stream/Views/Explore/JSONView.tsx +++ b/src/pages/Stream/Views/Explore/JSONView.tsx @@ -18,6 +18,7 @@ import { IconCheck, IconCopy, IconSearch } from '@tabler/icons-react'; import { copyTextToClipboard } from '@/utils'; import { useStreamStore } from '../../providers/StreamProvider'; import timeRangeUtils from '@/utils/timeRangeUtils'; +import { AxiosError } from 'axios'; const { setInstantSearchValue, applyInstantSearch, applyJqSearch } = logsStoreReducers; @@ -187,7 +188,7 @@ const TableContainer = (props: { children: ReactNode }) => { }; const JsonView = (props: { - errorMessage: string | null; + errorMessage: AxiosError; hasNoData: boolean; showTable: boolean; isFetchingCount: boolean; @@ -224,7 +225,7 @@ const JsonView = (props: { ) ) : ( - + )}