diff --git a/frontend/src/components/GenericComponent.tsx b/frontend/src/components/GenericComponent.tsx index 368f6f6..9b9bba1 100644 --- a/frontend/src/components/GenericComponent.tsx +++ b/frontend/src/components/GenericComponent.tsx @@ -97,10 +97,10 @@ export const GenericComponent = React.memo( parentPath={parentPath} docString={attribute.doc} readOnly={attribute.readonly} - value={attribute.value['value']['value']} - min={attribute.value['min']['value']} - max={attribute.value['max']['value']} - stepSize={attribute.value['step_size']['value']} + value={attribute.value['value']} + min={attribute.value['min']} + max={attribute.value['max']} + stepSize={attribute.value['step_size']} isInstantUpdate={isInstantUpdate} addNotification={addNotification} /> diff --git a/frontend/src/components/SliderComponent.tsx b/frontend/src/components/SliderComponent.tsx index 6cd7464..36f91d6 100644 --- a/frontend/src/components/SliderComponent.tsx +++ b/frontend/src/components/SliderComponent.tsx @@ -3,19 +3,19 @@ import { InputGroup, Form, Row, Col, Collapse, ToggleButton } from 'react-bootst import { setAttribute } from '../socket'; import { DocStringComponent } from './DocStringComponent'; import { Slider } from '@mui/material'; -import { NumberComponent } from './NumberComponent'; +import { NumberComponent, NumberObject } from './NumberComponent'; import { getIdFromFullAccessPath } from '../utils/stringUtils'; import { LevelName } from './NotificationsComponent'; interface SliderComponentProps { name: string; - min: number; - max: number; + min: NumberObject; + max: NumberObject; parentPath?: string; - value: number; + value: NumberObject; readOnly: boolean; docString: string; - stepSize: number; + stepSize: NumberObject; isInstantUpdate: boolean; addNotification: (message: string, levelname?: LevelName) => void; } @@ -30,7 +30,6 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { min, max, stepSize, - readOnly, docString, isInstantUpdate, addNotification @@ -71,6 +70,28 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { setAttribute(`${name}.${valueType}`, parentPath, newValue); }; + const deconstructNumberDict = ( + numberDict: NumberObject + ): [number, boolean, string | null] => { + let numberMagnitude: number; + let numberUnit: string | null = null; + const numberReadOnly = numberDict.readonly; + + if (numberDict.type === 'int' || numberDict.type === 'float') { + numberMagnitude = numberDict.value; + } else if (numberDict.type === 'Quantity') { + numberMagnitude = numberDict.value.magnitude; + numberUnit = numberDict.value.unit; + } + + return [numberMagnitude, numberReadOnly, numberUnit]; + }; + + const [valueMagnitude, valueReadOnly, valueUnit] = deconstructNumberDict(value); + const [minMagnitude, minReadOnly] = deconstructNumberDict(min); + const [maxMagnitude, maxReadOnly] = deconstructNumberDict(max); + const [stepSizeMagnitude, stepSizeReadOnly] = deconstructNumberDict(stepSize); + return (