mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
adapting components to new callback function
This commit is contained in:
parent
ff3a509132
commit
15cf0bd414
@ -1,6 +1,7 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import { ToggleButton } from 'react-bootstrap';
|
import { ToggleButton } from 'react-bootstrap';
|
||||||
import { DocStringComponent } from './DocStringComponent';
|
import { DocStringComponent } from './DocStringComponent';
|
||||||
|
import { SerializedValue } from './GenericComponent';
|
||||||
import { LevelName } from './NotificationsComponent';
|
import { LevelName } from './NotificationsComponent';
|
||||||
|
|
||||||
type ButtonComponentProps = {
|
type ButtonComponentProps = {
|
||||||
@ -10,12 +11,7 @@ type ButtonComponentProps = {
|
|||||||
docString: string;
|
docString: string;
|
||||||
mapping?: [string, string]; // Enforce a tuple of two strings
|
mapping?: [string, string]; // Enforce a tuple of two strings
|
||||||
addNotification: (message: string, levelname?: LevelName) => void;
|
addNotification: (message: string, levelname?: LevelName) => void;
|
||||||
changeCallback?: (
|
changeCallback?: (value: SerializedValue, callback?: (ack: unknown) => void) => void;
|
||||||
value: unknown,
|
|
||||||
attributeName?: string,
|
|
||||||
prefix?: string,
|
|
||||||
callback?: (ack: unknown) => void
|
|
||||||
) => void;
|
|
||||||
displayName: string;
|
displayName: string;
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@ import { Form, InputGroup } from 'react-bootstrap';
|
|||||||
import { DocStringComponent } from './DocStringComponent';
|
import { DocStringComponent } from './DocStringComponent';
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
import { LevelName } from './NotificationsComponent';
|
import { LevelName } from './NotificationsComponent';
|
||||||
|
import { SerializedValue } from './GenericComponent';
|
||||||
|
|
||||||
// TODO: add button functionality
|
// TODO: add button functionality
|
||||||
|
|
||||||
@ -38,12 +39,7 @@ type NumberComponentProps = {
|
|||||||
isInstantUpdate: boolean;
|
isInstantUpdate: boolean;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
addNotification: (message: string, levelname?: LevelName) => void;
|
addNotification: (message: string, levelname?: LevelName) => void;
|
||||||
changeCallback?: (
|
changeCallback?: (value: SerializedValue, callback?: (ack: unknown) => void) => void;
|
||||||
value: unknown,
|
|
||||||
attributeName?: string,
|
|
||||||
prefix?: string,
|
|
||||||
callback?: (ack: unknown) => void
|
|
||||||
) => void;
|
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
@ -249,7 +245,12 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
selectionEnd
|
selectionEnd
|
||||||
));
|
));
|
||||||
} else if (key === 'Enter' && !isInstantUpdate) {
|
} else if (key === 'Enter' && !isInstantUpdate) {
|
||||||
changeCallback(Number(newValue));
|
changeCallback({
|
||||||
|
type: type,
|
||||||
|
value: Number(newValue),
|
||||||
|
full_access_path: fullAccessPath,
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
console.debug(key);
|
console.debug(key);
|
||||||
@ -258,7 +259,12 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
|
|
||||||
// Update the input value and maintain the cursor position
|
// Update the input value and maintain the cursor position
|
||||||
if (isInstantUpdate) {
|
if (isInstantUpdate) {
|
||||||
changeCallback(Number(newValue));
|
changeCallback({
|
||||||
|
type: type,
|
||||||
|
value: Number(newValue),
|
||||||
|
full_access_path: fullAccessPath,
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setInputString(newValue);
|
setInputString(newValue);
|
||||||
@ -270,7 +276,12 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
const handleBlur = () => {
|
const handleBlur = () => {
|
||||||
if (!isInstantUpdate) {
|
if (!isInstantUpdate) {
|
||||||
// If not in "instant update" mode, emit an update when the input field loses focus
|
// If not in "instant update" mode, emit an update when the input field loses focus
|
||||||
changeCallback(Number(inputString));
|
changeCallback({
|
||||||
|
type: type,
|
||||||
|
value: Number(inputString),
|
||||||
|
full_access_path: fullAccessPath,
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -4,6 +4,7 @@ import { DocStringComponent } from './DocStringComponent';
|
|||||||
import { Slider } from '@mui/material';
|
import { Slider } from '@mui/material';
|
||||||
import { NumberComponent, NumberObject } from './NumberComponent';
|
import { NumberComponent, NumberObject } from './NumberComponent';
|
||||||
import { LevelName } from './NotificationsComponent';
|
import { LevelName } from './NotificationsComponent';
|
||||||
|
import { SerializedValue } from './GenericComponent';
|
||||||
|
|
||||||
type SliderComponentProps = {
|
type SliderComponentProps = {
|
||||||
fullAccessPath: string;
|
fullAccessPath: string;
|
||||||
@ -15,12 +16,7 @@ type SliderComponentProps = {
|
|||||||
stepSize: NumberObject;
|
stepSize: NumberObject;
|
||||||
isInstantUpdate: boolean;
|
isInstantUpdate: boolean;
|
||||||
addNotification: (message: string, levelname?: LevelName) => void;
|
addNotification: (message: string, levelname?: LevelName) => void;
|
||||||
changeCallback?: (
|
changeCallback?: (value: SerializedValue, callback?: (ack: unknown) => void) => void;
|
||||||
value: unknown,
|
|
||||||
attributeName?: string,
|
|
||||||
prefix?: string,
|
|
||||||
callback?: (ack: unknown) => void
|
|
||||||
) => void;
|
|
||||||
displayName: string;
|
displayName: string;
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
@ -68,11 +64,25 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
if (Array.isArray(newNumber)) {
|
if (Array.isArray(newNumber)) {
|
||||||
newNumber = newNumber[0];
|
newNumber = newNumber[0];
|
||||||
}
|
}
|
||||||
changeCallback(newNumber, `${name}.value`);
|
changeCallback({
|
||||||
|
type: value.type,
|
||||||
|
value: newNumber,
|
||||||
|
full_access_path: `${fullAccessPath}.value`,
|
||||||
|
readonly: value.readonly
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleValueChange = (newValue: number, valueType: string) => {
|
const handleValueChange = (
|
||||||
changeCallback(newValue, `${name}.${valueType}`);
|
newValue: number,
|
||||||
|
name: string,
|
||||||
|
valueObject: NumberObject
|
||||||
|
) => {
|
||||||
|
changeCallback({
|
||||||
|
type: valueObject.type,
|
||||||
|
value: newValue,
|
||||||
|
full_access_path: `${fullAccessPath}.${name}`,
|
||||||
|
readonly: valueObject.readonly
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const deconstructNumberDict = (
|
const deconstructNumberDict = (
|
||||||
@ -137,7 +147,7 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
value={valueMagnitude}
|
value={valueMagnitude}
|
||||||
unit={valueUnit}
|
unit={valueUnit}
|
||||||
addNotification={() => {}}
|
addNotification={() => {}}
|
||||||
changeCallback={(value) => changeCallback(value, name + '.value')}
|
changeCallback={changeCallback}
|
||||||
id={id + '-value'}
|
id={id + '-value'}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
@ -175,7 +185,7 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
type="number"
|
type="number"
|
||||||
value={minMagnitude}
|
value={minMagnitude}
|
||||||
disabled={minReadOnly}
|
disabled={minReadOnly}
|
||||||
onChange={(e) => handleValueChange(Number(e.target.value), 'min')}
|
onChange={(e) => handleValueChange(Number(e.target.value), 'min', min)}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
@ -185,7 +195,7 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
type="number"
|
type="number"
|
||||||
value={maxMagnitude}
|
value={maxMagnitude}
|
||||||
disabled={maxReadOnly}
|
disabled={maxReadOnly}
|
||||||
onChange={(e) => handleValueChange(Number(e.target.value), 'max')}
|
onChange={(e) => handleValueChange(Number(e.target.value), 'max', max)}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
@ -195,7 +205,9 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
|||||||
type="number"
|
type="number"
|
||||||
value={stepSizeMagnitude}
|
value={stepSizeMagnitude}
|
||||||
disabled={stepSizeReadOnly}
|
disabled={stepSizeReadOnly}
|
||||||
onChange={(e) => handleValueChange(Number(e.target.value), 'step_size')}
|
onChange={(e) =>
|
||||||
|
handleValueChange(Number(e.target.value), 'step_size', stepSize)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
@ -3,6 +3,7 @@ import { Form, InputGroup } from 'react-bootstrap';
|
|||||||
import { DocStringComponent } from './DocStringComponent';
|
import { DocStringComponent } from './DocStringComponent';
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
import { LevelName } from './NotificationsComponent';
|
import { LevelName } from './NotificationsComponent';
|
||||||
|
import { SerializedValue } from './GenericComponent';
|
||||||
|
|
||||||
// TODO: add button functionality
|
// TODO: add button functionality
|
||||||
|
|
||||||
@ -13,12 +14,7 @@ type StringComponentProps = {
|
|||||||
docString: string;
|
docString: string;
|
||||||
isInstantUpdate: boolean;
|
isInstantUpdate: boolean;
|
||||||
addNotification: (message: string, levelname?: LevelName) => void;
|
addNotification: (message: string, levelname?: LevelName) => void;
|
||||||
changeCallback?: (
|
changeCallback?: (value: SerializedValue, callback?: (ack: unknown) => void) => void;
|
||||||
value: unknown,
|
|
||||||
attributeName?: string,
|
|
||||||
prefix?: string,
|
|
||||||
callback?: (ack: unknown) => void
|
|
||||||
) => void;
|
|
||||||
displayName: string;
|
displayName: string;
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
@ -59,14 +55,24 @@ export const StringComponent = React.memo((props: StringComponentProps) => {
|
|||||||
|
|
||||||
const handleKeyDown = (event) => {
|
const handleKeyDown = (event) => {
|
||||||
if (event.key === 'Enter' && !isInstantUpdate) {
|
if (event.key === 'Enter' && !isInstantUpdate) {
|
||||||
changeCallback(inputString);
|
changeCallback({
|
||||||
|
type: 'str',
|
||||||
|
value: inputString,
|
||||||
|
full_access_path: fullAccessPath,
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBlur = () => {
|
const handleBlur = () => {
|
||||||
if (!isInstantUpdate) {
|
if (!isInstantUpdate) {
|
||||||
changeCallback(inputString);
|
changeCallback({
|
||||||
|
type: 'str',
|
||||||
|
value: inputString,
|
||||||
|
full_access_path: fullAccessPath,
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user