From 4d0d39891a5554d0af500c3c400e1e6a3a42c859 Mon Sep 17 00:00:00 2001 From: Youssef Date: Thu, 10 Feb 2022 09:23:11 +0100 Subject: [PATCH] fix: update PR based on feedback --- .../api/getters/useApplication/useApplication.ts | 11 ++++++----- .../api/getters/useApplications/useApplications.ts | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/frontend/src/hooks/api/getters/useApplication/useApplication.ts b/frontend/src/hooks/api/getters/useApplication/useApplication.ts index 6802f3f64a..7cc8344ca0 100644 --- a/frontend/src/hooks/api/getters/useApplication/useApplication.ts +++ b/frontend/src/hooks/api/getters/useApplication/useApplication.ts @@ -4,8 +4,9 @@ import { formatApiPath } from '../../../../utils/format-path'; import handleErrorResponses from '../httpErrorResponseHandler'; const useApplication = (name: string, options: SWRConfiguration = {}) => { + const path = formatApiPath(`api/admin/metrics/applications/${name}`); + const fetcher = async () => { - const path = formatApiPath(`api/admin/metrics/applications/${name}`); return fetch(path, { method: 'GET', }) @@ -13,16 +14,16 @@ const useApplication = (name: string, options: SWRConfiguration = {}) => { .then(res => res.json()); }; - const FEATURE_CACHE_KEY = `api/admin/metrics/applications/${name}`; + const APPLICATION_CACHE_KEY = `api/admin/metrics/applications/${name}`; - const { data, error } = useSWR(FEATURE_CACHE_KEY, fetcher, { + const { data, error } = useSWR(APPLICATION_CACHE_KEY, fetcher, { ...options, }); const [loading, setLoading] = useState(!error && !data); const refetchApplication = () => { - mutate(FEATURE_CACHE_KEY); + mutate(APPLICATION_CACHE_KEY); }; useEffect(() => { @@ -43,7 +44,7 @@ const useApplication = (name: string, options: SWRConfiguration = {}) => { error, loading, refetchApplication, - FEATURE_CACHE_KEY, + APPLICATION_CACHE_KEY, }; }; diff --git a/frontend/src/hooks/api/getters/useApplications/useApplications.ts b/frontend/src/hooks/api/getters/useApplications/useApplications.ts index 13efed5a8d..c2c4ea1464 100644 --- a/frontend/src/hooks/api/getters/useApplications/useApplications.ts +++ b/frontend/src/hooks/api/getters/useApplications/useApplications.ts @@ -3,26 +3,27 @@ import { useState, useEffect } from 'react'; import { formatApiPath } from '../../../../utils/format-path'; import handleErrorResponses from '../httpErrorResponseHandler'; +const path = formatApiPath('api/admin/metrics/applications'); + const useApplications = (options: SWRConfiguration = {}) => { const fetcher = async () => { - const path = formatApiPath('api/admin/metrics/applications'); return fetch(path, { method: 'GET', }) - .then(handleErrorResponses('Context data')) + .then(handleErrorResponses('Applications data')) .then(res => res.json()); }; - const FEATURE_CACHE_KEY = 'api/admin/metrics/applications'; + const APPLICATIONS_CACHE_KEY = 'api/admin/metrics/applications'; - const { data, error } = useSWR(FEATURE_CACHE_KEY, fetcher, { + const { data, error } = useSWR(APPLICATIONS_CACHE_KEY, fetcher, { ...options, }); const [loading, setLoading] = useState(!error && !data); const refetchApplications = () => { - mutate(FEATURE_CACHE_KEY); + mutate(APPLICATIONS_CACHE_KEY); }; useEffect(() => { @@ -34,7 +35,7 @@ const useApplications = (options: SWRConfiguration = {}) => { error, loading, refetchApplications, - FEATURE_CACHE_KEY, + APPLICATIONS_CACHE_KEY, }; };