Skip to content

Commit

Permalink
Fix redirect action in new context and relative urls (#4666)
Browse files Browse the repository at this point in the history
* Fix redirect action in new context and relative urls

* Add changeset
  • Loading branch information
typeofweb committed Feb 8, 2024
1 parent 9a48841 commit ce4eb48
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-falcons-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix redirect action in new context and relative urls
13 changes: 6 additions & 7 deletions src/apps/components/AppFrame/appActionsHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jest.spyOn(ExternalAppContext, "useExternalApp").mockImplementation(() => ({

jest
.spyOn(dashboardConfig, "getAppMountUri")
.mockImplementation(() => "http://localhost:3000");
// getAppMountUri is not an URI, it's a pathname
.mockImplementation(() => "/dashboard/");

jest.spyOn(ReactIntl, "useIntl").mockImplementation(
// @ts-expect-error - only mock required method
Expand Down Expand Up @@ -135,7 +136,7 @@ describe("AppActionsHandler", function () {
expect(mockHistoryPushState).toHaveBeenCalledWith(
null,
"",
"http://localhost:3000/apps/XYZ/app/foo/bar",
"/dashboard/apps/XYZ/app/foo/bar",
);
});
});
Expand Down Expand Up @@ -181,9 +182,7 @@ describe("AppActionsHandler", function () {
});

expect(mockWindowOpen).toHaveBeenCalledTimes(1);
expect(mockWindowOpen).toHaveBeenCalledWith(
"http://localhost:3000/orders",
);
expect(mockWindowOpen).toHaveBeenCalledWith("/dashboard/orders");
});

/**
Expand All @@ -203,7 +202,7 @@ describe("AppActionsHandler", function () {

expect(mockWindowOpen).toHaveBeenCalledTimes(1);
expect(mockWindowOpen).toHaveBeenCalledWith(
"http://localhost:3000/apps/XYZ/app/config",
"/dashboard/apps/XYZ/app/config",
);
});
});
Expand Down Expand Up @@ -263,7 +262,7 @@ describe("AppActionsHandler", function () {
expect(mockHistoryPushState).toHaveBeenCalledWith(
null,
"",
"http://localhost:3000/apps/XYZ/app/config",
"/dashboard/apps/XYZ/app/config",
);
});
});
Expand Down
7 changes: 3 additions & 4 deletions src/apps/components/AppFrame/appActionsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ const useHandleRedirectAction = (appId: string) => {

const handleLocalDashboardPathChange = (action: RedirectAction) => {
if (action.payload.newContext) {
const url = new URL(action.payload.to, getAppMountUri());

window.open(url.href);
const exactLocation = urlJoin(getAppMountUri(), action.payload.to);
window.open(exactLocation);
} else {
navigate(action.payload.to);
closeApp();
Expand Down Expand Up @@ -149,7 +148,7 @@ const useHandleRedirectAction = (appId: string) => {
* Assume failure if nothing catched
*/
console.error(
"Couldnt handle Redirect action properly, this should not happen",
"Couldn't handle Redirect action properly, this should not happen",
);
return createResponseStatus(actionId, false);
},
Expand Down

0 comments on commit ce4eb48

Please sign in to comment.