From ab4f5bdfe5972987eb57e8eff9b3f21e488974f0 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 12 May 2022 21:53:43 -0400 Subject: [PATCH] fix(striker-ui): add provision server request and related displays --- .../components/ProvisionServerDialog.tsx | 107 +++++++++++++----- 1 file changed, 79 insertions(+), 28 deletions(-) diff --git a/striker-ui/components/ProvisionServerDialog.tsx b/striker-ui/components/ProvisionServerDialog.tsx index 7dea84a4..866b9d4d 100644 --- a/striker-ui/components/ProvisionServerDialog.tsx +++ b/striker-ui/components/ProvisionServerDialog.tsx @@ -10,14 +10,20 @@ import { Box, Dialog, DialogProps, InputAdornment } from '@mui/material'; import { DataSizeUnit } from 'format-data-size'; import { v4 as uuidv4 } from 'uuid'; +import { BLUE, TEXT } from '../lib/consts/DEFAULT_THEME'; + import Autocomplete from './Autocomplete'; +import ConfirmDialog from './ConfirmDialog'; import ContainedButton, { ContainedButtonProps } from './ContainedButton'; import { dsize, dsizeToByte } from '../lib/format_data_size_wrappers'; -import { MessageBoxProps } from './MessageBox'; +import mainAxiosInstance from '../lib/singletons/mainAxiosInstance'; +import MessageBox, { MessageBoxProps } from './MessageBox'; import OutlinedInputWithLabel from './OutlinedInputWithLabel'; +import OutlinedLabeledInputWithSelect from './OutlinedLabeledInputWithSelect'; import { Panel, PanelHeader } from './Panels'; import SelectWithLabel, { SelectItem } from './SelectWithLabel'; import Slider, { SliderProps } from './Slider'; +import Spinner from './Spinner'; import { testInput as baseTestInput, testMax, @@ -29,8 +35,6 @@ import { TestInputFunction, } from '../types/TestInputFunction'; import { BodyText, HeaderText } from './Text'; -import OutlinedLabeledInputWithSelect from './OutlinedLabeledInputWithSelect'; -import ConfirmDialog from './ConfirmDialog'; type InputMessage = Partial>; @@ -368,6 +372,15 @@ const DATA_SIZE_UNIT_SELECT_ITEMS: SelectItem[] = [ const INITIAL_DATA_SIZE_UNIT: DataSizeUnit = 'GiB'; +const PROVISION_BUTTON_STYLES = { + backgroundColor: BLUE, + color: TEXT, + + '&:hover': { + backgroundColor: BLUE, + }, +}; + const createOutlinedSlider = ( id: string, label: string, @@ -1104,6 +1117,11 @@ const ProvisionServerDialog = ({ const [isOpenProvisionConfirmDialog, setIsOpenProvisionConfirmDialog] = useState(false); + const [isProvisionRequestInProgress, setIsProvisionRequestInProgress] = + useState(false); + + const [successfulProvisionCount, setSuccessfulProvisionCount] = + useState(0); const inputTests: InputTestBatches = { serverName: { @@ -1505,7 +1523,6 @@ const ProvisionServerDialog = ({ flexDirection: 'column', maxHeight: '50vh', overflowY: 'scroll', - paddingBottom: '.6em', paddingTop: '.6em', '& > :not(:first-child)': { @@ -1697,20 +1714,42 @@ const ProvisionServerDialog = ({ :not(:first-child)': { + marginTop: '1em', + }, }} > - { - setIsOpenProvisionConfirmDialog(true); - }} - > - Provision - + {successfulProvisionCount > 0 && ( + + )} + {isProvisionRequestInProgress ? ( + + ) : ( + + { + setIsOpenProvisionConfirmDialog(true); + }} + sx={PROVISION_BUTTON_STYLES} + > + Provision + + + )} {isOpenProvisionConfirmDialog && ( @@ -1755,22 +1794,34 @@ const ProvisionServerDialog = ({ setIsOpenProvisionConfirmDialog(false); }} onProceed={() => { - // const requestBody = { - // serverName: inputServerNameValue, - // cpuCores: inputCPUCoresValue, - // memory, - // virtualDisks: virtualDisks.stateIds.map((vdStateId, vdIndex) => ({ - // size: virtualDisks.sizes[vdIndex], - // storageGroupUUID: virtualDisks.inputStorageGroupUUIDs[vdIndex], - // })), - // installISOFileUUID: inputInstallISOFileUUID, - // driverISOFileUUID: inputDriverISOFileUUID, - // anvilUUID: inputAnvilValue, - // optimizeForOS: inputOptimizeForOSValue?.key, - // }; + const requestBody = JSON.stringify({ + serverName: inputServerNameValue, + cpuCores: inputCPUCoresValue, + memory: memory.toString(), + virtualDisks: virtualDisks.stateIds.map((vdStateId, vdIndex) => ({ + storageSize: virtualDisks.sizes[vdIndex].toString(), + storageGroupUUID: virtualDisks.inputStorageGroupUUIDs[vdIndex], + })), + installISOFileUUID: inputInstallISOFileUUID, + driverISOFileUUID: inputDriverISOFileUUID, + anvilUUID: inputAnvilValue, + optimizeForOS: inputOptimizeForOSValue?.key, + }); + + setIsProvisionRequestInProgress(true); + + mainAxiosInstance + .post('/server', requestBody, { + headers: { 'Content-Type': 'application/json' }, + }) + .then(() => { + setIsProvisionRequestInProgress(false); + setSuccessfulProvisionCount(successfulProvisionCount + 1); + }); setIsOpenProvisionConfirmDialog(false); }} + proceedButtonProps={{ sx: PROVISION_BUTTON_STYLES }} titleText={`Provision ${inputServerNameValue}?`} /> )}