mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
handle entity references inside global settings.
added referece mapping for future improvements also.
This commit is contained in:
parent
8a64175c0a
commit
28568714dd
1 changed files with 28 additions and 3 deletions
|
|
@ -19,8 +19,6 @@ import { componentTypes } from './WidgetManager/components';
|
|||
import { Inspector } from './Inspector/Inspector';
|
||||
import QueryPanel from './QueryPanel/QueryPanel';
|
||||
import {
|
||||
onComponentOptionChanged,
|
||||
onComponentOptionsChanged,
|
||||
onEvent,
|
||||
onQueryConfirmOrCancel,
|
||||
runQuery,
|
||||
|
|
@ -1402,10 +1400,15 @@ const EditorComponent = (props) => {
|
|||
|
||||
const updateEntityReferences = (appJson, pageId) => {
|
||||
const currentComponents = appJson?.pages?.[pageId]?.components;
|
||||
const globalSettings = appJson['globalSettings'];
|
||||
|
||||
let dataQueries = JSON.parse(JSON.stringify(useDataQueriesStore.getState().dataQueries));
|
||||
let allEvents = JSON.parse(JSON.stringify(useAppDataStore.getState().events));
|
||||
|
||||
const entittyReferencesInGlobalSettings = findAllEntityReferences(globalSettings, [])?.filter(
|
||||
(entity) => entity && isValidUUID(entity)
|
||||
);
|
||||
|
||||
const entityReferencesInComponentDefinitions = findAllEntityReferences(currentComponents, [])?.filter(
|
||||
(entity) => entity && isValidUUID(entity)
|
||||
);
|
||||
|
|
@ -1420,6 +1423,27 @@ const EditorComponent = (props) => {
|
|||
|
||||
const manager = useResolveStore.getState().referenceMapper;
|
||||
|
||||
if (Array.isArray(entittyReferencesInGlobalSettings) && entittyReferencesInGlobalSettings?.length > 0) {
|
||||
let newGlobalSettings = JSON.parse(JSON.stringify(globalSettings));
|
||||
entittyReferencesInGlobalSettings.forEach((entity) => {
|
||||
const entityrefExists = manager.has(entity);
|
||||
|
||||
if (entityrefExists) {
|
||||
const value = manager.get(entity);
|
||||
newGlobalSettings = dfs(newGlobalSettings, entity, value);
|
||||
}
|
||||
});
|
||||
|
||||
const newAppDefinition = produce(appJson, (draft) => {
|
||||
draft.globalSettings = newGlobalSettings;
|
||||
});
|
||||
|
||||
updateEditorState({
|
||||
isUpdatingEditorStateInProcess: false,
|
||||
appDefinition: newAppDefinition,
|
||||
});
|
||||
}
|
||||
|
||||
if (Array.isArray(entityReferencesInComponentDefinitions) && entityReferencesInComponentDefinitions?.length > 0) {
|
||||
let newComponentDefinition = JSON.parse(JSON.stringify(currentComponents));
|
||||
|
||||
|
|
@ -1432,7 +1456,8 @@ const EditorComponent = (props) => {
|
|||
}
|
||||
});
|
||||
|
||||
const newAppDefinition = produce(appJson, (draft) => {
|
||||
const appDefinition = useEditorStore.getState().appDefinition;
|
||||
const newAppDefinition = produce(appDefinition, (draft) => {
|
||||
draft.pages[pageId].components = newComponentDefinition;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue