You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.3 KiB
129 lines
3.3 KiB
2 years ago
|
import { ReactElement, useMemo } from 'react';
|
||
|
|
||
2 years ago
|
import AnHostInputGroup from './AnHostInputGroup';
|
||
2 years ago
|
import Grid from '../Grid';
|
||
|
|
||
2 years ago
|
const INPUT_ID_PREFIX_AN_HOST_CONFIG = 'an-host-config-input';
|
||
2 years ago
|
|
||
2 years ago
|
const INPUT_GROUP_ID_PREFIX_AHC = `${INPUT_ID_PREFIX_AN_HOST_CONFIG}-group`;
|
||
|
const INPUT_GROUP_CELL_ID_PREFIX_AHC = `${INPUT_GROUP_ID_PREFIX_AHC}-cell`;
|
||
2 years ago
|
|
||
|
const DEFAULT_HOST_LIST: ManifestHostList = {
|
||
|
node1: {
|
||
2 years ago
|
hostName: '',
|
||
2 years ago
|
hostNumber: 1,
|
||
|
hostType: 'node',
|
||
|
},
|
||
|
node2: {
|
||
2 years ago
|
hostName: '',
|
||
2 years ago
|
hostNumber: 2,
|
||
|
hostType: 'node',
|
||
|
},
|
||
|
};
|
||
|
|
||
2 years ago
|
const AnHostConfigInputGroup = <M extends MapToInputTestID>({
|
||
2 years ago
|
formUtils,
|
||
2 years ago
|
knownFences = {},
|
||
|
knownUpses = {},
|
||
2 years ago
|
networkListEntries,
|
||
|
previous: { hosts: previousHostList = DEFAULT_HOST_LIST } = {},
|
||
2 years ago
|
}: AnHostConfigInputGroupProps<M>): ReactElement => {
|
||
2 years ago
|
const hostListEntries = useMemo(
|
||
|
() => Object.entries(previousHostList),
|
||
|
[previousHostList],
|
||
|
);
|
||
2 years ago
|
const knownFenceListValues = useMemo(
|
||
|
() => Object.values(knownFences),
|
||
|
[knownFences],
|
||
|
);
|
||
|
const knownUpsListValues = useMemo(
|
||
|
() => Object.values(knownUpses),
|
||
|
[knownUpses],
|
||
|
);
|
||
2 years ago
|
|
||
|
const hostListGridLayout = useMemo<GridLayout>(
|
||
|
() =>
|
||
|
hostListEntries.reduce<GridLayout>(
|
||
|
(previous, [hostId, previousHostArgs]) => {
|
||
|
const {
|
||
2 years ago
|
fences: previousFenceList = {},
|
||
2 years ago
|
hostNumber,
|
||
|
hostType,
|
||
2 years ago
|
networks: previousNetworkList = {},
|
||
2 years ago
|
upses: previousUpsList = {},
|
||
2 years ago
|
}: ManifestHost = previousHostArgs;
|
||
|
|
||
2 years ago
|
const fences = knownFenceListValues.reduce<ManifestHostFenceList>(
|
||
|
(fenceList, { fenceName }) => {
|
||
|
const { fencePort = '' } = previousFenceList[fenceName] ?? {};
|
||
2 years ago
|
|
||
2 years ago
|
fenceList[fenceName] = { fenceName, fencePort };
|
||
2 years ago
|
|
||
|
return fenceList;
|
||
|
},
|
||
|
{},
|
||
|
);
|
||
2 years ago
|
const networks = networkListEntries.reduce<ManifestHostNetworkList>(
|
||
|
(networkList, [networkId, { networkNumber, networkType }]) => {
|
||
|
const { networkIp = '' } = previousNetworkList[networkId] ?? {};
|
||
|
|
||
|
networkList[networkId] = {
|
||
|
networkIp,
|
||
|
networkNumber,
|
||
|
networkType,
|
||
|
};
|
||
|
|
||
|
return networkList;
|
||
|
},
|
||
|
{},
|
||
|
);
|
||
2 years ago
|
const upses = knownUpsListValues.reduce<ManifestHostUpsList>(
|
||
|
(upsList, { upsName }) => {
|
||
|
const { isUsed = true } = previousUpsList[upsName] ?? {};
|
||
|
|
||
2 years ago
|
upsList[upsName] = { isUsed, upsName };
|
||
2 years ago
|
|
||
|
return upsList;
|
||
|
},
|
||
|
{},
|
||
|
);
|
||
|
|
||
2 years ago
|
const cellId = `${INPUT_GROUP_CELL_ID_PREFIX_AHC}-${hostId}`;
|
||
2 years ago
|
const hostLabel = `${hostType} ${hostNumber}`;
|
||
|
|
||
|
previous[cellId] = {
|
||
|
children: (
|
||
2 years ago
|
<AnHostInputGroup
|
||
2 years ago
|
formUtils={formUtils}
|
||
|
hostLabel={hostLabel}
|
||
2 years ago
|
previous={{ fences, networks, upses }}
|
||
2 years ago
|
/>
|
||
|
),
|
||
|
md: 3,
|
||
|
sm: 2,
|
||
|
};
|
||
|
|
||
|
return previous;
|
||
|
},
|
||
|
{},
|
||
|
),
|
||
2 years ago
|
[
|
||
|
formUtils,
|
||
|
hostListEntries,
|
||
|
knownFenceListValues,
|
||
|
knownUpsListValues,
|
||
2 years ago
|
networkListEntries,
|
||
2 years ago
|
],
|
||
2 years ago
|
);
|
||
|
|
||
|
return (
|
||
|
<Grid
|
||
|
columns={{ xs: 1, sm: 2, md: 3 }}
|
||
|
layout={hostListGridLayout}
|
||
|
spacing="1em"
|
||
|
/>
|
||
|
);
|
||
|
};
|
||
|
|
||
2 years ago
|
export default AnHostConfigInputGroup;
|