From 7b7a3d34ec6d52dc3f40f508dc0aeaf3f5c307d3 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Sat, 20 Apr 2024 23:05:23 +0200 Subject: [PATCH] web/admin: fix document title for admin interface (cherry-pick #9362) (#9365) web/admin: fix document title for admin interface (#9362) Signed-off-by: Jens Langhammer Co-authored-by: Jens L --- web/src/elements/PageHeader.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/web/src/elements/PageHeader.ts b/web/src/elements/PageHeader.ts index ed054af2c6..34ddd511b7 100644 --- a/web/src/elements/PageHeader.ts +++ b/web/src/elements/PageHeader.ts @@ -13,7 +13,7 @@ import { WithBrandConfig } from "@goauthentik/elements/Interface/brandProvider"; import "@patternfly/elements/pf-tooltip/pf-tooltip.js"; import { msg } from "@lit/localize"; -import { CSSResult, PropertyValues, TemplateResult, css, html } from "lit"; +import { CSSResult, TemplateResult, css, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; @@ -107,21 +107,23 @@ export class PageHeader extends WithBrandConfig(AKElement) { }); } - setTitle(value: string) { + setTitle(header?: string) { const currentIf = currentInterface(); - const title = this.brand?.brandingTitle || TITLE_DEFAULT; - document.title = - currentIf === "admin" - ? `${msg("Admin")} - ${title}` - : value !== "" - ? `${value} - ${title}` - : title; + let title = this.brand?.brandingTitle || TITLE_DEFAULT; + if (currentIf === "admin") { + title = `${msg("Admin")} - ${title}`; + } + // Prepend the header to the title + if (header !== undefined && header !== "") { + title = `${header} - ${title}`; + } + document.title = title; } - willUpdate(changedProperties: PropertyValues) { - if (changedProperties.has("header") && this.header) { - this.setTitle(this.header); - } + willUpdate() { + // Always update title, even if there's no header value set, + // as in that case we still need to return to the generic title + this.setTitle(this.header); } renderIcon(): TemplateResult {