From f1c2d9038a05f2863dd59fec8caf5377bb55b988 Mon Sep 17 00:00:00 2001 From: Jalinson Diaz Date: Fri, 20 Oct 2023 14:08:42 -0300 Subject: [PATCH] fix(core): Edit Options not Showing on UrlContent Page #26314 * dev (edit page state controller): regenerate menuItems when navigating inside the iframe * fix (edit page state controller): test was broken --- ...it-page-state-controller.component.spec.ts | 31 +++++++++++++++++ ...ot-edit-page-state-controller.component.ts | 8 ++++- ...age-state-controller-seo.component.spec.ts | 33 ++++++++++++++++++- ...dit-page-state-controller-seo.component.ts | 8 ++++- 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.spec.ts b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.spec.ts index 282e1ad5a305..88c765177262 100644 --- a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.spec.ts +++ b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.spec.ts @@ -585,5 +585,36 @@ describe('DotEditPageStateControllerComponent', () => { component.menu.onHide.emit(); expect(resetMock).toHaveBeenCalledWith(DotPageMode.EDIT); }); + + it('should have menuItems if the page goes from not having urlContentMap to having it', async () => { + let pageRenderStateMocked: DotPageRenderState = new DotPageRenderState( + { ...mockUser(), userId: '457' }, + { + ...mockDotRenderedPage() + } + ); + fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked); + fixtureHost.detectChanges(); + + await fixtureHost.whenStable(); + expect(component.menuItems.length).toBe(0); + + pageRenderStateMocked = new DotPageRenderState( + { ...mockUser(), userId: '457' }, + { + ...mockDotRenderedPage(), + urlContentMap: { + title: 'Title', + inode: '123', + contentType: 'test' + } + } + ); + fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked); + fixtureHost.detectChanges(); + + await fixtureHost.whenStable(); + expect(component.menuItems.length).toBe(2); + }); }); }); diff --git a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.ts b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.ts index b105a440702a..9f6a1263256a 100644 --- a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.ts +++ b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/content/components/dot-edit-page-state-controller/dot-edit-page-state-controller.component.ts @@ -58,7 +58,7 @@ export class DotEditPageStateControllerComponent implements OnChanges, OnInit { mode: DotPageMode; options: SelectItem[] = []; featureFlagEditURLContentMapIsOn = false; - menuItems: MenuItem[]; + menuItems: MenuItem[] = []; readonly dotPageMode = DotPageMode; readonly featureFlagEditURLContentMap = FeaturedFlags.FEATURE_FLAG_EDIT_URL_CONTENT_MAP; @@ -89,6 +89,12 @@ export class DotEditPageStateControllerComponent implements OnChanges, OnInit { this.lock = this.isLocked(pageState); this.lockWarn = this.shouldWarnLock(pageState); this.mode = pageState.state.mode; + + if (this.featureFlagEditURLContentMapIsOn && pageState.params.urlContentMap) { + this.menuItems = this.getMenuItems(); + } else if (this.menuItems.length) { + this.menuItems = []; // We have to clean the menu items because the menu is not re-rendered when the flag is off or the urlContentMap is null + } } } diff --git a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.spec.ts b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.spec.ts index d8a1d99d10e1..41bb090e4fb2 100644 --- a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.spec.ts +++ b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.spec.ts @@ -553,7 +553,7 @@ describe('DotEditPageStateControllerSeoComponent', () => { }); it('should not have menuItems if page does not have URLContentMap', async () => { - expect(component.menuItems).toBe(undefined); + expect(component.menuItems.length).toBe(0); }); }); @@ -617,5 +617,36 @@ describe('DotEditPageStateControllerSeoComponent', () => { expect(dotTabButtons.resetDropdownById).toHaveBeenCalledWith(DotPageMode.PREVIEW); }); + + it('should have menuItems if the page goes from not having urlContentMap to having it', async () => { + let pageRenderStateMocked: DotPageRenderState = new DotPageRenderState( + { ...mockUser(), userId: '457' }, + { + ...mockDotRenderedPage() + } + ); + fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked); + fixtureHost.detectChanges(); + + await fixtureHost.whenStable(); + expect(component.menuItems.length).toBe(0); + + pageRenderStateMocked = new DotPageRenderState( + { ...mockUser(), userId: '457' }, + { + ...mockDotRenderedPage(), + urlContentMap: { + title: 'Title', + inode: '123', + contentType: 'test' + } + } + ); + fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked); + fixtureHost.detectChanges(); + + await fixtureHost.whenStable(); + expect(component.menuItems.length).toBe(2); + }); }); }); diff --git a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.ts b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.ts index ad63c3635fcf..5f1523944549 100644 --- a/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.ts +++ b/core-web/apps/dotcms-ui/src/app/portlets/dot-edit-page/seo/components/dot-edit-page-state-controller-seo/dot-edit-page-state-controller-seo.component.ts @@ -87,7 +87,7 @@ export class DotEditPageStateControllerSeoComponent implements OnInit, OnChanges featureFlagEditURLContentMapIsOn = false; mode: DotPageMode; options: SelectItem[] = []; - menuItems: MenuItem[]; + menuItems: MenuItem[] = []; readonly dotPageMode = DotPageMode; @@ -128,6 +128,12 @@ export class DotEditPageStateControllerSeoComponent implements OnInit, OnChanges this.lock = this.isLocked(pageState); this.lockWarn = this.shouldWarnLock(pageState); this.mode = pageState.state.mode; + + if (this.featureFlagEditURLContentMapIsOn && pageState.params.urlContentMap) { + this.menuItems = this.getMenuItems(); + } else if (this.menuItems.length) { + this.menuItems = []; // We have to clean the menu items because the menu is not re-rendered when the flag is off or the urlContentMap is null + } } }