Removed the consoe.log
This commit is contained in:
parent
5386f0f4c3
commit
83e934f80c
|
@ -6,9 +6,9 @@ export function RenderFlowOption(flow: Flow): string {
|
||||||
return `${flow.slug} (${flow.name})`;
|
return `${flow.slug} (${flow.name})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pair = [FlowDesignationEnum, string];
|
type FlowDesignationPair = [FlowDesignationEnum, string];
|
||||||
|
|
||||||
export const flowDesignationTable: Pair[] = [
|
export const flowDesignationTable: FlowDesignationPair[] = [
|
||||||
[FlowDesignationEnum.Authentication, msg("Authentication")],
|
[FlowDesignationEnum.Authentication, msg("Authentication")],
|
||||||
[FlowDesignationEnum.Authorization, msg("Authorization")],
|
[FlowDesignationEnum.Authorization, msg("Authorization")],
|
||||||
[FlowDesignationEnum.Enrollment, msg("Enrollment")],
|
[FlowDesignationEnum.Enrollment, msg("Enrollment")],
|
||||||
|
@ -25,7 +25,7 @@ export function DesignationToLabel(designation: FlowDesignationEnum): string {
|
||||||
return flowDesignations.get(designation) ?? msg("Unknown designation");
|
return flowDesignations.get(designation) ?? msg("Unknown designation");
|
||||||
}
|
}
|
||||||
|
|
||||||
const layoutToLabel = new Map([
|
const layoutToLabel = new Map<LayoutEnum, string>([
|
||||||
[LayoutEnum.Stacked, msg("Stacked")],
|
[LayoutEnum.Stacked, msg("Stacked")],
|
||||||
[LayoutEnum.ContentLeft, msg("Content left")],
|
[LayoutEnum.ContentLeft, msg("Content left")],
|
||||||
[LayoutEnum.ContentRight, msg("Content right")],
|
[LayoutEnum.ContentRight, msg("Content right")],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { AKElement } from "@goauthentik/elements/Base";
|
import { AKElement } from "@goauthentik/elements/Base";
|
||||||
import "@goauthentik/elements/sidebar/SidebarBrand";
|
import "@goauthentik/elements/sidebar/SidebarBrand";
|
||||||
import "@goauthentik/elements/sidebar/SidebarUser";
|
|
||||||
import "@goauthentik/elements/sidebar/SidebarItems";
|
import "@goauthentik/elements/sidebar/SidebarItems";
|
||||||
|
import "@goauthentik/elements/sidebar/SidebarUser";
|
||||||
|
|
||||||
import { CSSResult, 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";
|
||||||
|
@ -73,8 +73,10 @@ export class Sidebar extends AKElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): TemplateResult {
|
render(): TemplateResult {
|
||||||
console.log(this.entries);
|
return html`<nav
|
||||||
return html`<nav class="pf-c-nav ${this.activeTheme === UiThemeEnum.Light ? "pf-m-light" : ""}" aria-label="Global">
|
class="pf-c-nav ${this.activeTheme === UiThemeEnum.Light ? "pf-m-light" : ""}"
|
||||||
|
aria-label="Global"
|
||||||
|
>
|
||||||
<ak-sidebar-brand></ak-sidebar-brand>
|
<ak-sidebar-brand></ak-sidebar-brand>
|
||||||
<ak-sidebar-items .entries=${this.entries}></ak-sidebar-items>
|
<ak-sidebar-items .entries=${this.entries}></ak-sidebar-items>
|
||||||
<ak-sidebar-user></ak-sidebar-user>
|
<ak-sidebar-user></ak-sidebar-user>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { ROUTE_SEPARATOR } from "@goauthentik/common/constants";
|
|
||||||
import { AKElement } from "@goauthentik/elements/Base";
|
import { AKElement } from "@goauthentik/elements/Base";
|
||||||
|
|
||||||
import { CSSResult, TemplateResult, css, html, nothing } from "lit";
|
import { CSSResult, TemplateResult, css, html, nothing } from "lit";
|
||||||
|
@ -25,6 +24,9 @@ export type SidebarAttributes = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarEntry = {
|
export type SidebarEntry = {
|
||||||
|
// - nullish: This entry is not a link.
|
||||||
|
// - string: the url for the entry
|
||||||
|
// - SidebarEventHandler: a function to run if the entry is clicked.
|
||||||
path: string | SidebarEventHandler | null;
|
path: string | SidebarEventHandler | null;
|
||||||
label: string;
|
label: string;
|
||||||
attributes?: SidebarAttributes | null; // eslint-disable-line
|
attributes?: SidebarAttributes | null; // eslint-disable-line
|
||||||
|
@ -34,6 +36,8 @@ export type SidebarEntry = {
|
||||||
// Typescript requires the type here to correctly type the recursive path
|
// Typescript requires the type here to correctly type the recursive path
|
||||||
export type SidebarRenderer = (_: SidebarEntry) => TemplateResult;
|
export type SidebarRenderer = (_: SidebarEntry) => TemplateResult;
|
||||||
|
|
||||||
|
const entryKey = (entry: SidebarEntry) => `${entry.path || "no-path"}:${entry.label}`;
|
||||||
|
|
||||||
@customElement("ak-sidebar-items")
|
@customElement("ak-sidebar-items")
|
||||||
export class SidebarItems extends AKElement {
|
export class SidebarItems extends AKElement {
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
|
@ -94,7 +98,7 @@ export class SidebarItems extends AKElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
.pf-c-nav__link a {
|
.pf-c-nav__link a {
|
||||||
flex: 1 0 max-content;
|
flex: 1 0 max-content;
|
||||||
color: var(--pf-c-nav__link--Color);
|
color: var(--pf-c-nav__link--Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +127,14 @@ flex: 1 0 max-content;
|
||||||
@state()
|
@state()
|
||||||
expanded: WeakSet<SidebarEntry> = new WeakSet();
|
expanded: WeakSet<SidebarEntry> = new WeakSet();
|
||||||
|
|
||||||
|
current?: SidebarEntry;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
// this.onToggle = this.onToggle.bind(this);
|
// this.onToggle = this.onToggle.bind(this);
|
||||||
|
|
||||||
this.onHashChange = this.onHashChange.bind(this);
|
this.onHashChange = this.onHashChange.bind(this);
|
||||||
this.isActive = this.isActive.bind(this);
|
this.recordActive = this.recordActive.bind(this);
|
||||||
this.renderItem = this.renderItem.bind(this);
|
this.renderItem = this.renderItem.bind(this);
|
||||||
this.toggleExpand = this.toggleExpand.bind(this);
|
this.toggleExpand = this.toggleExpand.bind(this);
|
||||||
}
|
}
|
||||||
|
@ -151,8 +157,8 @@ flex: 1 0 max-content;
|
||||||
/* no op */
|
/* no op */
|
||||||
}
|
}
|
||||||
|
|
||||||
isActive(path: string) {
|
recordActive(entry: SidebarEntry) {
|
||||||
return true;
|
this.current = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): TemplateResult {
|
render(): TemplateResult {
|
||||||
|
@ -180,7 +186,6 @@ flex: 1 0 max-content;
|
||||||
// not when being forwarded to the correct renderer.
|
// not when being forwarded to the correct renderer.
|
||||||
const attr = attributes ?? undefined;
|
const attr = attributes ?? undefined;
|
||||||
const hasChildren = !!(children && children.length > 0);
|
const hasChildren = !!(children && children.length > 0);
|
||||||
console.log(entry.label, hasChildren);
|
|
||||||
|
|
||||||
// This is grossly imperative, in that it HAS to come before the content is rendered
|
// This is grossly imperative, in that it HAS to come before the content is rendered
|
||||||
// to make sure the content gets the right settings with respect to expansion.
|
// to make sure the content gets the right settings with respect to expansion.
|
||||||
|
@ -195,8 +200,8 @@ flex: 1 0 max-content;
|
||||||
: hasChildren
|
: hasChildren
|
||||||
? this.renderLabelAndChildren(entry)
|
? this.renderLabelAndChildren(entry)
|
||||||
: path
|
: path
|
||||||
? this.renderLink(label, path, attr)
|
? this.renderLink(entry)
|
||||||
: this.renderLabel(label, attr);
|
: this.renderLabel(entry);
|
||||||
|
|
||||||
const expanded = {
|
const expanded = {
|
||||||
"highlighted": !!attr?.highlight,
|
"highlighted": !!attr?.highlight,
|
||||||
|
@ -207,9 +212,10 @@ flex: 1 0 max-content;
|
||||||
return html`<li class="pf-c-nav__item ${classMap(expanded)}">${content}</li>`;
|
return html`<li class="pf-c-nav__item ${classMap(expanded)}">${content}</li>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
toLinkClasses(attr: SidebarAttributes) {
|
toLinkClasses(entry: SidebarEntry) {
|
||||||
|
const attr = entry.attributes || {};
|
||||||
return {
|
return {
|
||||||
"pf-m-current": !!attr.isActive,
|
"pf-m-current": this.current === entry,
|
||||||
"pf-c-nav__link": true,
|
"pf-c-nav__link": true,
|
||||||
"highlight": !!(typeof attr.highlight === "function"
|
"highlight": !!(typeof attr.highlight === "function"
|
||||||
? attr.highlight()
|
? attr.highlight()
|
||||||
|
@ -217,22 +223,29 @@ flex: 1 0 max-content;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
renderLabel(label: string, attr: SidebarAttributes = {}) {
|
renderLabel(entry: SidebarEntry) {
|
||||||
return html`<div class=${classMap(this.toLinkClasses(attr))}>${label}</div>`;
|
return html`<div class=${classMap(this.toLinkClasses(entry))}>${entry.label}</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// note the responsibilities pushed up to the caller
|
// note the responsibilities pushed up to the caller
|
||||||
renderLink(label: string, path: string | SidebarEventHandler, attr: SidebarAttributes = {}) {
|
renderLink(entry: SidebarEntry) {
|
||||||
if (typeof path === "function") {
|
const record = () => this.recordActive(entry);
|
||||||
return html` <a @click=${path} class=${classMap(this.toLinkClasses(attr))}>
|
if (typeof entry.path === "function") {
|
||||||
${label}
|
const handler = entry.path;
|
||||||
|
const recordAndHandle = () => {
|
||||||
|
record();
|
||||||
|
handler();
|
||||||
|
};
|
||||||
|
return html` <a @click=${recordAndHandle} class=${classMap(this.toLinkClasses(entry))}>
|
||||||
|
${entry.label}
|
||||||
</a>`;
|
</a>`;
|
||||||
}
|
}
|
||||||
return html` <a
|
return html` <a
|
||||||
href="${attr.isAbsoluteLink ? "" : "#"}${path}"
|
@click=${record}
|
||||||
class=${classMap(this.toLinkClasses(attr))}
|
href="${entry.attributes?.isAbsoluteLink ? "" : "#"}${entry.path}"
|
||||||
|
class=${classMap(this.toLinkClasses(entry))}
|
||||||
>
|
>
|
||||||
${label}
|
${entry.label}
|
||||||
</a>`;
|
</a>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,9 +272,12 @@ flex: 1 0 max-content;
|
||||||
|
|
||||||
renderLinkAndChildren(entry: SidebarEntry): TemplateResult {
|
renderLinkAndChildren(entry: SidebarEntry): TemplateResult {
|
||||||
const handler = () => this.toggleExpand(entry);
|
const handler = () => this.toggleExpand(entry);
|
||||||
return html` <div class="pf-c-nav__link">
|
const record = () => this.recordActive(entry);
|
||||||
|
const active = { "pf-m-current": entry === this.current };
|
||||||
|
return html` <div class="pf-c-nav__link ${classMap(active)}">
|
||||||
<a
|
<a
|
||||||
href="${entry.attributes?.isAbsoluteLink ? "" : "#"}${entry.path}"
|
href="${entry.attributes?.isAbsoluteLink ? "" : "#"}${entry.path}"
|
||||||
|
@click=${record}
|
||||||
class="ak-nav__link"
|
class="ak-nav__link"
|
||||||
>
|
>
|
||||||
${entry.label}
|
${entry.label}
|
||||||
|
|
Reference in a new issue