From 2c4239d79a0f112e9e1420e71489f6241ee1215d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 4 Apr 2021 23:19:08 +0200 Subject: [PATCH] web: allow for non-path elements in hash, store current tab page in hash Signed-off-by: Jens Langhammer --- web/src/constants.ts | 1 + web/src/elements/Tabs.ts | 21 ++++++++++++++--- web/src/elements/router/RouterOutlet.ts | 26 +++++++++++++++++---- web/src/elements/sidebar/Sidebar.ts | 5 ++-- web/src/pages/policies/PolicyBindingForm.ts | 4 ++-- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/web/src/constants.ts b/web/src/constants.ts index e21c53ad4..f111e34d1 100644 --- a/web/src/constants.ts +++ b/web/src/constants.ts @@ -10,3 +10,4 @@ export const EVENT_NOTIFICATION_TOGGLE = "ak-notification-toggle"; export const EVENT_SIDEBAR_TOGGLE = "ak-sidebar-toggle"; export const EVENT_API_DRAWER_REFRESH = "ak-api-drawer-refresh"; export const TITLE_SUFFIX = "authentik"; +export const ROUTE_SEPARATOR = ";"; diff --git a/web/src/elements/Tabs.ts b/web/src/elements/Tabs.ts index a417603cf..a7895b455 100644 --- a/web/src/elements/Tabs.ts +++ b/web/src/elements/Tabs.ts @@ -3,7 +3,7 @@ import { ifDefined } from "lit-html/directives/if-defined"; import PFTabs from "@patternfly/patternfly/components/Tabs/tabs.css"; import PFGlobal from "@patternfly/patternfly/patternfly-base.css"; import AKGlobal from "../authentik.css"; -import { CURRENT_CLASS } from "../constants"; +import { CURRENT_CLASS, ROUTE_SEPARATOR } from "../constants"; import { t } from "@lingui/macro"; @customElement("ak-tabs") @@ -50,10 +50,17 @@ export class Tabs extends LitElement { super.disconnectedCallback(); } + onClick(slot?: string): void { + this.currentPage = slot; + const currentUrl = window.location.hash.slice(1, Infinity).split(ROUTE_SEPARATOR)[0]; + const newUrl = `#${currentUrl};${slot}`; + window.location.hash = newUrl; + } + renderTab(page: Element): TemplateResult { const slot = page.attributes.getNamedItem("slot")?.value; return html`
  • -