mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 13:30:41 +02:00
updates SliderComponent to emit attribute updates (instead of full state dict)
This commit is contained in:
parent
09f73a2b1d
commit
83cd07feee
@ -58,50 +58,17 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
addNotification(`${parentPath}.${name}.stepSize changed to ${stepSize}.`);
|
addNotification(`${parentPath}.${name}.stepSize changed to ${stepSize}.`);
|
||||||
}, [props.stepSize]);
|
}, [props.stepSize]);
|
||||||
|
|
||||||
const emitSliderUpdate = (
|
|
||||||
name: string,
|
|
||||||
parentPath: string,
|
|
||||||
value: number,
|
|
||||||
callback?: (ack: unknown) => void,
|
|
||||||
min: number = props.min,
|
|
||||||
max: number = props.max,
|
|
||||||
stepSize: number = props.stepSize
|
|
||||||
) => {
|
|
||||||
setAttribute(
|
|
||||||
name,
|
|
||||||
parentPath,
|
|
||||||
{
|
|
||||||
value: value,
|
|
||||||
min: min,
|
|
||||||
max: max,
|
|
||||||
step_size: stepSize
|
|
||||||
},
|
|
||||||
callback
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const handleOnChange = (event, newNumber: number | number[]) => {
|
const handleOnChange = (event, newNumber: number | number[]) => {
|
||||||
// This will never be the case as we do not have a range slider. However, we should
|
// This will never be the case as we do not have a range slider. However, we should
|
||||||
// make sure this is properly handled.
|
// make sure this is properly handled.
|
||||||
if (Array.isArray(newNumber)) {
|
if (Array.isArray(newNumber)) {
|
||||||
newNumber = newNumber[0];
|
newNumber = newNumber[0];
|
||||||
}
|
}
|
||||||
emitSliderUpdate(name, parentPath, newNumber);
|
setAttribute(`${name}.value`, parentPath, newNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleValueChange = (newValue: number, valueType: string) => {
|
const handleValueChange = (newValue: number, valueType: string) => {
|
||||||
switch (valueType) {
|
setAttribute(`${name}.${valueType}`, parentPath, newValue);
|
||||||
case 'min':
|
|
||||||
emitSliderUpdate(name, parentPath, value, undefined, newValue);
|
|
||||||
break;
|
|
||||||
case 'max':
|
|
||||||
emitSliderUpdate(name, parentPath, value, undefined, min, newValue);
|
|
||||||
break;
|
|
||||||
case 'stepSize':
|
|
||||||
emitSliderUpdate(name, parentPath, value, undefined, min, max, newValue);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -136,13 +103,12 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
<NumberComponent
|
<NumberComponent
|
||||||
isInstantUpdate={isInstantUpdate}
|
isInstantUpdate={isInstantUpdate}
|
||||||
parentPath={parentPath}
|
parentPath={parentPath}
|
||||||
name={name}
|
name={`${name}.value`}
|
||||||
docString=""
|
docString=""
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
type="float"
|
type="float"
|
||||||
value={value}
|
value={value}
|
||||||
showName={false}
|
showName={false}
|
||||||
customEmitUpdate={emitSliderUpdate}
|
|
||||||
addNotification={() => null}
|
addNotification={() => null}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
@ -197,7 +163,7 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
<Form.Control
|
<Form.Control
|
||||||
type="number"
|
type="number"
|
||||||
value={stepSize}
|
value={stepSize}
|
||||||
onChange={(e) => handleValueChange(Number(e.target.value), 'stepSize')}
|
onChange={(e) => handleValueChange(Number(e.target.value), 'step_size')}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user