From 8367a421c1163c110e94f06769e79de699d90b96 Mon Sep 17 00:00:00 2001 From: Josue Date: Fri, 30 Apr 2021 12:59:03 -0400 Subject: [PATCH] refactor: remove unnecessary parameter in the fetching tool --- striker-ui/components/Anvils/index.tsx | 4 ++-- striker-ui/components/CPU.tsx | 3 +-- striker-ui/components/Memory.tsx | 3 +-- striker-ui/components/Network/Network.tsx | 3 +-- striker-ui/components/Nodes/index.tsx | 3 +-- striker-ui/components/Servers.tsx | 3 +-- striker-ui/components/SharedStorage/SharedStorage.tsx | 3 +-- striker-ui/components/Storage.tsx | 3 +-- striker-ui/lib/fetchers/periodicFetch.ts | 5 ++--- striker-ui/pages/index.tsx | 3 +-- 10 files changed, 12 insertions(+), 21 deletions(-) diff --git a/striker-ui/components/Anvils/index.tsx b/striker-ui/components/Anvils/index.tsx index 1d3dc366..cf274aa6 100644 --- a/striker-ui/components/Anvils/index.tsx +++ b/striker-ui/components/Anvils/index.tsx @@ -10,8 +10,8 @@ const Anvils = ({ list }: { list: AnvilList | undefined }): JSX.Element => { list?.anvils.forEach((anvil: AnvilListItem) => { const { data } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_status?anvil_uuid=`, - anvil.anvil_uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_status?anvil_uuid= + ${anvil.anvil_uuid}`, ); /* eslint-disable no-param-reassign */ anvils.push({ diff --git a/striker-ui/components/CPU.tsx b/striker-ui/components/CPU.tsx index 7774566b..7d0ae57d 100644 --- a/striker-ui/components/CPU.tsx +++ b/striker-ui/components/CPU.tsx @@ -10,8 +10,7 @@ const CPU = (): JSX.Element => { const { uuid } = useContext(AnvilContext); const { data, isLoading } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_cpu?anvil_uuid=`, - uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_cpu?anvil_uuid=${uuid}`, ); const cpuData = diff --git a/striker-ui/components/Memory.tsx b/striker-ui/components/Memory.tsx index c7dd189d..dff7e3df 100644 --- a/striker-ui/components/Memory.tsx +++ b/striker-ui/components/Memory.tsx @@ -10,8 +10,7 @@ import { AnvilContext } from './AnvilContext'; const Memory = (): JSX.Element => { const { uuid } = useContext(AnvilContext); const { data, isLoading } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_memory?anvil_uuid=`, - uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_memory?anvil_uuid=${uuid}`, ); const memoryData = isLoading || !data ? { total: 0, free: 0 } : data; diff --git a/striker-ui/components/Network/Network.tsx b/striker-ui/components/Network/Network.tsx index 17e1f7cf..7c1ec91c 100644 --- a/striker-ui/components/Network/Network.tsx +++ b/striker-ui/components/Network/Network.tsx @@ -47,8 +47,7 @@ const Network = (): JSX.Element => { const classes = useStyles(); const { data } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_network?anvil_uuid=`, - uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_network?anvil_uuid=${uuid}`, ); const processed = processNetworkData(data); diff --git a/striker-ui/components/Nodes/index.tsx b/striker-ui/components/Nodes/index.tsx index 1a6eba0a..145f00be 100644 --- a/striker-ui/components/Nodes/index.tsx +++ b/striker-ui/components/Nodes/index.tsx @@ -9,8 +9,7 @@ const Nodes = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => { const { uuid } = useContext(AnvilContext); const { data } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_status?anvil_uuid=`, - uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_status?anvil_uuid=${uuid}`, ); return ( diff --git a/striker-ui/components/Servers.tsx b/striker-ui/components/Servers.tsx index 3f6aac58..d099a9a0 100644 --- a/striker-ui/components/Servers.tsx +++ b/striker-ui/components/Servers.tsx @@ -50,8 +50,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => { const classes = useStyles(); const { data } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_servers?anvil_uuid=`, - uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_servers?anvil_uuid=${uuid}`, ); return ( diff --git a/striker-ui/components/SharedStorage/SharedStorage.tsx b/striker-ui/components/SharedStorage/SharedStorage.tsx index 9f528ec8..fb86603b 100644 --- a/striker-ui/components/SharedStorage/SharedStorage.tsx +++ b/striker-ui/components/SharedStorage/SharedStorage.tsx @@ -27,8 +27,7 @@ const SharedStorage = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => { const classes = useStyles(); const { uuid } = useContext(AnvilContext); const { data } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_shared_storage?anvil_uuid=`, - uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_shared_storage?anvil_uuid=${uuid}`, ); return ( diff --git a/striker-ui/components/Storage.tsx b/striker-ui/components/Storage.tsx index 32670a79..421e34c0 100644 --- a/striker-ui/components/Storage.tsx +++ b/striker-ui/components/Storage.tsx @@ -7,8 +7,7 @@ import PeriodicFetch from '../lib/fetchers/periodicFetch'; const Storage = ({ uuid }: { uuid: string }): JSX.Element => { const { data, isLoading } = PeriodicFetch( - `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_memory?anvil_uuid=`, - uuid, + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_memory?anvil_uuid=${uuid}`, ); const memoryData = isLoading || !data ? { total: 0, free: 0 } : data; diff --git a/striker-ui/lib/fetchers/periodicFetch.ts b/striker-ui/lib/fetchers/periodicFetch.ts index 6354c775..5379f462 100644 --- a/striker-ui/lib/fetchers/periodicFetch.ts +++ b/striker-ui/lib/fetchers/periodicFetch.ts @@ -3,10 +3,9 @@ import fetcher from './fetchJSON'; const PeriodicFetch = ( url: string, - uuid: string, - refreshInterval = 2000, + refreshInterval = 5000, ): GetResponses => { - const { data, error } = useSWR(`${url}${uuid}`, fetcher, { + const { data, error } = useSWR(`${url}`, fetcher, { refreshInterval, }); return { diff --git a/striker-ui/pages/index.tsx b/striker-ui/pages/index.tsx index 17529570..540d8b5d 100644 --- a/striker-ui/pages/index.tsx +++ b/striker-ui/pages/index.tsx @@ -48,8 +48,7 @@ const Home = (): JSX.Element => { const classes = useStyles(); const { data } = PeriodicFetch( - process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080', - '/anvils/get_anvils', + `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_anvils`, ); return (