From 0e1098d8938985f28915a908722bf4369803e4b8 Mon Sep 17 00:00:00 2001 From: Josue Date: Thu, 27 May 2021 19:17:13 -0400 Subject: [PATCH] refactor: update host state following specs --- .../components/Anvils/SelectedAnvil.tsx | 5 +++-- striker-ui/components/Hosts/AnvilHost.tsx | 19 ++++++++----------- striker-ui/components/Hosts/index.tsx | 2 +- striker-ui/types/AnvilStatus.d.ts | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/striker-ui/components/Anvils/SelectedAnvil.tsx b/striker-ui/components/Anvils/SelectedAnvil.tsx index 32d18623..7c1130fb 100644 --- a/striker-ui/components/Anvils/SelectedAnvil.tsx +++ b/striker-ui/components/Anvils/SelectedAnvil.tsx @@ -35,8 +35,9 @@ const selectDecorator = (state: string): Colours => { const isAnvilOn = (anvil: AnvilListItem): boolean => !( - anvil.hosts.findIndex(({ state }: AnvilStatusHost) => state !== 'off') === - -1 + anvil.hosts.findIndex( + ({ state }: AnvilStatusHost) => state !== 'offline', + ) === -1 ); const SelectedAnvil = ({ list }: { list: AnvilListItem[] }): JSX.Element => { diff --git a/striker-ui/components/Hosts/AnvilHost.tsx b/striker-ui/components/Hosts/AnvilHost.tsx index b4c01b3e..b6642f5f 100644 --- a/striker-ui/components/Hosts/AnvilHost.tsx +++ b/striker-ui/components/Hosts/AnvilHost.tsx @@ -50,15 +50,12 @@ const selectStateMessage = (regex: RegExp, message: string): string => { const selectDecorator = (state: string): Colours => { switch (state) { - case 'ready': + case 'online': return 'ok'; - case 'off': + case 'offline': return 'off'; - case 'accessible': - case 'on': - return 'warning'; default: - return 'error'; + return 'warning'; } }; @@ -103,11 +100,11 @@ const AnvilHost = ({ putJSON('/set_power', { host_uuid: host.host_uuid, - is_on: !(host.state === 'ready'), + is_on: !(host.state === 'online'), }) } /> @@ -117,18 +114,18 @@ const AnvilHost = ({ putJSON('/set_membership', { host_uuid: host.host_uuid, - is_member: !(host.state === 'ready'), + is_member: !(host.state === 'online'), }) } /> - {host.state !== 'ready' && ( + {host.state !== 'online' && ( <> diff --git a/striker-ui/components/Hosts/index.tsx b/striker-ui/components/Hosts/index.tsx index 2a6d9233..dc9d525b 100644 --- a/striker-ui/components/Hosts/index.tsx +++ b/striker-ui/components/Hosts/index.tsx @@ -14,7 +14,7 @@ const Hosts = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => { return ( - + {anvil.findIndex((a) => a.anvil_uuid === uuid) !== -1 && data && ( a.anvil_uuid === uuid)].hosts.map( diff --git a/striker-ui/types/AnvilStatus.d.ts b/striker-ui/types/AnvilStatus.d.ts index 4a2e2d49..013a104e 100644 --- a/striker-ui/types/AnvilStatus.d.ts +++ b/striker-ui/types/AnvilStatus.d.ts @@ -1,5 +1,5 @@ declare type AnvilStatusHost = { - state: 'unknown' | 'off' | 'on' | 'accessible' | 'ready'; + state: 'offline' | 'booted' | 'crmd' | 'in_ccm' | 'online'; host_uuid: string; host_name: string; state_percent: number;