fix(striker-ui): hoist OutlinedLabeledInputWithSelect

main
Tsu-ba-me 3 years ago
parent c280498d4b
commit 86062d33a2
  1. 86
      striker-ui/components/OutlinedLabeledInputWithSelect.tsx
  2. 93
      striker-ui/components/ProvisionServerDialog.tsx

@ -0,0 +1,86 @@
import { FC } from 'react';
import { Box } from '@mui/material';
import InputMessageBox from './InputMessageBox';
import { MessageBoxProps } from './MessageBox';
import OutlinedInputWithLabel, {
OutlinedInputWithLabelProps,
} from './OutlinedInputWithLabel';
import SelectWithLabel, {
SelectItem,
SelectWithLabelProps,
} from './SelectWithLabel';
type OutlinedLabeledInputWithSelectOptionalProps = {
inputWithLabelProps?: Partial<OutlinedInputWithLabelProps>;
messageBoxProps?: Partial<MessageBoxProps>;
selectWithLabelProps?: Partial<SelectWithLabelProps>;
};
type OutlinedLabeledInputWithSelectProps =
OutlinedLabeledInputWithSelectOptionalProps & {
id: string;
label: string;
selectItems: SelectItem[];
};
const OUTLINED_LABELED_INPUT_WITH_SELECT_DEFAULT_PROPS: Required<OutlinedLabeledInputWithSelectOptionalProps> =
{
inputWithLabelProps: {},
messageBoxProps: {},
selectWithLabelProps: {},
};
const OutlinedLabeledInputWithSelect: FC<
OutlinedLabeledInputWithSelectProps
> = ({
id,
label,
inputWithLabelProps,
messageBoxProps,
selectItems,
selectWithLabelProps,
}) => (
<Box>
<Box
sx={{
display: 'flex',
flexDirection: 'row',
'& > :first-child': {
flexGrow: 1,
},
'& > :not(:last-child)': {
marginRight: '.5em',
},
}}
>
<OutlinedInputWithLabel
// eslint-disable-next-line react/jsx-props-no-spreading
{...{
id,
label,
...inputWithLabelProps,
}}
/>
<SelectWithLabel
// eslint-disable-next-line react/jsx-props-no-spreading
{...{
id: `${id}-nested-select`,
selectItems,
...selectWithLabelProps,
}}
/>
</Box>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<InputMessageBox {...messageBoxProps} />
</Box>
);
OutlinedLabeledInputWithSelect.defaultProps =
OUTLINED_LABELED_INPUT_WITH_SELECT_DEFAULT_PROPS;
export type { OutlinedLabeledInputWithSelectProps };
export default OutlinedLabeledInputWithSelect;

