fix(striker-ui): show easier to read range in out-of-bounds messages

main
Tsu-ba-me 3 years ago
parent 4f7fe063da
commit 5d5a16516a
  1. 59
      striker-ui/components/ProvisionServerDialog.tsx
  2. 19
      striker-ui/lib/test_input/testInput.ts
  3. 2
      striker-ui/types/TestInputFunction.ts

@ -166,7 +166,13 @@ type UpdateLimitsFunction = (options?: {
memory?: bigint; memory?: bigint;
storageGroupUUIDMapToFree?: StorageGroupUUIDMapToFree; storageGroupUUIDMapToFree?: StorageGroupUUIDMapToFree;
virtualDisks?: VirtualDiskStates; virtualDisks?: VirtualDiskStates;
}) => Partial<ReturnType<FilterAnvilsFunction>>; }) => Pick<
ReturnType<FilterAnvilsFunction>,
'maxCPUCores' | 'maxMemory' | 'maxVirtualDiskSizes'
> & {
formattedMaxMemory: string;
formattedMaxVDSizes: string[];
};
const MOCK_DATA = { const MOCK_DATA = {
anvils: [ anvils: [
@ -780,12 +786,15 @@ const createVirtualDiskForm = (
const changeVDSize = (cvsValue: bigint = BIGINT_ZERO) => { const changeVDSize = (cvsValue: bigint = BIGINT_ZERO) => {
set('sizes', cvsValue); set('sizes', cvsValue);
const { maxVirtualDiskSizes } = updateLimits({ virtualDisks }); const { formattedMaxVDSizes, maxVirtualDiskSizes } = updateLimits({
virtualDisks,
});
testInput({ testInput({
inputs: { inputs: {
[`vd${vdIndex}Size`]: { [`vd${vdIndex}Size`]: {
max: maxVirtualDiskSizes?.[vdIndex], displayMax: `${formattedMaxVDSizes[vdIndex]}`,
max: maxVirtualDiskSizes[vdIndex],
value: cvsValue, value: cvsValue,
}, },
}, },
@ -1096,9 +1105,9 @@ const ProvisionServerDialog = ({
test: testMax, test: testMax,
}, },
{ {
onFailure: ({ max, min }) => { onFailure: ({ displayMax, displayMin }) => {
setInputCPUCoresMessage({ setInputCPUCoresMessage({
text: `The number of CPU cores is expected to be between ${min} and ${max}.`, text: `The number of CPU cores is expected to be between ${displayMin} and ${displayMax}.`,
type: 'warning', type: 'warning',
}); });
}, },
@ -1108,6 +1117,8 @@ const ProvisionServerDialog = ({
}, },
memory: { memory: {
defaults: { defaults: {
displayMax: `${inputMemoryMax} ${inputMemoryUnit}`,
displayMin: '1 B',
max: memoryMax, max: memoryMax,
min: 1, min: 1,
onSuccess: () => { onSuccess: () => {
@ -1123,9 +1134,9 @@ const ProvisionServerDialog = ({
test: testMax, test: testMax,
}, },
{ {
onFailure: ({ max, min }) => { onFailure: ({ displayMax, displayMin }) => {
setInputMemoryMessage({ setInputMemoryMessage({
text: `Memory is expected to be between ${min} B and ${max} B.`, text: `Memory is expected to be between ${displayMin} and ${displayMax}.`,
type: 'warning', type: 'warning',
}); });
}, },
@ -1170,6 +1181,8 @@ const ProvisionServerDialog = ({
virtualDisks.inputSizeMessages.forEach((message, vdIndex) => { virtualDisks.inputSizeMessages.forEach((message, vdIndex) => {
inputTests[`vd${vdIndex}Size`] = { inputTests[`vd${vdIndex}Size`] = {
defaults: { defaults: {
displayMax: `${virtualDisks.inputMaxes[vdIndex]} ${virtualDisks.inputUnits[vdIndex]}`,
displayMin: '1 B',
max: virtualDisks.maxes[vdIndex], max: virtualDisks.maxes[vdIndex],
min: 1, min: 1,
onSuccess: () => { onSuccess: () => {
@ -1191,9 +1204,9 @@ const ProvisionServerDialog = ({
test: testMax, test: testMax,
}, },
{ {
onFailure: ({ max, min }) => { onFailure: ({ displayMax, displayMin }) => {
virtualDisks.inputSizeMessages[vdIndex] = { virtualDisks.inputSizeMessages[vdIndex] = {
text: `Virtual disk ${vdIndex} size is expected to be between ${min} B and ${max} B.`, text: `Virtual disk ${vdIndex} size is expected to be between ${displayMin} and ${displayMax}.`,
type: 'warning', type: 'warning',
}; };
}, },
@ -1256,13 +1269,16 @@ const ProvisionServerDialog = ({
setInputCPUCoresMax(maxCPUCores); setInputCPUCoresMax(maxCPUCores);
setMemoryMax(maxMemory); setMemoryMax(maxMemory);
const formattedMaxVDSizes: string[] = [];
ulVirtualDisks.maxes = maxVirtualDiskSizes; ulVirtualDisks.maxes = maxVirtualDiskSizes;
ulVirtualDisks.maxes.forEach((vdMaxSize, vdIndex) => { ulVirtualDisks.maxes.forEach((vdMaxSize, vdIndex) => {
dSize(vdMaxSize, { dSize(vdMaxSize, {
fromUnit: 'B', fromUnit: 'B',
onSuccess: { onSuccess: {
string: (value) => { string: (value, unit) => {
ulVirtualDisks.inputMaxes[vdIndex] = value; ulVirtualDisks.inputMaxes[vdIndex] = value;
formattedMaxVDSizes[vdIndex] = `${value} ${unit}`;
}, },
}, },
toUnit: ulVirtualDisks.inputUnits[vdIndex], toUnit: ulVirtualDisks.inputUnits[vdIndex],
@ -1274,15 +1290,22 @@ const ProvisionServerDialog = ({
setIncludeFileUUIDs(fileUUIDs); setIncludeFileUUIDs(fileUUIDs);
setIncludeStorageGroupUUIDs(storageGroupUUIDs); setIncludeStorageGroupUUIDs(storageGroupUUIDs);
let formattedMaxMemory = '';
dSize(maxMemory, { dSize(maxMemory, {
fromUnit: 'B', fromUnit: 'B',
onSuccess: { onSuccess: {
string: (value) => setInputMemoryMax(value), string: (value, unit) => {
setInputMemoryMax(value);
formattedMaxMemory = `${value} ${unit}`;
},
}, },
toUnit: ulInputMemoryUnit, toUnit: ulInputMemoryUnit,
}); });
return { return {
formattedMaxMemory,
formattedMaxVDSizes,
maxCPUCores, maxCPUCores,
maxMemory, maxMemory,
maxVirtualDiskSizes, maxVirtualDiskSizes,
@ -1302,12 +1325,20 @@ const ProvisionServerDialog = ({
}: { cmValue?: bigint; cmUnit?: DataSizeUnit } = {}) => { }: { cmValue?: bigint; cmUnit?: DataSizeUnit } = {}) => {
setMemory(cmValue); setMemory(cmValue);
const { maxMemory } = updateLimits({ const { formattedMaxMemory, maxMemory } = updateLimits({
inputMemoryUnit: cmUnit, inputMemoryUnit: cmUnit,
memory: cmValue, memory: cmValue,
}); });
testInput({ inputs: { memory: { max: maxMemory, value: cmValue } } }); testInput({
inputs: {
memory: {
displayMax: formattedMaxMemory,
max: maxMemory,
value: cmValue,
},
},
});
}; };
const handleInputMemoryValueChange = ({ const handleInputMemoryValueChange = ({
@ -1330,7 +1361,7 @@ const ProvisionServerDialog = ({
unit, unit,
(convertedMemory) => (convertedMemory) =>
changeMemory({ cmValue: convertedMemory, cmUnit: unit }), changeMemory({ cmValue: convertedMemory, cmUnit: unit }),
() => changeMemory(), () => changeMemory({ cmUnit: unit }),
); );
}; };

@ -48,12 +48,25 @@ const testInput: TestInputFunction = ({
Object.keys(testsToRun).every((id: string) => { Object.keys(testsToRun).every((id: string) => {
const { const {
defaults: { max: dMax, min: dMin, onSuccess: dOnSuccess, value: dValue }, defaults: {
displayMax: dDisplayMax,
displayMin: dDisplayMin,
max: dMax,
min: dMin,
onSuccess: dOnSuccess,
value: dValue,
},
onFinishBatch, onFinishBatch,
optionalTests, optionalTests,
tests: requiredTests, tests: requiredTests,
} = tests[id]; } = tests[id];
const { max = dMax, min = dMin, value = dValue } = testsToRun[id]; const {
displayMax = dDisplayMax ?? String(dMax),
displayMin = dDisplayMin ?? String(dMin),
max = dMax,
min = dMin,
value = dValue,
} = testsToRun[id];
const { cbFinishBatch } = setBatchCallback({ onFinishBatch }); const { cbFinishBatch } = setBatchCallback({ onFinishBatch });
@ -62,7 +75,7 @@ const testInput: TestInputFunction = ({
onSuccess = dOnSuccess, onSuccess = dOnSuccess,
test, test,
}) => { }) => {
const args = { max, min, value }; const args = { displayMax, displayMin, max, min, value };
const singleResult: boolean = test(args); const singleResult: boolean = test(args);
const { cbFailure, cbSuccess } = setSingleCallback({ const { cbFailure, cbSuccess } = setSingleCallback({

@ -1,4 +1,6 @@
export type InputTestArgs = { export type InputTestArgs = {
displayMax?: string;
displayMin?: string;
max: bigint | number; max: bigint | number;
min: bigint | number; min: bigint | number;
value?: bigint | number | null | string; value?: bigint | number | null | string;

Loading…
Cancel
Save