Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/version screens bug #16

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/Menu/Items/OperationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -125,6 +125,7 @@ export const OperationScreen = ({
[name]: meta,
};
}, {});
if (Object.keys(meta).length === 0) meta = undefined;
let startPublication;
if (rest.startPublication) {
if (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Menu/Revisions/Diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
};
Expand All @@ -369,7 +369,7 @@ export const MenuRevisionsDiff = ({ id, diff, snapshot }: Props) => {
return (
<Box className="flex flex-col my-2" key={index}>
<Typography variant="h5" component="h5">
{to.order || from.order}. {to.label || from.label}
{to.order || from?.order}. {to.label || from?.label}
</Typography>
<Typography variant="body1" component="p" sx={{ ml: '1rem', color: 'success.main' }}>
{t('common.added', { context: 'male' })}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Menu/Revisions/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
22 changes: 15 additions & 7 deletions src/pages/Menu/Revisions/Publish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 12 additions & 7 deletions src/pages/Menu/Revisions/Restore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down