diff --git a/src/components/Menu/Items/OperationScreen.tsx b/src/components/Menu/Items/OperationScreen.tsx index c68f3e2..e61a5cc 100644 --- a/src/components/Menu/Items/OperationScreen.tsx +++ b/src/components/Menu/Items/OperationScreen.tsx @@ -113,7 +113,7 @@ export const OperationScreen = ({ action, ...rest } = node; - const meta = Object.keys(rest.meta).reduce((acc, key) => { + let meta = Object.keys(rest.meta).reduce((acc, key) => { const name = data.menu.meta.find(meta => meta.id === Number(key))?.name || key; const meta = rest.meta[key]; const originalMeta = original?.meta[key] || original?.meta[name]; @@ -125,6 +125,7 @@ export const OperationScreen = ({ [name]: meta, }; }, {}); + if (Object.keys(meta).length === 0) meta = undefined; let startPublication; if (rest.startPublication) { if ( diff --git a/src/components/Menu/Revisions/Diff.tsx b/src/components/Menu/Revisions/Diff.tsx index 2ce330d..4886d5a 100644 --- a/src/components/Menu/Revisions/Diff.tsx +++ b/src/components/Menu/Revisions/Diff.tsx @@ -346,7 +346,7 @@ export const MenuRevisionsDiff = ({ id, diff, snapshot }: Props) => { break; } children = getChildren(parentId, items[i].children); - if (children) break; + if (children && children.length > 0) break; } return children || []; }; @@ -369,7 +369,7 @@ export const MenuRevisionsDiff = ({ id, diff, snapshot }: Props) => { return ( - {to.order || from.order}. {to.label || from.label} + {to.order || from?.order}. {to.label || from?.label} {t('common.added', { context: 'male' })} diff --git a/src/pages/Menu/Revisions/Create.tsx b/src/pages/Menu/Revisions/Create.tsx index 6c54682..fbe2567 100644 --- a/src/pages/Menu/Revisions/Create.tsx +++ b/src/pages/Menu/Revisions/Create.tsx @@ -128,7 +128,8 @@ const CreateRevision = () => { }); let currentItems = [...menu.items]; const updatedItems = setUpdatedItems(snapshot.items, currentItems); - currentItems = [...(updatedItems || []), ...(currentItems || [])].filter((item, index, arr) => { + currentItems = [...(currentItems || []), ...(updatedItems || [])]; + currentItems = currentItems.filter((item, index, arr) => { if (item === null) return true; return arr.findIndex(i => i?.id === item.id) === index; }); diff --git a/src/pages/Menu/Revisions/Publish.tsx b/src/pages/Menu/Revisions/Publish.tsx index 93b1425..e345fbf 100644 --- a/src/pages/Menu/Revisions/Publish.tsx +++ b/src/pages/Menu/Revisions/Publish.tsx @@ -121,15 +121,23 @@ const PublishRevision = () => { return { ...current, children: setUpdatedItems(current.children, item.children) }; }); const updatedItems = setUpdatedItems(snapshot.items, publishedRevision?.snapshot.items); - snapshot.items = [...(snapshot.items || []), ...(updatedItems || [])].filter( - (item, index, arr) => { - if (item === null) return true; - return arr.findIndex(i => i?.id === item.id) === index; - }, - ); + + if ( + !data.menu.publishedRevision || + selectedRevision.createdAt > data.menu.publishedRevision.createdAt + ) { + snapshot.items = [...(snapshot.items || []), ...(updatedItems || [])]; + } else { + snapshot.items = [...(updatedItems || []), ...(snapshot.items || [])]; + } + + snapshot.items = snapshot.items.filter((item, index, arr) => { + if (item === null) return true; + return arr.findIndex(i => i?.id === item.id) === index; + }); const diff = menuRevisionDiff(publishedRevision?.snapshot || {}, snapshot); return diff; - }, [publishedRevision, selectedRevision, getChildren]); + }, [publishedRevision, selectedRevision, getChildren, data]); const renderMenuRevisions = () => { if (!data?.menu.revisions?.length) return null; diff --git a/src/pages/Menu/Revisions/Restore.tsx b/src/pages/Menu/Revisions/Restore.tsx index 4cf9656..6a2d2b1 100644 --- a/src/pages/Menu/Revisions/Restore.tsx +++ b/src/pages/Menu/Revisions/Restore.tsx @@ -117,15 +117,20 @@ const RestoreRevision = () => { return { ...current, children: setUpdatedItems(current.children, item.children) }; }); const updatedItems = setUpdatedItems(snapshot.items, menu.items); - snapshot.items = [...(snapshot.items || []), ...(updatedItems || [])].filter( - (item, index, arr) => { - if (item === null) return true; - return arr.findIndex(i => i?.id === item.id) === index; - }, - ); + + if (selectedRevision.createdAt > data.menu.currentRevision.createdAt) { + snapshot.items = [...(snapshot.items || []), ...(updatedItems || [])]; + } else { + snapshot.items = [...(updatedItems || []), ...(snapshot.items || [])]; + } + + snapshot.items = snapshot.items.filter((item, index, arr) => { + if (item === null) return true; + return arr.findIndex(i => i?.id === item.id) === index; + }); const diff = menuRevisionDiff(menu, snapshot); return diff; - }, [menu, selectedRevision, getChildren]); + }, [menu, selectedRevision, getChildren, data]); const renderMenuRevisions = () => { if (!data?.menu.revisions?.length) return null;