Skip to content

Commit

Permalink
Merge pull request #87 from zanna-37/feat/preserve-url-params
Browse files Browse the repository at this point in the history
Preserve url params
  • Loading branch information
zanna-37 authored Nov 11, 2024
2 parents 4074e4d + 9845d13 commit 51f8bb9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/swipeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,16 @@ class SwipeManager {
}

private static navigateTo(viewName: string) {
const queryString = window.location.search;
const hashFragment = window.location.hash;
const panelName = ConfigManager.getPanel();
window.history.pushState(null,"","/" + panelName + "/" + viewName);
window.dispatchEvent(new CustomEvent("location-changed"));

const targetUrl = "/" + panelName + "/" + viewName + queryString + hashFragment;

if (window.location.pathname + window.location.search + window.location.hash !== targetUrl) {
window.history.pushState(null,"",targetUrl);
window.dispatchEvent(new CustomEvent("location-changed"));
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/dashboards/individual-dashboards/preserve-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from "@playwright/test";
import { SwipeHelper } from "../../helpers/touchHelpers";

test("should preserve URL, using defaults", async ({ page }) => {
const urlParams = "?thishouldbe=preserved#hashtopreserve";

const dashboardPath = "/default-values";
await page.goto(dashboardPath + "/0" + urlParams);
await expect(page).toHaveURL(dashboardPath + "/0" + urlParams);

const haAppLayout = page.locator("[id='view']");

await SwipeHelper.swipeLeft(haAppLayout);
await expect(page).toHaveURL(dashboardPath + "/1" + urlParams);
});

0 comments on commit 51f8bb9

Please sign in to comment.