Fix: Update reference resolution logic for dynamic component variables

This commit updates the reference resolution logic to ensure that only component references are resolved using the legacy approach. Due to recent changes where we stopped updating references upon currentState changes, exposed variables of components have become dynamic and uncontrollable. The updated logic now checks if a reference starts with 'components.' before proceeding with the legacy resolution method. This change maintains the integrity of our component reference resolution while accommodating the new dynamic nature of component variables.

The conditional structure has been adjusted to specifically identify component values, thereby preventing inappropriate application of the legacy resolution method to non-component references. This ensures that our reference resolution remains accurate and consistent with the updated system behavior.
This commit is contained in:
arpitnath 2024-03-20 00:31:30 +05:30
parent f6391c3e99
commit 8e3f2ec474

View file

@ -183,6 +183,8 @@ function getDynamicVariables(text) {
const resolveMultiDynamicReferences = (code, lookupTable) => {
let resolvedValue = code;
const isComponentValue = code.includes('components.') || false;
const allDynamicVariables = getDynamicVariables(code);
if (allDynamicVariables) {
@ -191,13 +193,14 @@ const resolveMultiDynamicReferences = (code, lookupTable) => {
const { toResolveReference } = inferJSExpAndReferences(variableToResolve, lookupTable.hints);
if (toResolveReference && lookupTable.hints.has(toResolveReference)) {
if (!isComponentValue && toResolveReference && lookupTable.hints.has(toResolveReference)) {
const idToLookUp = lookupTable.hints.get(variableToResolve);
const res = lookupTable.resolvedRefs.get(idToLookUp);
resolvedValue = resolvedValue.replace(variable, res);
} else {
const [resolvedCode] = resolveCode(variableToResolve, lookupTable, {}, true, [], true);
const currentState = useCurrentStateStore.getState();
const [resolvedCode] = resolveCode(variableToResolve, currentState, {}, true, [], true);
resolvedValue = resolvedCode;
}
@ -242,8 +245,8 @@ export const resolveReferences = (query, validationSchema, customResolvers = {},
}
const { toResolveReference, jsExpression, jsExpMatch } = inferJSExpAndReferences(value, lookupTable.hints);
if (!jsExpMatch && toResolveReference && lookupTable.hints.has(toResolveReference)) {
const isComponentValue = toResolveReference.startsWith('components.') || false; //!Notes: As we removed the updating of references on currentState changes, exposed variable of components are dynamic and cannot be controlled in any form, so we are resolving only components references with our legacy approach.
if (!isComponentValue && !jsExpMatch && toResolveReference && lookupTable.hints.has(toResolveReference)) {
const idToLookUp = lookupTable.hints.get(toResolveReference);
resolvedValue = lookupTable.resolvedRefs.get(idToLookUp);