diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 6f321d3f3e..3405ada065 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -110,6 +110,7 @@ const EditorComponent = (props) => { showLeftSidebar, queryConfirmationList, currentPageId, + currentSessionId, } = useEditorState(); const dataQueries = useDataQueries(); @@ -142,7 +143,7 @@ const EditorComponent = (props) => { const [showPageDeletionConfirmation, setShowPageDeletionConfirmation] = useState(null); const [isDeletingPage, setIsDeletingPage] = useState(false); - const [currentSessionId, setCurrentSessionId] = useState(null); + // const [currentSessionId, setCurrentSessionId] = useState(null); const [undoStack, setUndoStack] = useState([]); const [redoStack, setRedoStack] = useState([]); @@ -204,7 +205,7 @@ const EditorComponent = (props) => { $componentDidMount(); - setCurrentSessionId(() => uuid()); + // setCurrentSessionId(() => uuid()); // 6. Unsubscribe from the observable when the component is unmounted return () => { @@ -369,6 +370,8 @@ const EditorComponent = (props) => { skipAutoSave: true, skipYmapUpdate: true, currentSessionId: ymapUpdates.currentSessionId, + componentAdding: ymapUpdates.componentAdding, + componentDeleting: ymapUpdates.componentDeleting, }); }); }; @@ -791,7 +794,36 @@ const EditorComponent = (props) => { const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition)); if (opts?.skipYmapUpdate && opts?.currentSessionId !== currentSessionId) { - updatedAppDefinition = newDefinition; + updatedAppDefinition = produce(copyOfAppDefinition, (draft) => { + const _currentPageId = useEditorStore.getState().currentPageId; + if (opts?.componentDeleting) { + const currentPageComponentIds = Object.keys(copyOfAppDefinition.pages[_currentPageId]?.components); + const newComponentIds = Object.keys(newDefinition.pages[_currentPageId]?.components); + + const finalComponents = _.omit( + draft?.pages[_currentPageId]?.components, + _.difference(currentPageComponentIds, newComponentIds) + ); + + console.log('---arpit appDefinitionChanged--- ymap only', { + finalComponents, + }); + + draft.pages[_currentPageId].components = finalComponents; + } else if (opts?.componentAdding) { + const currentPageComponentIds = Object.keys(copyOfAppDefinition.pages[_currentPageId]?.components); + const newComponentIds = Object.keys(newDefinition.pages[_currentPageId]?.components); + + const finalComponents = _.pick( + newDefinition?.pages[_currentPageId]?.components, + _.difference(newComponentIds, currentPageComponentIds) + ); + + draft.pages[_currentPageId].components = finalComponents; + } else { + Object.assign(draft, newDefinition); + } + }); } else { updatedAppDefinition = produce(copyOfAppDefinition, (draft) => { if (_.isEmpty(draft)) return; @@ -868,6 +900,7 @@ const EditorComponent = (props) => { editingVersionId: editingVersion?.id, currentSessionId, areOthersOnSameVersionAndPage, + opts, }); } }; diff --git a/frontend/src/_stores/editorStore.js b/frontend/src/_stores/editorStore.js index a42dc2ae88..6140f7d790 100644 --- a/frontend/src/_stores/editorStore.js +++ b/frontend/src/_stores/editorStore.js @@ -1,5 +1,5 @@ import { create, zustandDevTools } from './utils'; - +import { v4 as uuid } from 'uuid'; const STORE_NAME = 'Editor'; const ACTIONS = { @@ -39,6 +39,7 @@ const initialState = { showLeftSidebar: true, queryConfirmationList: [], currentPageId: null, + currentSessionId: uuid(), }; export const useEditorStore = create(