Skip to content

Commit

Permalink
fix(edit-ema): Reset Persona Selector on Internal Navigation #27306 (#…
Browse files Browse the repository at this point in the history
…27362)

* Added reset to default persona on internal navigation

* Added distint mechanism to fix double call

* Removed last logic, is other fix hehe

* Updated logic. Now refresh the persona selector on load new page

---------

Co-authored-by: Jalinson Diaz <[email protected]>
  • Loading branch information
KevinDavilaDotCMS and zJaaal authored Jan 19, 2024
1 parent 6c07db4 commit e00db60
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ describe('EditEmaEditorComponent', () => {
);
});

it('should navigate to new url when postMessage SET_URL', () => {
it('should navigate to new url and change persona when postMessage SET_URL', () => {
const router = spectator.inject(Router);
jest.spyOn(router, 'navigate');

Expand All @@ -1552,7 +1552,36 @@ describe('EditEmaEditorComponent', () => {
);

expect(router.navigate).toHaveBeenCalledWith([], {
queryParams: { url: '/some' },
queryParams: {
url: '/some',
'com.dotmarketing.persona.id': 'modes.persona.no.persona'
},
queryParamsHandling: 'merge'
});
});

it('should not change persona on load same url', () => {
const router = spectator.inject(Router);
jest.spyOn(router, 'navigate');

spectator.detectChanges();

window.dispatchEvent(
new MessageEvent('message', {
origin: HOST,
data: {
action: 'set-url',
payload: {
url: 'page-one'
}
}
})
);

expect(router.navigate).toHaveBeenCalledWith([], {
queryParams: {
url: 'page-one' //Same page as init
},
queryParamsHandling: 'merge'
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,20 @@ export class EditEmaEditorComponent implements OnInit, OnDestroy {
// This triggers a rerender that makes nextjs to send the set_url again
// But this time the params are the same so the shell component wont trigger a load and there we know that the page is loaded

if (this.activatedRouter.snapshot.queryParams.url === payload.url) {
const isSameUrl = this.activatedRouter.snapshot.queryParams.url === payload.url;

if (isSameUrl) {
this.store.updateEditorState(EDITOR_STATE.LOADED);
this.personaSelector.fetchPersonas(); // We need to fetch the personas again because the page is loaded
} else {
this.store.updateEditorState(EDITOR_STATE.LOADING);
}

this.updateQueryParams({
url: payload.url
url: payload.url,
...(isSameUrl
? {}
: { 'com.dotmarketing.persona.id': DEFAULT_PERSONA.identifier })
});
},
[CUSTOMER_ACTIONS.SET_BOUNDS]: () => {
Expand Down

0 comments on commit e00db60

Please sign in to comment.