mirror of
https://github.com/tiqi-group/pydase.git
synced 2026-02-04 01:38:40 +01:00
feat: reset frontend value to last value on exception
When changing a value in the frontend and this operation triggers an exception in the backend, reset the frontend value to the last known value.
This commit is contained in:
@@ -50,7 +50,7 @@ const createDisplayNameFromAccessPath = (fullAccessPath: string): string => {
|
||||
|
||||
function changeCallback(
|
||||
value: SerializedObject,
|
||||
callback: (ack: unknown) => void = () => {},
|
||||
callback: (ack: undefined | SerializedObject) => void = () => {},
|
||||
) {
|
||||
updateValue(value, callback);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,10 @@ interface NumberComponentProps {
|
||||
isInstantUpdate: boolean;
|
||||
unit?: string;
|
||||
addNotification: (message: string, levelname?: LevelName) => void;
|
||||
changeCallback?: (value: SerializedObject, callback?: (ack: unknown) => void) => void;
|
||||
changeCallback?: (
|
||||
value: SerializedObject,
|
||||
callback?: (ack: undefined | SerializedObject) => void,
|
||||
) => void;
|
||||
displayName?: string;
|
||||
id: string;
|
||||
}
|
||||
@@ -217,6 +220,15 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
||||
id,
|
||||
} = props;
|
||||
|
||||
const handleChange = (newValue: SerializedObject) => {
|
||||
changeCallback(newValue, (result: undefined | SerializedObject) => {
|
||||
if (result === undefined) return;
|
||||
if (result.type == "Exception") {
|
||||
setInputString(value.toString());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Create a state for the cursor position
|
||||
const cursorPositionRef = useRef<number | null>(null);
|
||||
|
||||
@@ -319,7 +331,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
||||
};
|
||||
}
|
||||
|
||||
changeCallback(serializedObject);
|
||||
handleChange(serializedObject);
|
||||
return;
|
||||
} else {
|
||||
console.debug(key);
|
||||
@@ -350,7 +362,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
||||
};
|
||||
}
|
||||
|
||||
changeCallback(serializedObject);
|
||||
handleChange(serializedObject);
|
||||
}
|
||||
|
||||
setInputString(newValue);
|
||||
@@ -384,7 +396,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
||||
};
|
||||
}
|
||||
|
||||
changeCallback(serializedObject);
|
||||
handleChange(serializedObject);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
|
||||
@@ -19,7 +19,10 @@ interface SliderComponentProps {
|
||||
stepSize: NumberObject;
|
||||
isInstantUpdate: boolean;
|
||||
addNotification: (message: string, levelname?: LevelName) => void;
|
||||
changeCallback?: (value: SerializedObject, callback?: (ack: unknown) => void) => void;
|
||||
changeCallback?: (
|
||||
value: SerializedObject,
|
||||
callback?: (ack: undefined | SerializedObject) => void,
|
||||
) => void;
|
||||
displayName: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export const socket = io(URL, {
|
||||
|
||||
export const updateValue = (
|
||||
serializedObject: SerializedObject,
|
||||
callback?: (ack: unknown) => void,
|
||||
callback?: (ack: undefined | SerializedObject) => void,
|
||||
) => {
|
||||
if (callback) {
|
||||
socket.emit(
|
||||
|
||||
Reference in New Issue
Block a user