From 6a3f7197e951f4e341fa4faace9ba3913255b17e Mon Sep 17 00:00:00 2001 From: Ben Carver Date: Fri, 1 Mar 2024 12:05:44 -0500 Subject: [PATCH] Added refresh buttons to the cards. --- src/app/Components/KernelList.tsx | 45 ++++++++++++------------- src/app/Components/KernelSpecList.tsx | 43 +++++++++++++----------- src/app/Components/NodeList.tsx | 47 ++++++++++++++------------- 3 files changed, 72 insertions(+), 63 deletions(-) diff --git a/src/app/Components/KernelList.tsx b/src/app/Components/KernelList.tsx index aed37cdd..07857af7 100644 --- a/src/app/Components/KernelList.tsx +++ b/src/app/Components/KernelList.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useRef } from 'react'; import { Badge, Button, @@ -56,6 +56,7 @@ import { SkullIcon, SpinnerIcon, StopCircleIcon, + SyncIcon, } from '@patternfly/react-icons'; // Map from kernel status to the associated icon. @@ -244,27 +245,29 @@ export const KernelList: React.FunctionComponent = () => { }; }, [isStatusMenuOpen, statusMenuRef]); - const [kernels, setKernels] = React.useState([]); - useEffect(() => { - let ignoreResponse = false; - async function fetchKernels() { - try { - console.log('Refreshing kernels.'); + const ignoreResponse = useRef(false); + async function fetchKernels() { + try { + console.log('Refreshing kernels.'); - // Make a network request to the backend. The server infrastructure handles proxying/routing the request to the correct host. - // We're specifically targeting the API endpoint I setup called "kernels". - const response = await fetch('/api/kernel'); + // Make a network request to the backend. The server infrastructure handles proxying/routing the request to the correct host. + // We're specifically targeting the API endpoint I setup called "kernels". + const response = await fetch('/api/kernel'); - const respKernels: DistributedJupyterKernel[] = await response.json(); + const respKernels: DistributedJupyterKernel[] = await response.json(); - if (!ignoreResponse) { - console.log('Received kernels: ' + JSON.stringify(respKernels)); - setKernels(respKernels); - } - } catch (e) { - console.error(e); + if (!ignoreResponse.current) { + console.log('Received kernels: ' + JSON.stringify(respKernels)); + setKernels(respKernels); } + } catch (e) { + console.error(e); } + } + + const [kernels, setKernels] = React.useState([]); + useEffect(() => { + ignoreResponse.current = false; fetchKernels(); @@ -272,7 +275,7 @@ export const KernelList: React.FunctionComponent = () => { setInterval(fetchKernels, 30000); return () => { - ignoreResponse = true; + ignoreResponse.current = true; }; }, []); @@ -437,9 +440,7 @@ export const KernelList: React.FunctionComponent = () => { ); - // const cardHeaderActions = ( - - // ) + const cardHeaderActions =