mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 01:18:23 +00:00
fixes: on updating component option should also update required hierarchical paths
This commit is contained in:
parent
a535b6c3d7
commit
b476d4e531
2 changed files with 41 additions and 3 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue