fix(striker-ui): autocomplete OS and simplify dSize

main
Tsu-ba-me 3 years ago
parent 99b56515e3
commit 92ddab3344
  1. 112
      striker-ui/components/ProvisionServerDialog.tsx

@ -13,6 +13,7 @@ import {
FormatDataSizeInputValue, FormatDataSizeInputValue,
} from 'format-data-size'; } from 'format-data-size';
import Autocomplete from './Autocomplete';
import MenuItem from './MenuItem'; import MenuItem from './MenuItem';
import OutlinedInput, { OutlinedInputProps } from './OutlinedInput'; import OutlinedInput, { OutlinedInputProps } from './OutlinedInput';
import OutlinedInputLabel from './OutlinedInputLabel'; import OutlinedInputLabel from './OutlinedInputLabel';
@ -21,6 +22,8 @@ import Select, { SelectProps } from './Select';
import Slider, { SliderProps } from './Slider'; import Slider, { SliderProps } from './Slider';
import { BodyText, HeaderText } from './Text'; import { BodyText, HeaderText } from './Text';
import ContainedButton from './ContainedButton'; import ContainedButton from './ContainedButton';
import { OutlinedInputLabelProps } from './OutlinedInputLabel/OutlinedInputLabel';
import OutlinedInputWithLabel from './OutlinedInputWithLabel';
type SelectItem<SelectItemValueType = string> = { type SelectItem<SelectItemValueType = string> = {
displayValue?: SelectItemValueType; displayValue?: SelectItemValueType;
@ -291,18 +294,6 @@ const DATA_SIZE_UNITS: SelectItem<DataSizeUnit>[] = [
{ value: 'TB' }, { value: 'TB' },
]; ];
const createOutlinedInput = (
id: string,
label: string,
inputProps?: Partial<OutlinedInputProps>,
): JSX.Element => (
<FormControl>
<OutlinedInputLabel {...{ htmlFor: id }}>{label}</OutlinedInputLabel>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<OutlinedInput {...{ id, label, ...inputProps }} />
</FormControl>
);
const createOutlinedSelect = ( const createOutlinedSelect = (
id: string, id: string,
label: string | undefined, label: string | undefined,
@ -378,9 +369,11 @@ const createOutlinedInputWithSelect = (
selectItems: SelectItem[], selectItems: SelectItem[],
{ {
inputProps, inputProps,
inputLabelProps,
selectProps, selectProps,
}: { }: {
inputProps?: Partial<OutlinedInputProps>; inputProps?: Partial<OutlinedInputProps>;
inputLabelProps?: Partial<OutlinedInputLabelProps>;
selectProps?: Partial<SelectProps>; selectProps?: Partial<SelectProps>;
} = {}, } = {},
) => ( ) => (
@ -394,7 +387,7 @@ const createOutlinedInputWithSelect = (
}, },
}} }}
> >
{createOutlinedInput(id, label, inputProps)} <OutlinedInputWithLabel {...{ id, label, inputProps, inputLabelProps }} />
{createOutlinedSelect(`${id}-nested-select`, undefined, selectItems, { {createOutlinedSelect(`${id}-nested-select`, undefined, selectItems, {
selectProps, selectProps,
})} })}
@ -596,6 +589,21 @@ const dSize = (
} }
}; };
const dSizeToBytes = (
value: FormatDataSizeInputValue,
fromUnit: DataSizeUnit,
onSuccess: (newValue: bigint, unit: DataSizeUnit) => void,
) => {
dSize(value, {
fromUnit,
onSuccess: {
bigint: onSuccess,
},
precision: 0,
toUnit: 'B',
});
};
const filterAnvils = ( const filterAnvils = (
organizedAnvils: OrganizedAnvilDetailMetadataForProvisionServer[], organizedAnvils: OrganizedAnvilDetailMetadataForProvisionServer[],
cpuCores: number, cpuCores: number,
@ -688,9 +696,14 @@ const ProvisionServerDialog = ({
value: fileUUID, value: fileUUID,
})); }));
// const optimizeOSList = data.osList.map((keyValuePair) => const optimizeOSList = data.osList.map((keyValuePair) => {
// keyValuePair.split(','), const [osKey, osValue] = keyValuePair.split(',');
// );
return {
label: osValue,
key: osKey,
};
});
useEffect(() => { useEffect(() => {
setInputCPUCoresMax(maxCPUCores); setInputCPUCoresMax(maxCPUCores);
@ -712,7 +725,7 @@ const ProvisionServerDialog = ({
<HeaderText text="Provision a Server" /> <HeaderText text="Provision a Server" />
</PanelHeader> </PanelHeader>
<FormGroup> <FormGroup>
{createOutlinedInput('ps-server-name', 'Server name')} <OutlinedInputWithLabel id="ps-server-name" label="Server name" />
{createOutlinedSlider('ps-cpu-cores', 'CPU cores', cpuCoresValue, { {createOutlinedSlider('ps-cpu-cores', 'CPU cores', cpuCoresValue, {
sliderProps: { sliderProps: {
onChange: (value) => { onChange: (value) => {
@ -731,16 +744,7 @@ const ProvisionServerDialog = ({
onChange: ({ target: { value } }) => { onChange: ({ target: { value } }) => {
setInputMemoryValue(value); setInputMemoryValue(value);
dSize(value, { dSizeToBytes(value, inputMemoryUnit, setMemoryValue);
fromUnit: inputMemoryUnit,
onSuccess: {
bigint: (newValue) => {
setMemoryValue(newValue);
},
},
precision: 0,
toUnit: 'B',
});
}, },
value: inputMemoryValue, value: inputMemoryValue,
}, },
@ -750,16 +754,7 @@ const ProvisionServerDialog = ({
setInputMemoryUnit(selectedUnit); setInputMemoryUnit(selectedUnit);
dSize(inputMemoryValue, { dSizeToBytes(inputMemoryValue, selectedUnit, setMemoryValue);
fromUnit: selectedUnit,
onSuccess: {
bigint: (newValue) => {
setMemoryValue(newValue);
},
},
precision: 0,
toUnit: 'B',
});
}, },
value: inputMemoryUnit, value: inputMemoryUnit,
}, },
@ -777,16 +772,11 @@ const ProvisionServerDialog = ({
onChange: ({ target: { value } }) => { onChange: ({ target: { value } }) => {
setInputVirtualDiskSizeValue(value); setInputVirtualDiskSizeValue(value);
dSize(value, { dSizeToBytes(
fromUnit: inputVirtualDiskSizeUnit, value,
onSuccess: { inputVirtualDiskSizeUnit,
bigint: (newValue) => { setVirtualDiskSizeValue,
setVirtualDiskSizeValue(newValue); );
},
},
precision: 0,
toUnit: 'B',
});
}, },
value: inputVirtualDiskSizeValue, value: inputVirtualDiskSizeValue,
}, },
@ -796,16 +786,11 @@ const ProvisionServerDialog = ({
setInputVirtualDiskSizeUnit(selectedUnit); setInputVirtualDiskSizeUnit(selectedUnit);
dSize(inputVirtualDiskSizeValue, { dSizeToBytes(
fromUnit: selectedUnit, inputVirtualDiskSizeValue,
onSuccess: { selectedUnit,
bigint: (newValue) => { setVirtualDiskSizeValue,
setVirtualDiskSizeValue(newValue); );
},
},
precision: 0,
toUnit: 'B',
});
}, },
value: inputVirtualDiskSizeUnit, value: inputVirtualDiskSizeUnit,
}, },
@ -979,12 +964,13 @@ const ProvisionServerDialog = ({
}, },
}, },
)} )}
{/* <Autocomplete
{createOutlinedSelect( id="ps-optimize-for-os"
'ps-optimize-for-os', label="Optimize for OS"
'Optimize for OS', noOptionsText="No matching OS"
optimizeOSList, openOnFocus
)} */} options={optimizeOSList}
/>
</FormGroup> </FormGroup>
<ContainedButton>Provision</ContainedButton> <ContainedButton>Provision</ContainedButton>
</Dialog> </Dialog>

Loading…
Cancel
Save