Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 47 additions & 15 deletions web/src/admin/AdminInterface/index.entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ import {
renderNotificationDrawerPanel,
} from "#elements/notifications/utils";

import { PageNavMenuToggle } from "#components/ak-page-navbar";

import type { AboutModal } from "#admin/AdminInterface/AboutModal";
import Styles from "#admin/AdminInterface/index.entrypoint.css";
import { ROUTES } from "#admin/Routes";

import { CapabilitiesEnum } from "@goauthentik/api";

import { msg } from "@lit/localize";
import { CSSResult, html, nothing, PropertyValues, TemplateResult } from "lit";
import { customElement, property, query, state } from "lit/decorators.js";
import { customElement, eventOptions, property, query, state } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";

import PFButton from "@patternfly/patternfly/components/Button/button.css";
Expand Down Expand Up @@ -73,19 +72,30 @@ export class AdminInterface extends WithCapabilitiesConfig(
@query("ak-about-modal")
public aboutModal?: AboutModal;

@property({ type: Boolean, reflect: true })
@property({ type: Boolean, reflect: true, attribute: "sidebar" })
public sidebarOpen = false;

#onPageNavMenuEvent = (event: PageNavMenuToggle) => {
this.sidebarOpen = event.open;
//#endregion

//#region Public Methods

public toggleSidebar = () => {
this.sidebarOpen = !this.sidebarOpen;
};

//#endregion

//#region Lifecycle

#sidebarMatcher: MediaQueryList;
#sidebarMediaQueryListener = (event: MediaQueryListEvent) => {
this.sidebarOpen = event.matches;
};

//#endregion
@eventOptions({ passive: true })
protected routeChangeListener() {
this.sidebarOpen = this.#sidebarMatcher.matches;
}

@state()
protected drawer: DrawerState = readDrawerParams();
Expand All @@ -96,21 +106,15 @@ export class AdminInterface extends WithCapabilitiesConfig(
persistDrawerParams(event.drawer);
};

//#region Lifecycle

constructor() {
configureSentry();

super();

WebsocketClient.connect();

this.#sidebarMatcher = window.matchMedia("(min-width: 1200px)");
this.#sidebarMatcher = window.matchMedia("(width >= 1200px)");
this.sidebarOpen = this.#sidebarMatcher.matches;

this.addEventListener(PageNavMenuToggle.eventName, this.#onPageNavMenuEvent, {
passive: true,
});
}

public connectedCallback() {
Expand Down Expand Up @@ -139,7 +143,11 @@ export class AdminInterface extends WithCapabilitiesConfig(
}
}

