fixes: on component delete, ref should not connect to the new component dropped with same name

This commit is contained in:
arpitnath 2024-03-26 15:13:27 +05:30
parent 319464c0c5
commit 4fd2a3a1f4
4 changed files with 15 additions and 5 deletions

View file

@ -1342,6 +1342,7 @@ const EditorComponent = (props) => {
});
delete newDefinition.pages[currentPageId].components[componentId];
const platform = navigator?.userAgentData?.platform || navigator?.platform || 'unknown';
if (platform.toLowerCase().indexOf('mac') > -1) {
toast('Component deleted! (⌘ + Z to undo)', {
@ -1358,6 +1359,14 @@ const EditorComponent = (props) => {
return appDefinition.pages[currentPageId].components[id].component.name;
});
const currentComponents = newDefinition.pages[currentPageId].components;
const newComponentDefinition = useResolveStore
.getState()
.actions.findAndReplaceReferences(currentComponents, deletedComponentNames);
newDefinition.pages[currentPageId].components = newComponentDefinition;
appDefinitionChanged(newDefinition, {
componentDefinitionChanged: true,
componentDeleted: true,

View file

@ -56,7 +56,7 @@ export const useAppDataStore = create(
let updateDiff = appDefinitionDiff.updateDiff;
if (appDefinitionDiff.operation === 'update') {
updateDiff = useResolveStore.getState().actions.findReferences(updateDiff);
updateDiff = useResolveStore.getState().actions.findAndReplaceReferences(updateDiff);
}
appVersionService
@ -91,7 +91,7 @@ export const useAppDataStore = create(
const appId = get().appId;
const versionId = get().currentVersionId;
const entityIdMappingData = useResolveStore.getState().actions.findReferences(events);
const entityIdMappingData = useResolveStore.getState().actions.findAndReplaceReferences(events);
const response = await appVersionService.saveAppVersionEventHandlers(
appId,

View file

@ -464,7 +464,7 @@ export const useDataQueriesStore = create(
set({ queuedActions: { ...get().queuedActions, saveData: newValues } });
return;
}
const entityIdMappedOptions = useResolveStore.getState().actions.findReferences(newValues?.options);
const entityIdMappedOptions = useResolveStore.getState().actions.findAndReplaceReferences(newValues?.options);
useAppDataStore.getState().actions.setIsSaving(true);
set({ isUpdatingQueryInProcess: true });

View file

@ -195,8 +195,9 @@ export const useResolveStore = create(
}
},
findReferences: (obj) => {
const entityNameReferences = findAllEntityReferences(obj, []);
findAndReplaceReferences: (obj, targetEntityNames = []) => {
const entityNameReferences =
targetEntityNames.length === 0 ? findAllEntityReferences(obj, []) : targetEntityNames;
if (entityNameReferences.length === 0) return obj;