fix(striker-ui): isolate fetched data conversion

main
Tsu-ba-me 1 year ago
parent 78cbdeb123
commit ac28ea88df
  1. 36
      striker-ui/components/Files/ManageFilePanel.tsx
  2. 5
      striker-ui/lib/api_converters/index.ts
  3. 15
      striker-ui/lib/api_converters/toAnvilMemoryCalcable.ts
  4. 13
      striker-ui/lib/api_converters/toAnvilOverviewHostList.ts
  5. 28
      striker-ui/lib/api_converters/toAnvilOverviewList.ts
  6. 16
      striker-ui/types/APIAnvil.d.ts

@ -6,6 +6,7 @@ import { UPLOAD_FILE_TYPES } from '../../lib/consts/UPLOAD_FILE_TYPES';
import AddFileForm from './AddFileForm';
import api from '../../lib/api';
import { toAnvilOverviewList } from '../../lib/api_converters';
import ConfirmDialog from '../ConfirmDialog';
import { DialogWithHeader } from '../Dialog';
import Divider from '../Divider';
@ -23,41 +24,6 @@ import useConfirmDialogProps from '../../hooks/useConfirmDialogProps';
import useFetch from '../../hooks/useFetch';
import useProtectedState from '../../hooks/useProtectedState';
const toAnvilOverviewHostList = (
data: APIAnvilOverviewArray[number]['hosts'],
) =>
data.reduce<APIAnvilOverview['hosts']>(
(previous, { hostName: name, hostType: type, hostUUID: uuid }) => {
previous[uuid] = { name, type, uuid };
return previous;
},
{},
);
const toAnvilOverviewList = (data: APIAnvilOverviewArray) =>
data.reduce<APIAnvilOverviewList>(
(
previous,
{
anvilDescription: description,
anvilName: name,
anvilUUID: uuid,
hosts,
},
) => {
previous[uuid] = {
description,
hosts: toAnvilOverviewHostList(hosts),
name,
uuid,
};
return previous;
},
{},
);
const toFileOverviewList = (rows: string[][]) =>
rows.reduce<APIFileOverviewList>((previous, row) => {
const [uuid, name, size, type, checksum] = row;

@ -0,0 +1,5 @@
import toAnvilMemoryCalcable from './toAnvilMemoryCalcable';
import toAnvilOverviewHostList from './toAnvilOverviewHostList';
import toAnvilOverviewList from './toAnvilOverviewList';
export { toAnvilMemoryCalcable, toAnvilOverviewHostList, toAnvilOverviewList };

@ -0,0 +1,15 @@
const toAnvilMemoryCalcable = (data: AnvilMemory): AnvilMemoryCalcable => {
const { allocated: rAllocated, reserved: rReserved, total: rTotal } = data;
const allocated = BigInt(rAllocated);
const reserved = BigInt(rReserved);
const total = BigInt(rTotal);
return {
allocated,
reserved,
total,
};
};
export default toAnvilMemoryCalcable;

@ -0,0 +1,13 @@
const toAnvilOverviewHostList = (
data: APIAnvilOverviewArray[number]['hosts'],
): APIAnvilOverview['hosts'] =>
data.reduce<APIAnvilOverview['hosts']>(
(previous, { hostName: name, hostType: type, hostUUID: uuid }) => {
previous[uuid] = { name, type, uuid };
return previous;
},
{},
);
export default toAnvilOverviewHostList;

@ -0,0 +1,28 @@
import toAnvilOverviewHostList from './toAnvilOverviewHostList';
const toAnvilOverviewList = (
data: APIAnvilOverviewArray,
): APIAnvilOverviewList =>
data.reduce<APIAnvilOverviewList>(
(
previous,
{
anvilDescription: description,
anvilName: name,
anvilUUID: uuid,
hosts,
},
) => {
previous[uuid] = {
description,
hosts: toAnvilOverviewHostList(hosts),
name,
uuid,
};
return previous;
},
{},
);
export default toAnvilOverviewList;

@ -1,6 +1,16 @@
type AnvilCPU = {
allocated: number;
cores: number;
hosts: {
[hostUuid: string]: {
cores: number;
model: string;
name: string;
threads: number;
uuid: string;
vendor: string;
};
};
threads: number;
};
@ -10,6 +20,12 @@ type AnvilMemory = {
total: string;
};
type AnvilMemoryCalcable = {
allocated: bigint;
reserved: bigint;
total: bigint;
};
type AnvilNetworkBondLink = {
link_name: string;
link_uuid: string;

Loading…
Cancel
Save