render(): TemplateResult {
//#endregion

//#region Rendering

protected override render(): TemplateResult {
if (!isAPIResultReady(this.session) || !canAccessAdmin(this.session.user)) {
return html`<slot></slot>`;
}
Expand All @@ -158,6 +166,19 @@ export class AdminInterface extends WithCapabilitiesConfig(

return html`<div class="pf-c-page">
<ak-page-navbar ?open=${this.sidebarOpen}>
<button
slot="toggle"
aria-controls="global-nav"
class="pf-c-button pf-m-plain"
@click=${this.toggleSidebar}
aria-label=${this.sidebarOpen
? msg("Collapse navigation")
: msg("Expand navigation")}
aria-expanded=${this.sidebarOpen ? "true" : "false"}
>
<i aria-hidden="true" class="fas fa-bars"></i>
</button>

<ak-version-banner></ak-version-banner>
<ak-enterprise-status interface="admin"></ak-enterprise-status>
</ak-page-navbar>
Expand All @@ -181,6 +202,7 @@ export class AdminInterface extends WithCapabilitiesConfig(
id="main-content"
defaultUrl="/administration/overview"
.routes=${ROUTES}
@ak-route-change=${this.routeChangeListener}
>
</ak-router-outlet>
</div>
Expand All @@ -189,9 +211,19 @@ export class AdminInterface extends WithCapabilitiesConfig(
<ak-about-modal></ak-about-modal>
</div>
</div>

<div
class="pf-c-page__sidebar-backdrop"
aria-label=${this.sidebarOpen ? msg("Close sidebar") : msg("Open sidebar")}
@click=${this.toggleSidebar}
role="button"
tabindex="0"
></div>
</div>
</div>`;
}

//#endregion
}

declare global {
Expand Down
190 changes: 190 additions & 0 deletions web/src/components/ak-page-navbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
:host {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bulk of this file is extracted verbatim from ak-page-navbar.ts, both for good housekeeping and to avoid Lit Analyzer's lack of container queries

--pf-c-page__header-tools--MarginRight: 0;
--ak-c-page-navbar__brand-logo--Height: var(--pf-global--FontSize--4xl, 2.25rem);
--ak-c-page-navbar__brand---BackgroundColor: var(--pf-c-page__sidebar--BackgroundColor);
--ak-c-page-navbar--Height: 7.5rem;
}

:host([theme="dark"]) {
--ak-c-page-navbar__brand---BackgroundColor: var(--pf-c-page__sidebar--BackgroundColor);
}

.main-content {
border-bottom-width: 0.5px;
border-bottom-style: solid;
border-bottom-color: var(--pf-global--BorderColor--100);
background-color: var(--pf-c-page__main-nav--BackgroundColor);
display: flex;
height: var(--ak-c-page-navbar--Height);

flex-direction: row;
box-shadow: var(--pf-global--BoxShadow--sm-bottom);

display: grid;
column-gap: var(--pf-global--spacer--md);

grid-template-columns: [brand] auto [toggle] auto [primary] 1fr [secondary] auto;
grid-template-rows: auto auto;
grid-template-areas:
"brand toggle primary secondary"
"brand toggle description secondary";

@media (width <= 425px) {
/* Fix for mobile flickering between elements with box shadows. */
border-bottom: none;
}
@media (width <= 767px) {
--ak-c-page-navbar--Height: auto;
}

@media (width <= 767px) {
row-gap: var(--pf-global--spacer--xs);

align-items: center;
grid-template-areas:
"toggle primary secondary"
"toggle description description";
justify-content: space-between;
width: 100%;
}

@media (width < 1200px) {
column-gap: calc(var(--pf-global--spacer--md) / 2);
}
}

.items {
display: block;

&.primary {
grid-column: primary;
grid-row: primary / description;

align-self: center;
padding-block: var(--pf-global--spacer--md);

@media (width <= 768px) {
padding-block: var(--pf-global--spacer--sm);
}

&.block-sibling {
}

@media (width >= 425px) {
&.block-sibling {
align-self: end;
padding-block-end: 0;
grid-row: primary;
}
}

.accent-icon {
height: 1.2em;
width: 1em;

@media (width <= 768px) {
display: none;
}
}
}

&.page-description {
padding-top: 0.3em;
grid-area: description;
margin-block-end: var(--pf-global--spacer--md);

display: box;
display: -webkit-box;
line-clamp: 2;
-webkit-line-clamp: 2;
box-orient: vertical;
-webkit-box-orient: vertical;
overflow: hidden;

@media (width <= 425px) {
display: none;
}

@media (width >= 769px) {
text-wrap: balance;
}
}

&.secondary {
grid-area: secondary;
flex: 0 0 auto;
justify-self: end;
padding-block: var(--pf-global--spacer--sm);
padding-inline-end: var(--pf-global--spacer--sm);

@media (width >= 769px) {
align-content: center;
padding-block: var(--pf-global--spacer--md);
padding-inline-end: var(--pf-global--spacer--xl);
}
}
}

.brand {
grid-area: brand;
background-color: var(--ak-c-page-navbar__brand---BackgroundColor);
height: 100%;
width: var(--pf-c-page__sidebar--Width);
align-items: center;
padding-inline: var(--pf-global--spacer--sm);

display: flex;
justify-content: center;

&.pf-m-collapsed {
display: none;
}

@media (width < 1200px) {
display: none;
}
}

.logo {
flex: 0 0 auto;
height: var(--ak-c-page-navbar__brand-logo--Height);

& img {
height: 100%;
}

& i {
font-size: var(--ak-c-page-navbar__brand-logo--Height);
height: var(--ak-c-page-navbar__brand-logo--Height);
line-height: var(--ak-c-page-navbar__brand-logo--Height);
}
}

::slotted([slot="toggle"]) {
--pf-c-button--FontSize: var(--pf-global--FontSize--2xl) !important;
height: 100%;

grid-area: toggle;
}

@media (width >= 1200px) {
slot[name="toggle"] {
display: none;
}
}

.pf-c-content .page-title {
display: box;
display: -webkit-box;
line-clamp: 2;
-webkit-line-clamp: 2;
box-orient: vertical;
-webkit-box-orient: vertical;
overflow: hidden;
}

h1 {
display: flex;
flex-direction: row;
align-items: center !important;
}
Loading
Loading