From 8e3f2ec47481a76584663e22c9a0e72e8fcacee7 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Wed, 20 Mar 2024 00:31:30 +0530 Subject: [PATCH] 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. --- frontend/src/Editor/CodeEditor/utils.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/Editor/CodeEditor/utils.js b/frontend/src/Editor/CodeEditor/utils.js index b5a7b7f999..0a98cde67e 100644 --- a/frontend/src/Editor/CodeEditor/utils.js +++ b/frontend/src/Editor/CodeEditor/utils.js @@ -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);