From 3af144d34bd8d5d2fd56db30f3c25ce6736cbebf Mon Sep 17 00:00:00 2001 From: Praveen K B <30530587+praveen5959@users.noreply.github.com> Date: Sat, 9 Nov 2024 09:13:05 +0530 Subject: [PATCH] fix: missing query in API call on dashboard page (#362) --------- Co-authored-by: praveen5959 --- src/hooks/useDashboards.tsx | 10 +++++++--- src/pages/Dashboards/CreateTileForm.tsx | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hooks/useDashboards.tsx b/src/hooks/useDashboards.tsx index 1b917688..b5877bd5 100644 --- a/src/hooks/useDashboards.tsx +++ b/src/hooks/useDashboards.tsx @@ -12,12 +12,13 @@ import { UpdateDashboardType, } from '@/@types/parseable/api/dashboards'; import { useSearchParams } from 'react-router-dom'; +import { sanitiseSqlString } from '@/utils/sanitiseSqlString'; const { setDashboards, setTileData, selectDashboard } = dashboardsStoreReducers; export const useDashboardsQuery = (opts: { updateTimeRange?: (dashboard: Dashboard) => void }) => { const [activeDashboard, setDashboardsStore] = useDashboardsStore((store) => store.activeDashboard); - const [searchParams] = useSearchParams() + const [searchParams] = useSearchParams(); const { isError: fetchDashaboardsError, @@ -156,10 +157,10 @@ export const useTileQuery = (opts: { const [, setDashboardsStore] = useDashboardsStore((_store) => null); const { query, startTime, endTime, tileId, enabled = true } = opts; const { isLoading, isFetching, isError, refetch } = useQuery( - [tileId, query, startTime, endTime], + [tileId, startTime, endTime], () => getQueryData({ - query, + query: sanitiseSqlString(query, false, 100), startTime, endTime, }), @@ -169,6 +170,9 @@ export const useTileQuery = (opts: { if (tileId) { setDashboardsStore((store) => setTileData(store, tileId, tileData)); } + if (opts.onSuccess) { + opts.onSuccess(tileData); + } }, onError: (error: AxiosError) => { if (isAxiosError(error) && error.response) { diff --git a/src/pages/Dashboards/CreateTileForm.tsx b/src/pages/Dashboards/CreateTileForm.tsx index a77b3ea0..5100633d 100644 --- a/src/pages/Dashboards/CreateTileForm.tsx +++ b/src/pages/Dashboards/CreateTileForm.tsx @@ -328,7 +328,7 @@ const Query = (props: { form: TileFormType; onChangeValue: (key: string, value: const { refetch, isLoading } = useTileQuery({ onSuccess: onFetchTileSuccess, - query: '', // Initial query (will be updated in refetch) + query, startTime: timeRange.startTime, endTime: timeRange.endTime, enabled: false,