From bd6bc7f7f68abe613387815ac44b26f084003f69 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 2 Oct 2023 20:41:09 -0400 Subject: [PATCH] fix(striker-ui): add api converter to anvil detail --- striker-ui/lib/api_converters/index.ts | 2 + .../lib/api_converters/toAnvilDetail.ts | 37 +++++++++++++++++++ striker-ui/types/APIAnvil.d.ts | 15 ++++++++ 3 files changed, 54 insertions(+) create mode 100644 striker-ui/lib/api_converters/toAnvilDetail.ts diff --git a/striker-ui/lib/api_converters/index.ts b/striker-ui/lib/api_converters/index.ts index 7ce821fe..73268108 100644 --- a/striker-ui/lib/api_converters/index.ts +++ b/striker-ui/lib/api_converters/index.ts @@ -1,9 +1,11 @@ +import toAnvilDetail from './toAnvilDetail'; import toAnvilMemoryCalcable from './toAnvilMemoryCalcable'; import toAnvilOverviewHostList from './toAnvilOverviewHostList'; import toAnvilOverviewList from './toAnvilOverviewList'; import toAnvilSharedStorageOverview from './toAnvilSharedStorageOverview'; export { + toAnvilDetail, toAnvilMemoryCalcable, toAnvilOverviewHostList, toAnvilOverviewList, diff --git a/striker-ui/lib/api_converters/toAnvilDetail.ts b/striker-ui/lib/api_converters/toAnvilDetail.ts new file mode 100644 index 00000000..fcf23e4d --- /dev/null +++ b/striker-ui/lib/api_converters/toAnvilDetail.ts @@ -0,0 +1,37 @@ +const toAnvilDetail = (data: AnvilListItem): APIAnvilDetail => { + const { + anvil_name: anvilName, + anvil_state: anvilState, + anvil_uuid: anvilUuid, + hosts: rHosts, + } = data; + + const hosts = rHosts.reduce((previous, current) => { + const { + host_name: hostName, + host_uuid: hostUuid, + maintenance_mode: maintenance, + state, + state_percent: stateProgress, + } = current; + + previous[hostUuid] = { + name: hostName, + maintenance, + state, + stateProgress, + uuid: hostUuid, + }; + + return previous; + }, {}); + + return { + hosts, + name: anvilName, + state: anvilState, + uuid: anvilUuid, + }; +}; + +export default toAnvilDetail; diff --git a/striker-ui/types/APIAnvil.d.ts b/striker-ui/types/APIAnvil.d.ts index 37e9cdb4..4276e3c7 100644 --- a/striker-ui/types/APIAnvil.d.ts +++ b/striker-ui/types/APIAnvil.d.ts @@ -129,6 +129,21 @@ type APIAnvilOverview = { uuid: string; }; +type APIAnvilDetail = { + hosts: { + [uuid: string]: { + maintenance: boolean; + name: string; + state: AnvilStatusHost['state']; + stateProgress: number; + uuid: string; + }; + }; + name: string; + state: AnvilStatus['anvil_state']; + uuid: string; +}; + type APIAnvilOverviewList = { [uuid: string]: APIAnvilOverview; };