🐛 fix(parameterComponent): convert parameter values to numbers before assigning them to improve data consistency
🔧 chore(reactflowUtils): add utility function to convert values to numbers in an array of objects
This commit is contained in:
parent
7d3f2377a5
commit
b30f9ddf7f
2 changed files with 23 additions and 4 deletions
|
|
@ -28,6 +28,7 @@ import { ParameterComponentType } from "../../../../types/components";
|
|||
import { TabsState } from "../../../../types/tabs";
|
||||
import {
|
||||
convertObjToArray,
|
||||
convertValuesToNumbers,
|
||||
hasDuplicateKeys,
|
||||
isValidConnection,
|
||||
} from "../../../../utils/reactflowUtils";
|
||||
|
|
@ -399,9 +400,10 @@ export default function ParameterComponent({
|
|||
}
|
||||
duplicateKey={errorDuplicateKey}
|
||||
onChange={(newValue) => {
|
||||
data.node!.template[name].value = newValue;
|
||||
setErrorDuplicateKey(hasDuplicateKeys(newValue));
|
||||
handleOnNewValue(newValue);
|
||||
const valueToNumbers = convertValuesToNumbers(newValue);
|
||||
data.node!.template[name].value = valueToNumbers;
|
||||
setErrorDuplicateKey(hasDuplicateKeys(valueToNumbers));
|
||||
handleOnNewValue(valueToNumbers);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -317,4 +317,21 @@ export function hasDuplicateKeys(array) {
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function convertValuesToNumbers(arr) {
|
||||
return arr.map((obj) => {
|
||||
const newObj = {};
|
||||
for (const key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
let value = obj[key];
|
||||
if (/\s/g.test(value)) {
|
||||
value = value.trim();
|
||||
}
|
||||
newObj[key] = value === "" || isNaN(value) ? value.toString() : Number(value);
|
||||
}
|
||||
}
|
||||
return newObj;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue