From 131b601e55307aba64add32820179678914d69b8 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 13 Apr 2022 21:12:04 -0400 Subject: [PATCH] fix: correct memory slider WIP --- .../components/ProvisionServerDialog.tsx | 222 +++++++++++++----- 1 file changed, 168 insertions(+), 54 deletions(-) diff --git a/striker-ui/components/ProvisionServerDialog.tsx b/striker-ui/components/ProvisionServerDialog.tsx index e07baf68..2287c542 100644 --- a/striker-ui/components/ProvisionServerDialog.tsx +++ b/striker-ui/components/ProvisionServerDialog.tsx @@ -1,24 +1,96 @@ +import { useEffect, useState } from 'react'; import { + Box, Dialog, DialogProps, FormControl, FormGroup, - Select, } from '@mui/material'; +import { dSize, dSizeStr } from 'format-data-size'; +import MenuItem from './MenuItem'; import OutlinedInput from './OutlinedInput'; import OutlinedInputLabel from './OutlinedInputLabel'; import { Panel, PanelHeader } from './Panels'; +import Select from './Select'; import Slider, { SliderProps } from './Slider'; -import { HeaderText } from './Text'; +import { BodyText, HeaderText } from './Text'; type ProvisionServerDialogProps = { dialogProps: DialogProps; }; +const BIGINT_ZERO = BigInt(0); + +const createOutlinedInput = (id: string, label: string): JSX.Element => ( + + {label} + + +); + +const createOutlinedSelect = ( + id: string, + label: string | undefined, + value: string, + selectItems: string[][] | string[], +): JSX.Element => ( + + {label && ( + {label} + )} + + +); + +const createOutlinedSlider = ( + id: string, + label: string, + sliderProps?: Partial, +): JSX.Element => ( + + + +); + const ProvisionServerDialog = ({ dialogProps: { open }, }: ProvisionServerDialogProps): JSX.Element => { + const [sliderMaxAvailableCPUCores, setSliderMaxAvailableCPUCores] = + useState(0); + const [sliderMaxAvailableMemory, setSliderMaxAvailableMemory] = + useState(0); + + const [memory, setMemory] = useState(BIGINT_ZERO); + const [memoryUnit, setMemoryUnit] = useState(''); + const data = { anvils: [ { @@ -141,52 +213,58 @@ const ProvisionServerDialog = ({ ], }; - const generateFormControl = ( - id: string, - label: string, + const { maxAvailableCPUCores, maxAvailableMemory } = data.anvils.reduce<{ + maxAvailableCPUCores: number; + maxAvailableMemory: bigint; + }>( + ( + reducedValues, + { anvilTotalAvailableCPUCores, anvilTotalAvailableMemory }, + ) => { + const convertedAnvilTotalAvailableMemory = BigInt( + anvilTotalAvailableMemory, + ); + + reducedValues.maxAvailableCPUCores = Math.max( + anvilTotalAvailableCPUCores, + reducedValues.maxAvailableCPUCores, + ); + + if ( + convertedAnvilTotalAvailableMemory > reducedValues.maxAvailableMemory + ) { + reducedValues.maxAvailableMemory = convertedAnvilTotalAvailableMemory; + } + + return reducedValues; + }, { - inputType = 'text', - sliderProps, - }: { - inputType?: 'select' | 'slider' | 'text'; - sliderProps?: SliderProps; - } = {}, - ) => { - const labelElement = ( - {label} - ); + maxAvailableCPUCores: 0, + maxAvailableMemory: BIGINT_ZERO, + }, + ); - let inputElement = ( - <> - {labelElement} - - - ); + const optimizeOSList = data.osList.map((keyValuePair) => + keyValuePair.split(','), + ); - if (inputType === 'slider') { - inputElement = ( - - ); - } else if (inputType === 'select') { - inputElement = ( - <> - {labelElement} -