Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix move back from collections #5367

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading