fixes: on updating component option should also update required hierarchical paths

This commit is contained in:
arpitnath 2024-05-04 01:23:16 +05:30 committed by Kavin Venkatachalam
parent a535b6c3d7
commit b476d4e531
2 changed files with 41 additions and 3 deletions

View file

@ -37,6 +37,7 @@ import { useEditorStore } from '@/_stores/editorStore';
import { useGridStore } from '@/_stores/gridStore';
import { useResolveStore } from '@/_stores/resolverStore';
import { handleLowPriorityWork } from './editorHelpers';
import { updateParentNodes } from './utility';
const ERROR_TYPES = Object.freeze({
ReferenceError: 'ReferenceError',
@ -134,9 +135,11 @@ export function onComponentOptionChanged(component, option_name, value) {
if (shouldUpdateRef) {
handleLowPriorityWork(() => {
useResolveStore
.getState()
.actions.updateResolvedRefsOfHints([{ hint: path, newRef: componentData[option_name] }]);
const toUpdateHints = updateParentNodes(path, componentData[option_name], option_name);
toUpdateHints.push({ hint: path, newRef: componentData[option_name] });
useResolveStore.getState().actions.updateResolvedRefsOfHints(toUpdateHints);
});
}
}

View file

@ -1,3 +1,6 @@
import { useResolveStore } from '@/_stores/resolverStore';
import _ from 'lodash';
export function validateMultilineCode(code) {
const reservedKeyword = ['app', 'window', 'this']; // Case-sensitive reserved keywords
const keywordRegex = new RegExp(`\\b(${reservedKeyword.join('|')})\\b`, 'i');
@ -51,3 +54,35 @@ export function validateMultilineCode(code) {
},
};
}
export function updateParentNodes(path, newValue) {
const pathsToUpdate = [];
const updateReceivedPath = path;
const allPathsToBeUpdated = updateReceivedPath.split('.');
let currentPath = '';
for (let i = 0; i < allPathsToBeUpdated.length; i++) {
currentPath = currentPath + allPathsToBeUpdated[i];
if (i !== allPathsToBeUpdated.length - 1) {
const lookUpTable = useResolveStore.getState().lookupTable;
const existingRef = lookUpTable.resolvedRefs?.get(lookUpTable.hints?.get(currentPath));
if (typeof existingRef === 'function') return;
const updatePath = allPathsToBeUpdated.slice(i + 1).join('.');
const newRef = _.set(existingRef, updatePath, newValue);
pathsToUpdate.push({ hint: currentPath, newRef });
}
currentPath = currentPath + '.';
}
return pathsToUpdate;
}