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 <jens@goauthentik.io>
Co-authored-by: Jens L <jens@goauthentik.io>
This commit is contained in:
gcp-cherry-pick-bot[bot]
2024-04-20 23:05:23 +02:00
committed by GitHub
parent b1ca579397
commit 7b7a3d34ec

View File

@ -13,7 +13,7 @@ import { WithBrandConfig } from "@goauthentik/elements/Interface/brandProvider";
import "@patternfly/elements/pf-tooltip/pf-tooltip.js"; import "@patternfly/elements/pf-tooltip/pf-tooltip.js";
import { msg } from "@lit/localize"; 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 { customElement, property } from "lit/decorators.js";
import PFButton from "@patternfly/patternfly/components/Button/button.css"; import PFButton from "@patternfly/patternfly/components/Button/button.css";
@ -107,22 +107,24 @@ export class PageHeader extends WithBrandConfig(AKElement) {
}); });
} }
setTitle(value: string) { setTitle(header?: string) {
const currentIf = currentInterface(); const currentIf = currentInterface();
const title = this.brand?.brandingTitle || TITLE_DEFAULT; let title = this.brand?.brandingTitle || TITLE_DEFAULT;
document.title = if (currentIf === "admin") {
currentIf === "admin" title = `${msg("Admin")} - ${title}`;
? `${msg("Admin")} - ${title}` }
: value !== "" // Prepend the header to the title
? `${value} - ${title}` if (header !== undefined && header !== "") {
: title; title = `${header} - ${title}`;
}
document.title = title;
} }
willUpdate(changedProperties: PropertyValues<this>) { willUpdate() {
if (changedProperties.has("header") && this.header) { // 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); this.setTitle(this.header);
} }
}
renderIcon(): TemplateResult { renderIcon(): TemplateResult {
if (this.icon) { if (this.icon) {