🐛 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 { TabsState } from "../../../../types/tabs";
|
||||||
import {
|
import {
|
||||||
convertObjToArray,
|
convertObjToArray,
|
||||||
|
convertValuesToNumbers,
|
||||||
hasDuplicateKeys,
|
hasDuplicateKeys,
|
||||||
isValidConnection,
|
isValidConnection,
|
||||||
} from "../../../../utils/reactflowUtils";
|
} from "../../../../utils/reactflowUtils";
|
||||||
|
|
@ -399,9 +400,10 @@ export default function ParameterComponent({
|
||||||
}
|
}
|
||||||
duplicateKey={errorDuplicateKey}
|
duplicateKey={errorDuplicateKey}
|
||||||
onChange={(newValue) => {
|
onChange={(newValue) => {
|
||||||
data.node!.template[name].value = newValue;
|
const valueToNumbers = convertValuesToNumbers(newValue);
|
||||||
setErrorDuplicateKey(hasDuplicateKeys(newValue));
|
data.node!.template[name].value = valueToNumbers;
|
||||||
handleOnNewValue(newValue);
|
setErrorDuplicateKey(hasDuplicateKeys(valueToNumbers));
|
||||||
|
handleOnNewValue(valueToNumbers);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -318,3 +318,20 @@ export function hasDuplicateKeys(array) {
|
||||||
}
|
}
|
||||||
return false;
|
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