@ -15,13 +15,9 @@ import {
import Autocomplete from './Autocomplete'; import Autocomplete from './Autocomplete';
import ContainedButton, { ContainedButtonProps } from './ContainedButton'; import ContainedButton, { ContainedButtonProps } from './ContainedButton';
import InputMessageBox from './InputMessageBox';
import { MessageBoxProps } from './MessageBox'; import { MessageBoxProps } from './MessageBox';
import OutlinedInputWithLabel, { import OutlinedInputWithLabel from './OutlinedInputWithLabel';
OutlinedInputWithLabelProps,
} from './OutlinedInputWithLabel';
import { Panel, PanelHeader } from './Panels'; import { Panel, PanelHeader } from './Panels';
import { SelectProps } from './Select';
import SelectWithLabel, { SelectItem } from './SelectWithLabel'; import SelectWithLabel, { SelectItem } from './SelectWithLabel';
import Slider, { SliderProps } from './Slider'; import Slider, { SliderProps } from './Slider';
import { import {
@ -35,6 +31,7 @@ import {
TestInputFunction, TestInputFunction,
} from '../types/TestInputFunction'; } from '../types/TestInputFunction';
import { BodyText, HeaderText } from './Text'; import { BodyText, HeaderText } from './Text';
import OutlinedLabeledInputWithSelect from './OutlinedLabeledInputWithSelect';
type InputMessage = Partial<Pick<MessageBoxProps, 'type' | 'text'>>; type InputMessage = Partial<Pick<MessageBoxProps, 'type' | 'text'>>;
@ -371,48 +368,6 @@ const createOutlinedSlider = (
/> />
); );
const createOutlinedInputWithSelect = (
id: string,
label: string,
selectItems: SelectItem[],
{
messageBoxProps,
inputWithLabelProps,
selectProps,
}: {
inputWithLabelProps?: Partial<OutlinedInputWithLabelProps>;
messageBoxProps?: Partial<MessageBoxProps>;
selectProps?: Partial<SelectProps>;
} = {},
) => (
<Box>
<Box
sx={{
display: 'flex',
flexDirection: 'row',
'& > :first-child': {
flexGrow: 1,
},
}}
>
<OutlinedInputWithLabel
// eslint-disable-next-line react/jsx-props-no-spreading
{...{
id,
label,
...inputWithLabelProps,
}}
/>
<SelectWithLabel
{...{ id: `${id}-nested-select`, selectItems, selectProps }}
/>
</Box>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<InputMessageBox {...messageBoxProps} />
</Box>
);
const createMaxValueButton = ( const createMaxValueButton = (
maxValue: string, maxValue: string,
{ {
@ -884,12 +839,11 @@ const createVirtualDiskForm = (
).toString()}, Max: ${get('maxes').toString()}`} ).toString()}, Max: ${get('maxes').toString()}`}
/> />
<Box sx={{ display: 'flex', flexDirection: 'column' }}> <Box sx={{ display: 'flex', flexDirection: 'column' }}>
{createOutlinedInputWithSelect( <OutlinedLabeledInputWithSelect
`ps-virtual-disk-size-${vdIndex}`, id={`ps-virtual-disk-size-${vdIndex}`}
'Virtual disk size', label="Virtual disk size"
DATA_SIZE_UNIT_SELECT_ITEMS, messageBoxProps={get('inputSizeMessages')}
{ inputWithLabelProps={{
inputWithLabelProps: {
inputProps: { inputProps: {
endAdornment: createMaxValueButton( endAdornment: createMaxValueButton(
`${get('inputMaxes')} ${get('inputUnits')}`, `${get('inputMaxes')} ${get('inputUnits')}`,
@ -906,7 +860,9 @@ const createVirtualDiskForm = (
type: 'number', type: 'number',
value: get('inputSizes'), value: get('inputSizes'),
}, },
}, }}
selectItems={DATA_SIZE_UNIT_SELECT_ITEMS}
selectWithLabelProps={{
selectProps: { selectProps: {
onChange: ({ target: { value } }) => { onChange: ({ target: { value } }) => {
const selectedUnit = value as DataSizeUnit; const selectedUnit = value as DataSizeUnit;
@ -915,10 +871,8 @@ const createVirtualDiskForm = (
}, },
value: get('inputUnits'), value: get('inputUnits'),
}, },
}, }}
)} />
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<InputMessageBox {...get('inputSizeMessages')} />
</Box> </Box>
<Box sx={{ display: 'flex', flexDirection: 'column' }}> <Box sx={{ display: 'flex', flexDirection: 'column' }}>
<SelectWithLabel <SelectWithLabel
@ -930,6 +884,7 @@ const createVirtualDiskForm = (
get('sizes') <= storageGroupUUIDMapToFree[value] get('sizes') <= storageGroupUUIDMapToFree[value]
) )
} }
messageBoxProps={get('inputStorageGroupUUIDMessages')}
selectItems={storageGroupSelectItems} selectItems={storageGroupSelectItems}
selectProps={{ selectProps={{
onChange: ({ target: { value } }) => { onChange: ({ target: { value } }) => {
@ -941,8 +896,6 @@ const createVirtualDiskForm = (
onClearIndicatorClick: () => handleVDStorageGroupChange(''), onClearIndicatorClick: () => handleVDStorageGroupChange(''),
}} }}
/> />
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<InputMessageBox {...get('inputStorageGroupUUIDMessages')} />
</Box> </Box>
</Box> </Box>
); );
@ -1500,13 +1453,11 @@ const ProvisionServerDialog = ({
<BodyText <BodyText
text={`Memory: ${memory.toString()}, Max: ${memoryMax.toString()}`} text={`Memory: ${memory.toString()}, Max: ${memoryMax.toString()}`}
/> />
{createOutlinedInputWithSelect( <OutlinedLabeledInputWithSelect
'ps-memory', id="ps-memory"
'Memory', label="Memory"
DATA_SIZE_UNIT_SELECT_ITEMS, messageBoxProps={inputMemoryMessage}
{ inputWithLabelProps={{
messageBoxProps: inputMemoryMessage,
inputWithLabelProps: {
inputProps: { inputProps: {
endAdornment: createMaxValueButton( endAdornment: createMaxValueButton(
`${inputMemoryMax} ${inputMemoryUnit}`, `${inputMemoryMax} ${inputMemoryUnit}`,
@ -1526,7 +1477,9 @@ const ProvisionServerDialog = ({
inputLabelProps: { inputLabelProps: {
isNotifyRequired: inputMemoryValue.length === 0, isNotifyRequired: inputMemoryValue.length === 0,
}, },
}, }}
selectItems={DATA_SIZE_UNIT_SELECT_ITEMS}
selectWithLabelProps={{
selectProps: { selectProps: {
onChange: ({ target: { value } }) => { onChange: ({ target: { value } }) => {
const selectedUnit = value as DataSizeUnit; const selectedUnit = value as DataSizeUnit;
@ -1535,8 +1488,8 @@ const ProvisionServerDialog = ({
}, },
value: inputMemoryUnit, value: inputMemoryUnit,
}, },
}, }}
)} />
{virtualDisks.maxes.map((max, vdIndex) => {virtualDisks.maxes.map((max, vdIndex) =>
createVirtualDiskForm( createVirtualDiskForm(
virtualDisks, virtualDisks,

Loading…
Cancel
Save