mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-07 05:50:41 +02:00
fixes changing Quantity from frontend
This commit is contained in:
parent
4eddf4b980
commit
65f63e08ae
@ -102,7 +102,7 @@ export const GenericComponent = React.memo(
|
|||||||
} else if (attribute.type === 'Quantity') {
|
} else if (attribute.type === 'Quantity') {
|
||||||
return (
|
return (
|
||||||
<NumberComponent
|
<NumberComponent
|
||||||
type="float"
|
type="Quantity"
|
||||||
fullAccessPath={fullAccessPath}
|
fullAccessPath={fullAccessPath}
|
||||||
docString={attribute.doc}
|
docString={attribute.doc}
|
||||||
readOnly={attribute.readonly}
|
readOnly={attribute.readonly}
|
||||||
|
@ -31,7 +31,7 @@ export type FloatObject = {
|
|||||||
export type NumberObject = IntObject | FloatObject | QuantityObject;
|
export type NumberObject = IntObject | FloatObject | QuantityObject;
|
||||||
|
|
||||||
type NumberComponentProps = {
|
type NumberComponentProps = {
|
||||||
type: 'float' | 'int';
|
type: 'float' | 'int' | 'Quantity';
|
||||||
fullAccessPath: string;
|
fullAccessPath: string;
|
||||||
value: number;
|
value: number;
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
@ -218,7 +218,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
selectionStart,
|
selectionStart,
|
||||||
selectionEnd
|
selectionEnd
|
||||||
));
|
));
|
||||||
} else if (key === '.' && type === 'float') {
|
} else if (key === '.' && (type === 'float' || type === 'Quantity')) {
|
||||||
({ value: newValue, selectionStart } = handleNumericKey(
|
({ value: newValue, selectionStart } = handleNumericKey(
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
@ -245,9 +245,16 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
selectionEnd
|
selectionEnd
|
||||||
));
|
));
|
||||||
} else if (key === 'Enter' && !isInstantUpdate) {
|
} else if (key === 'Enter' && !isInstantUpdate) {
|
||||||
|
let updatedValue: number | Record<string, unknown> = Number(newValue);
|
||||||
|
if (type === 'Quantity') {
|
||||||
|
updatedValue = {
|
||||||
|
magnitude: Number(newValue),
|
||||||
|
unit: unit
|
||||||
|
};
|
||||||
|
}
|
||||||
changeCallback({
|
changeCallback({
|
||||||
type: type,
|
type: type,
|
||||||
value: Number(newValue),
|
value: updatedValue,
|
||||||
full_access_path: fullAccessPath,
|
full_access_path: fullAccessPath,
|
||||||
readonly: readOnly,
|
readonly: readOnly,
|
||||||
doc: docString
|
doc: docString
|
||||||
@ -260,9 +267,16 @@ 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) {
|
||||||
|
let updatedValue: number | Record<string, unknown> = Number(newValue);
|
||||||
|
if (type === 'Quantity') {
|
||||||
|
updatedValue = {
|
||||||
|
magnitude: Number(newValue),
|
||||||
|
unit: unit
|
||||||
|
};
|
||||||
|
}
|
||||||
changeCallback({
|
changeCallback({
|
||||||
type: type,
|
type: type,
|
||||||
value: Number(newValue),
|
value: updatedValue,
|
||||||
full_access_path: fullAccessPath,
|
full_access_path: fullAccessPath,
|
||||||
readonly: readOnly,
|
readonly: readOnly,
|
||||||
doc: docString
|
doc: docString
|
||||||
@ -278,9 +292,16 @@ 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
|
||||||
|
let updatedValue: number | Record<string, unknown> = Number(inputString);
|
||||||
|
if (type === 'Quantity') {
|
||||||
|
updatedValue = {
|
||||||
|
magnitude: Number(inputString),
|
||||||
|
unit: unit
|
||||||
|
};
|
||||||
|
}
|
||||||
changeCallback({
|
changeCallback({
|
||||||
type: type,
|
type: type,
|
||||||
value: Number(inputString),
|
value: updatedValue,
|
||||||
full_access_path: fullAccessPath,
|
full_access_path: fullAccessPath,
|
||||||
readonly: readOnly,
|
readonly: readOnly,
|
||||||
doc: docString
|
doc: docString
|
||||||
|
Loading…
x
Reference in New Issue
Block a user