fix(striker-ui): add shared storage api response converter

main
Tsu-ba-me 1 year ago
parent 72ee08414a
commit 05438d39f4
  1. 8
      striker-ui/lib/api_converters/index.ts
  2. 29
      striker-ui/lib/api_converters/toAnvilSharedStorageOverview.ts
  3. 17
      striker-ui/types/APIAnvil.d.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,
};

@ -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<APIAnvilSharedStorageOverview>(
(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;

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

Loading…
Cancel
Save