handle entity references inside global settings.

added referece mapping for future improvements also.
This commit is contained in:
arpitnath 2024-04-08 18:25:37 +05:30
parent 8a64175c0a
commit 28568714dd

View file

@ -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;
});