Skip to content

Commit

Permalink
Fix move back from collections (#5367)
Browse files Browse the repository at this point in the history
* Fix move back from collections

* Add changeset
  • Loading branch information
poulch authored Jan 24, 2025
1 parent fbfc969 commit 70dbf11
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wild-seals-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

You can now navigate back from collection details to collection list
22 changes: 22 additions & 0 deletions src/hooks/useBackLinkWithState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@ describe("useBackLinkWithState", () => {
// Assert
expect(result.current).toBe("/orders/drafts?asc=false&after=cursor");
});

it("should omit /dashboard from pathname when returning the previous URL", () => {
// Arrange
(useLocation as jest.Mock).mockReturnValue({
state: {
prevLocation: {
pathname: "/dashboard/collections/Q29sbGVjdGlvbjoxNjY",
search: "",
},
},
});

// Act
const { result } = renderHook(() =>
useBackLinkWithState({
path: "/collections",
}),
);

// Assert
expect(result.current).toBe("/collections/Q29sbGVjdGlvbjoxNjY");
});
});
4 changes: 3 additions & 1 deletion src/hooks/useBackLinkWithState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const getPreviousUrl = (location: LocationWithState) => {

const { pathname, search } = location.state.prevLocation;

return urljoin(pathname, search);
const withRemovedDashboard = pathname.replace(/^\/dashboard/, "");

return urljoin(withRemovedDashboard, search);
};

interface UseBackLinkWithState {
Expand Down

0 comments on commit 70dbf11

Please sign in to comment.