From c1a5d607c989857194fd0b31db97fb91f40f15b2 Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Mon, 10 Jan 2022 18:37:12 +0200 Subject: [PATCH] Apply requested fixes. --- frontend/pages/dashboard/[dashboardId].js | 13 ++++------- frontend/src/components/CheckboxABI.js | 2 +- frontend/src/components/SubscriptionReport.js | 11 +++++---- frontend/src/core/hooks/useDashboard.js | 19 ++++++--------- frontend/src/core/hooks/usePresignedURL.js | 23 ++++++++++--------- 5 files changed, 31 insertions(+), 37 deletions(-) diff --git a/frontend/pages/dashboard/[dashboardId].js b/frontend/pages/dashboard/[dashboardId].js index 86ed64bc..4f611a8c 100644 --- a/frontend/pages/dashboard/[dashboardId].js +++ b/frontend/pages/dashboard/[dashboardId].js @@ -40,7 +40,6 @@ const Analytics = () => { const router = useRouter(); const overlay = useContext(OverlayContext); const { dashboardId } = router.params; - const [refreshingStatus, setRefreshingStatus] = useState(false); const { dashboardCache, dashboardLinksCache, @@ -89,13 +88,11 @@ const Analytics = () => { const plotMinW = "250px"; - const referesh_graf = function () { + const referesh_charts = () => { refreshDashboard.mutate({ dashboardId: dashboardCache.data.id, - setStatus: setRefreshingStatus, timeRange: timeRange, }); - setRefreshingStatus(true); }; return ( @@ -159,13 +156,15 @@ const Analytics = () => { icon={} /> } variant="ghost" colorScheme="green" size="sm" onClick={() => { - referesh_graf(); + referesh_charts(); }} /> @@ -203,8 +202,6 @@ const Analytics = () => { presignedRequest={s3PresignedURLs[timeRange]} id={dashboardId} refetchLinks={dashboardLinksCache.refetch} - refreshingStatus={refreshingStatus} - setRefreshingStatus={setRefreshingStatus} /> ); diff --git a/frontend/src/components/CheckboxABI.js b/frontend/src/components/CheckboxABI.js index 8a830c62..5c79b73d 100644 --- a/frontend/src/components/CheckboxABI.js +++ b/frontend/src/components/CheckboxABI.js @@ -144,4 +144,4 @@ const SuggestABI = ({ subscriptionId, state }) => { const ChakraSuggestABI = chakra(SuggestABI); -export default ChakraSuggestABI; \ No newline at end of file +export default ChakraSuggestABI; diff --git a/frontend/src/components/SubscriptionReport.js b/frontend/src/components/SubscriptionReport.js index 48000dc1..58e5c92b 100644 --- a/frontend/src/components/SubscriptionReport.js +++ b/frontend/src/components/SubscriptionReport.js @@ -27,7 +27,7 @@ const SubscriptionReport = ({ refetchLinks, }) => { const { data, isLoading, failureCount, isFetching } = usePresignedURL({ - presignedRequest: presignedRequest, + ...presignedRequest, isEnabled: true, id: id, cacheType: `${timeRange} subscription_report`, @@ -104,10 +104,11 @@ const SubscriptionReport = ({ flexBasis={plotMinW} direction="column" > - {`Latest block number: ${data?.blocks_state.latest_labelled_block}`} + {`Latest block number: ${ + data?.blocks_state?.latest_labelled_block != undefined + ? data?.blocks_state?.latest_labelled_block + : "Not available" + }`} { ); const refreshDashboard = useMutation(DashboardService.refreshDashboard, { - onSuccess: (data, variables) => { - let new_state = {}; + onSuccess: (data) => { + let newData = {}; - let current_links_state = queryClient.getQueryData([ + let oldData = queryClient.getQueryData([ "dashboardLinks", { dashboardId: dashboardId }, ]); - new_state = current_links_state; + newData = oldData; Object.keys(data.data).map((subscription) => { Object.keys(data.data[subscription]).map((timeScale) => { - new_state.data[subscription][timeScale] = + newData.data[subscription][timeScale] = data.data[subscription][timeScale]; }); }); queryClient.setQueryData( ["dashboardLinks", { dashboardId: dashboardId }], - new_state + newData ); - variables.setStatus(false); }, - onError: (error, variables) => { - variables.setStatus(false); + onError: (error) => { toast(error.error, "error", "Fail"); }, - onSettled: () => { - dashboardsListCache.refetch(); - }, }); return { diff --git a/frontend/src/core/hooks/usePresignedURL.js b/frontend/src/core/hooks/usePresignedURL.js index 7be08423..b596c745 100644 --- a/frontend/src/core/hooks/usePresignedURL.js +++ b/frontend/src/core/hooks/usePresignedURL.js @@ -1,10 +1,11 @@ -import { useQuery, useQueryClient } from "react-query"; +import { useQuery } from "react-query"; import { queryCacheProps } from "./hookCommon"; import { useToast } from "."; import axios from "axios"; const usePresignedURL = ({ - presignedRequest, + url, + headers, cacheType, id, requestNewURLCallback, @@ -15,16 +16,16 @@ const usePresignedURL = ({ const getFromPresignedURL = async () => { let request_parameters = { - url: presignedRequest.url, + url: url, // You can uncomment this to use mockupsLibrary in development // url: `https://example.com/s3`, headers: {}, method: "GET", }; - if ("headers" in presignedRequest) { - Object.keys(presignedRequest.headers).map((key) => { - request_parameters["headers"][key] = presignedRequest.headers[key]; + if (headers != undefined) { + Object.keys(headers).map((key) => { + request_parameters["headers"][key] = headers[key]; }); } @@ -32,8 +33,8 @@ const usePresignedURL = ({ return response.data; }; - const { data, isLoading, error, failureCount, refetch, isFetching } = useQuery( - ["presignedURL", cacheType, id, presignedRequest.url], + const { data, isLoading, error, failureCount, isFetching } = useQuery( + ["presignedURL", cacheType, id, url], getFromPresignedURL, { ...queryCacheProps, @@ -41,7 +42,7 @@ const usePresignedURL = ({ refetchOnWindowFocus: false, refetchOnReconnect: false, staleTime: Infinity, - enabled: isEnabled && presignedRequest.url ? true : false, + enabled: isEnabled && url ? true : false, keepPreviousData: true, onSuccess: () => {}, onError: (e) => { @@ -51,6 +52,7 @@ const usePresignedURL = ({ ) { requestNewURLCallback(); } else if (e?.response?.status === 304) { + // If not modified. } else { !hideToastOn404 && toast(error, "error"); } @@ -63,8 +65,7 @@ const usePresignedURL = ({ isLoading, error, failureCount, - refetch, - isFetching + isFetching, }; };