Skip to content

Commit

Permalink
feat: incorporate submenu items ordering in config:sync command (#3689)
Browse files Browse the repository at this point in the history
* feat: add check for submenu item order change

* feat: incorporate submenu items ordering in config:sync command

* chore: imporve variable name

* chore: update tests for submenu items order change

* chore: add a changeset for updating submenu item order from the configuration file

* chore: correct changeset file
  • Loading branch information
mustafaasif2 authored Jan 22, 2025
1 parent 6ece19a commit f6827aa
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-gorillas-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/mc-scripts': minor
---

Update the `mc-scripts config:sync` command to synchronize submenu item order from the configuration file to the database.
70 changes: 70 additions & 0 deletions packages/mc-scripts/src/utils/get-config-diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ describe('Custom Application Config Diff', () => {
expect(getCustomApplicationConfigDiff(oldConfig, newConfig))
.toMatchInlineSnapshot(`
"submenuLink changed
submenu order changed
previous order: []
new order: [my-test-app/new]
menu link added: <color-green>my-test-app/new</color-green>"
`);
});
Expand Down Expand Up @@ -344,6 +347,9 @@ describe('Custom Application Config Diff', () => {
expect(getCustomApplicationConfigDiff(oldConfig, newConfig))
.toMatchInlineSnapshot(`
"submenuLink changed
submenu order changed
previous order: [my-test-app/new]
new order: []
menu link removed: <color-red>my-test-app/new</color-red>"
`);
});
Expand Down Expand Up @@ -401,6 +407,70 @@ describe('Custom Application Config Diff', () => {
locale removed: <color-red>en</color-red>"
`);
});

it('should display diff when submenu items are reordered', () => {
const oldConfig = createTestCustomApplicationConfig({
submenuLinks: [
{
uriPath: 'my-test-app/first',
defaultLabel: 'First Item',
permissions: ['ManageMyTestApp'],
labelAllLocales: [
{
locale: 'de',
value: 'Erstes Element',
},
],
},
{
uriPath: 'my-test-app/second',
defaultLabel: 'Second Item',
permissions: ['ManageMyTestApp'],
labelAllLocales: [
{
locale: 'de',
value: 'Zweites Element',
},
],
},
],
});

const newConfig = createTestCustomApplicationConfig({
submenuLinks: [
{
uriPath: 'my-test-app/second',
defaultLabel: 'Second Item',
permissions: ['ManageMyTestApp'],
labelAllLocales: [
{
locale: 'de',
value: 'Zweites Element',
},
],
},
{
uriPath: 'my-test-app/first',
defaultLabel: 'First Item',
permissions: ['ManageMyTestApp'],
labelAllLocales: [
{
locale: 'de',
value: 'Erstes Element',
},
],
},
],
});

expect(getCustomApplicationConfigDiff(oldConfig, newConfig))
.toMatchInlineSnapshot(`
"submenuLink changed
submenu order changed
previous order: [my-test-app/first, my-test-app/second]
new order: [my-test-app/second, my-test-app/first]"
`);
});
});
});
});
Expand Down
12 changes: 12 additions & 0 deletions packages/mc-scripts/src/utils/get-config-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ const getSubmenuLinksDiff = ({
{}
);

const getOrder = (value: { uriPath: string }[]): string =>
value.map((link) => link.uriPath).join(', ');

const previousOrder = getOrder(previousValue);
const newOrder = getOrder(nextValue);

if (previousOrder !== newOrder) {
submenuLinksDiff.push(`${indent(1)}submenu order changed`);
submenuLinksDiff.push(`${indent(2)}previous order: [${previousOrder}]`);
submenuLinksDiff.push(`${indent(2)}new order: [${newOrder}]`);
}

nextValue.forEach((newSubmenuLink) => {
const oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
Expand Down

0 comments on commit f6827aa

Please sign in to comment.