mirror of
https://github.com/tiqi-group/pydase.git
synced 2026-02-06 02: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(
|
function changeCallback(
|
||||||
value: SerializedObject,
|
value: SerializedObject,
|
||||||
callback: (ack: unknown) => void = () => {},
|
callback: (ack: undefined | SerializedObject) => void = () => {},
|
||||||
) {
|
) {
|
||||||
updateValue(value, callback);
|
updateValue(value, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ interface NumberComponentProps {
|
|||||||
isInstantUpdate: boolean;
|
isInstantUpdate: boolean;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
addNotification: (message: string, levelname?: LevelName) => void;
|
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;
|
displayName?: string;
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
@@ -217,6 +220,15 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
id,
|
id,
|
||||||
} = props;
|
} = 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
|
// Create a state for the cursor position
|
||||||
const cursorPositionRef = useRef<number | null>(null);
|
const cursorPositionRef = useRef<number | null>(null);
|
||||||
|
|
||||||
@@ -319,7 +331,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
changeCallback(serializedObject);
|
handleChange(serializedObject);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
console.debug(key);
|
console.debug(key);
|
||||||
@@ -350,7 +362,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
changeCallback(serializedObject);
|
handleChange(serializedObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInputString(newValue);
|
setInputString(newValue);
|
||||||
@@ -384,7 +396,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
changeCallback(serializedObject);
|
handleChange(serializedObject);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ interface SliderComponentProps {
|
|||||||
stepSize: NumberObject;
|
stepSize: NumberObject;
|
||||||
isInstantUpdate: boolean;
|
isInstantUpdate: boolean;
|
||||||
addNotification: (message: string, levelname?: LevelName) => void;
|
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;
|
displayName: string;
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const socket = io(URL, {
|
|||||||
|
|
||||||
export const updateValue = (
|
export const updateValue = (
|
||||||
serializedObject: SerializedObject,
|
serializedObject: SerializedObject,
|
||||||
callback?: (ack: unknown) => void,
|
callback?: (ack: undefined | SerializedObject) => void,
|
||||||
) => {
|
) => {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
socket.emit(
|
socket.emit(
|
||||||
|
|||||||
Reference in New Issue
Block a user