From bbba31036a8dbcfd2a1b4a406375b29521ffe490 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 5 May 2022 17:26:20 -0400 Subject: [PATCH] fix(striker-ui): apply InputMessageBox and SelectWithLabel in provision server --- .../components/ProvisionServerDialog.tsx | 220 +++++++----------- 1 file changed, 79 insertions(+), 141 deletions(-) diff --git a/striker-ui/components/ProvisionServerDialog.tsx b/striker-ui/components/ProvisionServerDialog.tsx index 47183fec..84d6c34e 100644 --- a/striker-ui/components/ProvisionServerDialog.tsx +++ b/striker-ui/components/ProvisionServerDialog.tsx @@ -5,14 +5,7 @@ import { useEffect, useState, } from 'react'; -import { - Box, - Checkbox, - Dialog, - DialogProps, - FormControl, - InputAdornment, -} from '@mui/material'; +import { Box, Dialog, DialogProps, InputAdornment } from '@mui/material'; import { dSize as baseDSize, DataSizeUnit, @@ -22,15 +15,14 @@ import { import Autocomplete from './Autocomplete'; import ContainedButton, { ContainedButtonProps } from './ContainedButton'; -import MenuItem from './MenuItem'; -import MessageBox, { MessageBoxProps } from './MessageBox'; -import OutlinedInput from './OutlinedInput'; -import OutlinedInputLabel from './OutlinedInputLabel'; +import InputMessageBox from './InputMessageBox'; +import { MessageBoxProps } from './MessageBox'; import OutlinedInputWithLabel, { OutlinedInputWithLabelProps, } from './OutlinedInputWithLabel'; import { Panel, PanelHeader } from './Panels'; -import Select, { SelectProps } from './Select'; +import { SelectProps } from './Select'; +import SelectWithLabel, { SelectItem } from './SelectWithLabel'; import Slider, { SliderProps } from './Slider'; import { testInput as baseTestInput, @@ -38,19 +30,14 @@ import { testNotBlank, testRange, } from '../lib/test_input'; -import { BodyText, HeaderText } from './Text'; import { InputTestBatches, TestInputFunction, } from '../types/TestInputFunction'; +import { BodyText, HeaderText } from './Text'; type InputMessage = Partial>; -type SelectItem = { - displayValue?: SelectItemValueType; - value: SelectItemValueType; -}; - type ProvisionServerDialogProps = { dialogProps: DialogProps; }; @@ -364,61 +351,6 @@ const DATA_SIZE_UNIT_SELECT_ITEMS: SelectItem[] = [ { value: 'TB' }, ]; -const createInputMessage = ({ text, type }: Partial = {}) => - text && ; - -const createOutlinedSelect = ( - id: string, - label: string | undefined, - selectItems: SelectItem[], - { - checkItem, - disableItem, - hideItem, - messageBoxProps, - selectProps, - isCheckableItems = selectProps?.multiple, - }: { - checkItem?: (value: string) => boolean; - disableItem?: (value: string) => boolean; - hideItem?: (value: string) => boolean; - isCheckableItems?: boolean; - messageBoxProps?: Partial; - selectProps?: Partial; - } = {}, -): JSX.Element => ( - - {label && ( - {label} - )} - - {createInputMessage(messageBoxProps)} - -); - const createOutlinedSlider = ( id: string, label: string, @@ -470,11 +402,12 @@ const createOutlinedInputWithSelect = ( ...inputWithLabelProps, }} /> - {createOutlinedSelect(`${id}-nested-select`, undefined, selectItems, { - selectProps, - })} + - {createInputMessage(messageBoxProps)} + {/* eslint-disable-next-line react/jsx-props-no-spreading */} + ); @@ -982,31 +915,32 @@ const createVirtualDiskForm = ( }, }, )} - {createInputMessage(get('inputSizeMessages'))} + {/* eslint-disable-next-line react/jsx-props-no-spreading */} + - {createOutlinedSelect( - `ps-storage-group-${vdIndex}`, - 'Storage group', - storageGroupSelectItems, - { - disableItem: (value) => - !( - includeStorageGroupUUIDs.includes(value) && - get('sizes') <= storageGroupUUIDMapToFree[value] - ), - selectProps: { - onChange: ({ target: { value } }) => { - const selectedStorageGroupUUID = value as string; + + !( + includeStorageGroupUUIDs.includes(value) && + get('sizes') <= storageGroupUUIDMapToFree[value] + ) + } + selectItems={storageGroupSelectItems} + selectProps={{ + onChange: ({ target: { value } }) => { + const selectedStorageGroupUUID = value as string; - handleVDStorageGroupChange(selectedStorageGroupUUID); - }, - value: get('inputStorageGroupUUIDs'), - onClearIndicatorClick: () => handleVDStorageGroupChange(''), + handleVDStorageGroupChange(selectedStorageGroupUUID); }, - }, - )} - {createInputMessage(get('inputStorageGroupUUIDMessages'))} + value: get('inputStorageGroupUUIDs'), + onClearIndicatorClick: () => handleVDStorageGroupChange(''), + }} + /> + {/* eslint-disable-next-line react/jsx-props-no-spreading */} + ); @@ -1529,6 +1463,9 @@ const ProvisionServerDialog = ({ }, value: inputServerNameValue, }} + inputLabelProps={{ + isNotifyRequired: inputServerNameValue.length === 0, + }} messageBoxProps={inputServerNameMessage} /> @@ -1582,6 +1519,9 @@ const ProvisionServerDialog = ({ type: 'number', value: inputMemoryValue, }, + inputLabelProps: { + isNotifyRequired: inputMemoryValue.length === 0, + }, }, selectProps: { onChange: ({ target: { value } }) => { @@ -1605,50 +1545,48 @@ const ProvisionServerDialog = ({ testInput, ), )} - {createOutlinedSelect( - 'ps-install-image', - 'Install ISO', - fileSelectItems, - { - disableItem: (value) => value === inputDriverISOFileUUID, - hideItem: (value) => !includeFileUUIDs.includes(value), - messageBoxProps: inputInstallISOMessage, - selectProps: { - onChange: ({ target: { value } }) => { - const newInstallISOFileUUID = value as string; + value === inputDriverISOFileUUID} + hideItem={(value) => !includeFileUUIDs.includes(value)} + id="ps-install-image" + label="Install ISO" + messageBoxProps={inputInstallISOMessage} + selectItems={fileSelectItems} + selectProps={{ + onChange: ({ target: { value } }) => { + const newInstallISOFileUUID = value as string; - handleInputInstallISOFileUUIDChange(newInstallISOFileUUID); - }, - onClearIndicatorClick: () => - handleInputInstallISOFileUUIDChange(''), - value: inputInstallISOFileUUID, + handleInputInstallISOFileUUIDChange(newInstallISOFileUUID); }, - }, - )} - {createOutlinedSelect( - 'ps-driver-image', - 'Driver ISO (optional)', - fileSelectItems, - { - disableItem: (value) => value === inputInstallISOFileUUID, - hideItem: (value) => !includeFileUUIDs.includes(value), - messageBoxProps: inputDriverISOMessage, - selectProps: { - onChange: ({ target: { value } }) => { - const newDriverISOFileUUID = value as string; + onClearIndicatorClick: () => + handleInputInstallISOFileUUIDChange(''), + value: inputInstallISOFileUUID, + }} + /> + value === inputInstallISOFileUUID} + hideItem={(value) => !includeFileUUIDs.includes(value)} + id="ps-driver-image" + label="Driver ISO (optional)" + messageBoxProps={inputDriverISOMessage} + selectItems={fileSelectItems} + selectProps={{ + onChange: ({ target: { value } }) => { + const newDriverISOFileUUID = value as string; - handleInputDriverISOFileUUIDChange(newDriverISOFileUUID); - }, - onClearIndicatorClick: () => - handleInputDriverISOFileUUIDChange(''), - value: inputDriverISOFileUUID, + handleInputDriverISOFileUUIDChange(newDriverISOFileUUID); }, - }, - )} - {createOutlinedSelect('ps-anvil', 'Anvil', anvilSelectItems, { - disableItem: (value) => !includeAnvilUUIDs.includes(value), - messageBoxProps: inputAnvilMessage, - selectProps: { + onClearIndicatorClick: () => handleInputDriverISOFileUUIDChange(''), + value: inputDriverISOFileUUID, + }} + /> + !includeAnvilUUIDs.includes(value)} + id="ps-anvil" + label="Anvil node pair" + messageBoxProps={inputAnvilMessage} + selectItems={anvilSelectItems} + selectProps={{ onChange: ({ target: { value } }) => { const newAnvilUUID: string = value as string; @@ -1656,8 +1594,8 @@ const ProvisionServerDialog = ({ }, onClearIndicatorClick: () => handleInputAnvilValueChange(''), value: inputAnvilValue, - }, - })} + }} + />