fix(striker-ui): make node summary update periodically

main
Tsu-ba-me 9 months ago
parent 4d5d698a9c
commit ba9c65addc
  1. 15
      striker-ui/components/Anvils/AnvilSummary.tsx
  2. 13
      striker-ui/components/Anvils/AnvilSummaryList.tsx
  3. 6
      striker-ui/types/AnvilSummary.d.ts
  4. 5
      striker-ui/types/AnvilSummaryList.d.ts

@ -30,10 +30,13 @@ const MAP_TO_HOST_STATE_COLOUR: Record<string, string> = {
}; };
const AnvilSummary: FC<AnvilSummaryProps> = (props) => { const AnvilSummary: FC<AnvilSummaryProps> = (props) => {
const { anvilUuid } = props; const { anvilUuid, refreshInterval = 5000 } = props;
const { data: rAnvil, loading: loadingAnvil } = useFetch<AnvilListItem>( const { data: rAnvil, loading: loadingAnvil } = useFetch<AnvilListItem>(
`/anvil/${anvilUuid}`, `/anvil/${anvilUuid}`,
{
refreshInterval,
},
); );
const anvil = useMemo<APIAnvilDetail | undefined>( const anvil = useMemo<APIAnvilDetail | undefined>(
@ -43,6 +46,9 @@ const AnvilSummary: FC<AnvilSummaryProps> = (props) => {
const { data: cpu, loading: loadingCpu } = useFetch<AnvilCPU>( const { data: cpu, loading: loadingCpu } = useFetch<AnvilCPU>(
`/anvil/${anvilUuid}/cpu`, `/anvil/${anvilUuid}/cpu`,
{
refreshInterval,
},
); );
const cpuSubnodes = useMemo<AnvilCPU['hosts'][string][] | undefined>( const cpuSubnodes = useMemo<AnvilCPU['hosts'][string][] | undefined>(
@ -52,6 +58,9 @@ const AnvilSummary: FC<AnvilSummaryProps> = (props) => {
const { data: rMemory, loading: loadingMemory } = useFetch<AnvilMemory>( const { data: rMemory, loading: loadingMemory } = useFetch<AnvilMemory>(
`/anvil/${anvilUuid}/memory`, `/anvil/${anvilUuid}/memory`,
{
refreshInterval,
},
); );
const memory = useMemo<AnvilMemoryCalcable | undefined>( const memory = useMemo<AnvilMemoryCalcable | undefined>(
@ -60,7 +69,9 @@ const AnvilSummary: FC<AnvilSummaryProps> = (props) => {
); );
const { data: rStorages, loading: loadingStorages } = const { data: rStorages, loading: loadingStorages } =
useFetch<AnvilSharedStorage>(`/anvil/${anvilUuid}/store`); useFetch<AnvilSharedStorage>(`/anvil/${anvilUuid}/store`, {
refreshInterval,
});
const storages = useMemo<APIAnvilSharedStorageOverview | undefined>( const storages = useMemo<APIAnvilSharedStorageOverview | undefined>(
() => rStorages && toAnvilSharedStorageOverview(rStorages), () => rStorages && toAnvilSharedStorageOverview(rStorages),

@ -15,9 +15,11 @@ import Spinner from '../Spinner';
import { BodyText, HeaderText } from '../Text'; import { BodyText, HeaderText } from '../Text';
import useFetch from '../../hooks/useFetch'; import useFetch from '../../hooks/useFetch';
const AnvilSummaryList: FC = () => { const AnvilSummaryList: FC<AnvilSummaryListProps> = (props) => {
const { refreshInterval = 5000 } = props;
const { data: rawAnvils, loading: loadingAnvils } = const { data: rawAnvils, loading: loadingAnvils } =
useFetch<APIAnvilOverviewArray>('/anvil', { refreshInterval: 5000 }); useFetch<APIAnvilOverviewArray>('/anvil', { refreshInterval });
const anvils = useMemo<APIAnvilOverviewList | undefined>( const anvils = useMemo<APIAnvilOverviewList | undefined>(
() => rawAnvils && toAnvilOverviewList(rawAnvils), () => rawAnvils && toAnvilOverviewList(rawAnvils),
@ -48,7 +50,10 @@ const AnvilSummaryList: FC = () => {
</BodyText> </BodyText>
</InnerPanelHeader> </InnerPanelHeader>
<InnerPanelBody> <InnerPanelBody>
<AnvilSummary anvilUuid={uuid} /> <AnvilSummary
anvilUuid={uuid}
refreshInterval={refreshInterval}
/>
</InnerPanelBody> </InnerPanelBody>
</InnerPanel> </InnerPanel>
), ),
@ -68,7 +73,7 @@ const AnvilSummaryList: FC = () => {
}} }}
/> />
), ),
[anvils], [anvils, refreshInterval],
); );
return ( return (

@ -1,3 +1,7 @@
type AnvilSummaryProps = { type AnvilSummaryOptionalProps = {
refreshInterval?: number;
};
type AnvilSummaryProps = AnvilSummaryOptionalProps & {
anvilUuid: string; anvilUuid: string;
}; };

@ -0,0 +1,5 @@
type AnvilSummaryListOptionalProps = {
refreshInterval?: number;
};
type AnvilSummaryListProps = AnvilSummaryListOptionalProps;
Loading…
Cancel
Save