From 8e3f2ec47481a76584663e22c9a0e72e8fcacee7 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Wed, 20 Mar 2024 00:31:30 +0530 Subject: [PATCH 1/3] 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); From a2e32c9073a613cd62151f209847dbe421c94bb3 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Wed, 20 Mar 2024 00:52:47 +0530 Subject: [PATCH 2/3] re-select the query if entities are mapped and updated the store --- frontend/src/_stores/dataQueriesStore.js | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/_stores/dataQueriesStore.js b/frontend/src/_stores/dataQueriesStore.js index d905cee09a..cc4f602b78 100644 --- a/frontend/src/_stores/dataQueriesStore.js +++ b/frontend/src/_stores/dataQueriesStore.js @@ -101,6 +101,7 @@ export const useDataQueriesStore = create( set({ dataQueries }); if (type === 'mappingUpdate') { const { actions } = useQueryPanelStore.getState(); + actions.setSelectedQuery(null); const queryId = dataQueries[0]?.id; actions.setSelectedQuery(queryId); From ce185b518d2ec5a56203fac60e24b49e92b1ae69 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Wed, 20 Mar 2024 01:57:22 +0530 Subject: [PATCH 3/3] fixes: editor crash on focusing codehinter --- frontend/src/Editor/CodeEditor/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Editor/CodeEditor/utils.js b/frontend/src/Editor/CodeEditor/utils.js index 0a98cde67e..6bf6dbd7ca 100644 --- a/frontend/src/Editor/CodeEditor/utils.js +++ b/frontend/src/Editor/CodeEditor/utils.js @@ -245,7 +245,7 @@ export const resolveReferences = (query, validationSchema, customResolvers = {}, } const { toResolveReference, jsExpression, jsExpMatch } = inferJSExpAndReferences(value, lookupTable.hints); - 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. + 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);