diff --git a/striker-ui/lib/api_converters/index.ts b/striker-ui/lib/api_converters/index.ts index 58ec1845..7ce821fe 100644 --- a/striker-ui/lib/api_converters/index.ts +++ b/striker-ui/lib/api_converters/index.ts @@ -1,5 +1,11 @@ import toAnvilMemoryCalcable from './toAnvilMemoryCalcable'; import toAnvilOverviewHostList from './toAnvilOverviewHostList'; import toAnvilOverviewList from './toAnvilOverviewList'; +import toAnvilSharedStorageOverview from './toAnvilSharedStorageOverview'; -export { toAnvilMemoryCalcable, toAnvilOverviewHostList, toAnvilOverviewList }; +export { + toAnvilMemoryCalcable, + toAnvilOverviewHostList, + toAnvilOverviewList, + toAnvilSharedStorageOverview, +}; diff --git a/striker-ui/lib/api_converters/toAnvilSharedStorageOverview.ts b/striker-ui/lib/api_converters/toAnvilSharedStorageOverview.ts new file mode 100644 index 00000000..74e2e099 --- /dev/null +++ b/striker-ui/lib/api_converters/toAnvilSharedStorageOverview.ts @@ -0,0 +1,29 @@ +const toAnvilSharedStorageOverview = ( + data: AnvilSharedStorage, +): APIAnvilSharedStorageOverview => { + const { storage_groups, total_free, total_size } = data; + + const totalFree = BigInt(total_free); + const totalSize = BigInt(total_size); + + return storage_groups.reduce( + (previous, current) => { + const { + storage_group_free: rFree, + storage_group_name: name, + storage_group_total: rSize, + storage_group_uuid: uuid, + } = current; + + const free = BigInt(rFree); + const size = BigInt(rSize); + + previous.storageGroups[uuid] = { free, name, size, uuid }; + + return previous; + }, + { storageGroups: {}, totalFree, totalSize }, + ); +}; + +export default toAnvilSharedStorageOverview; diff --git a/striker-ui/types/APIAnvil.d.ts b/striker-ui/types/APIAnvil.d.ts index ee9d4403..37e9cdb4 100644 --- a/striker-ui/types/APIAnvil.d.ts +++ b/striker-ui/types/APIAnvil.d.ts @@ -78,6 +78,8 @@ type AnvilSharedStorageGroup = { type AnvilSharedStorage = { storage_groups: AnvilSharedStorageGroup[]; + total_size: string; + total_free: string; }; type AnvilStatusHost = { @@ -130,3 +132,18 @@ type APIAnvilOverview = { type APIAnvilOverviewList = { [uuid: string]: APIAnvilOverview; }; + +type APIAnvilStorageGroupCalcable = { + free: bigint; + name: string; + size: bigint; + uuid: string; +}; + +type APIAnvilSharedStorageOverview = { + storageGroups: { + [uuid: string]: APIAnvilStorageGroupCalcable; + }; + totalFree: bigint; + totalSize: bigint; +};