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; };