@@ -2,8 +2,6 @@ import "#admin/AdminInterface/AboutModal";
22import "#elements/banner/EnterpriseStatusBanner" ;
33import "#elements/banner/VersionBanner" ;
44import "#elements/messages/MessageContainer" ;
5- import "#elements/notifications/APIDrawer" ;
6- import "#elements/notifications/NotificationDrawer" ;
75import "#elements/router/RouterOutlet" ;
86import "#elements/sidebar/Sidebar" ;
97import "#elements/sidebar/SidebarItem" ;
@@ -15,15 +13,22 @@ import {
1513} from "./AdminSidebar.js" ;
1614
1715import { isAPIResultReady } from "#common/api/responses" ;
18- import { EVENT_API_DRAWER_TOGGLE , EVENT_NOTIFICATION_DRAWER_TOGGLE } from "#common/constants" ;
1916import { configureSentry } from "#common/sentry/index" ;
2017import { isGuest } from "#common/users" ;
21- import { WebsocketClient } from "#common/ws" ;
18+ import { WebsocketClient } from "#common/ws/WebSocketClient " ;
2219
2320import { AuthenticatedInterface } from "#elements/AuthenticatedInterface" ;
21+ import { listen } from "#elements/decorators/listen" ;
2422import { WithCapabilitiesConfig } from "#elements/mixins/capabilities" ;
23+ import { WithNotifications } from "#elements/mixins/notifications" ;
2524import { canAccessAdmin , WithSession } from "#elements/mixins/session" ;
26- import { getURLParam , updateURLParams } from "#elements/router/RouteMatch" ;
25+ import { AKDrawerChangeEvent } from "#elements/notifications/events" ;
26+ import {
27+ DrawerState ,
28+ persistDrawerParams ,
29+ readDrawerParams ,
30+ renderNotificationDrawerPanel ,
31+ } from "#elements/notifications/utils" ;
2732
2833import { PageNavMenuToggle } from "#components/ak-page-navbar" ;
2934
@@ -34,28 +39,36 @@ import { ROUTES } from "#admin/Routes";
3439import { CapabilitiesEnum } from "@goauthentik/api" ;
3540
3641import { CSSResult , html , nothing , PropertyValues , TemplateResult } from "lit" ;
37- import { customElement , property , query } from "lit/decorators.js" ;
42+ import { customElement , property , query , state } from "lit/decorators.js" ;
3843import { classMap } from "lit/directives/class-map.js" ;
3944
4045import PFButton from "@patternfly/patternfly/components/Button/button.css" ;
4146import PFDrawer from "@patternfly/patternfly/components/Drawer/drawer.css" ;
4247import PFNav from "@patternfly/patternfly/components/Nav/nav.css" ;
4348import PFPage from "@patternfly/patternfly/components/Page/page.css" ;
44- import PFBase from "@patternfly/patternfly/patternfly-base.css" ;
4549
4650if ( process . env . NODE_ENV === "development" ) {
4751 await import ( "@goauthentik/esbuild-plugin-live-reload/client" ) ;
4852}
4953
5054@customElement ( "ak-interface-admin" )
51- export class AdminInterface extends WithCapabilitiesConfig ( WithSession ( AuthenticatedInterface ) ) {
52- //#region Properties
55+ export class AdminInterface extends WithCapabilitiesConfig (
56+ WithNotifications ( WithSession ( AuthenticatedInterface ) ) ,
57+ ) {
58+ //#region Styles
59+
60+ public static readonly styles : CSSResult [ ] = [
61+ // ---
62+ PFPage ,
63+ PFButton ,
64+ PFDrawer ,
65+ PFNav ,
66+ Styles ,
67+ ] ;
5368
54- @property ( { type : Boolean } )
55- public notificationDrawerOpen = getURLParam ( "notificationDrawerOpen" , false ) ;
69+ //#endregion
5670
57- @property ( { type : Boolean } )
58- public apiDrawerOpen = getURLParam ( "apiDrawerOpen" , false ) ;
71+ //#region Properties
5972
6073 @query ( "ak-about-modal" )
6174 public aboutModal ?: AboutModal ;
@@ -74,19 +87,14 @@ export class AdminInterface extends WithCapabilitiesConfig(WithSession(Authentic
7487
7588 //#endregion
7689
77- //#region Styles
90+ @state ( )
91+ protected drawer : DrawerState = readDrawerParams ( ) ;
7892
79- static styles : CSSResult [ ] = [
80- // ---
81- PFBase ,
82- PFPage ,
83- PFButton ,
84- PFDrawer ,
85- PFNav ,
86- Styles ,
87- ] ;
88-
89- //#endregion
93+ @listen ( AKDrawerChangeEvent )
94+ protected drawerListener = ( event : AKDrawerChangeEvent ) => {
95+ this . drawer = event . drawer ;
96+ persistDrawerParams ( event . drawer ) ;
97+ } ;
9098
9199 //#region Lifecycle
92100
@@ -99,6 +107,7 @@ export class AdminInterface extends WithCapabilitiesConfig(WithSession(Authentic
99107
100108 this . #sidebarMatcher = window . matchMedia ( "(min-width: 1200px)" ) ;
101109 this . sidebarOpen = this . #sidebarMatcher. matches ;
110+
102111 this . addEventListener ( PageNavMenuToggle . eventName , this . #onPageNavMenuEvent, {
103112 passive : true ,
104113 } ) ;
@@ -107,27 +116,14 @@ export class AdminInterface extends WithCapabilitiesConfig(WithSession(Authentic
107116 public connectedCallback ( ) {
108117 super . connectedCallback ( ) ;
109118
110- window . addEventListener ( EVENT_NOTIFICATION_DRAWER_TOGGLE , ( ) => {
111- this . notificationDrawerOpen = ! this . notificationDrawerOpen ;
112- updateURLParams ( {
113- notificationDrawerOpen : this . notificationDrawerOpen ,
114- } ) ;
115- } ) ;
116-
117- window . addEventListener ( EVENT_API_DRAWER_TOGGLE , ( ) => {
118- this . apiDrawerOpen = ! this . apiDrawerOpen ;
119- updateURLParams ( {
120- apiDrawerOpen : this . apiDrawerOpen ,
121- } ) ;
122- } ) ;
123-
124119 this . #sidebarMatcher. addEventListener ( "change" , this . #sidebarMediaQueryListener, {
125120 passive : true ,
126121 } ) ;
127122 }
128123
129124 public disconnectedCallback ( ) : void {
130125 super . disconnectedCallback ( ) ;
126+
131127 this . #sidebarMatcher. removeEventListener ( "change" , this . #sidebarMediaQueryListener) ;
132128
133129 WebsocketClient . close ( ) ;
@@ -154,11 +150,10 @@ export class AdminInterface extends WithCapabilitiesConfig(WithSession(Authentic
154150 "pf-m-collapsed" : ! this . sidebarOpen ,
155151 } ;
156152
157- const drawerOpen = this . notificationDrawerOpen || this . apiDrawerOpen ;
158-
153+ const openDrawerCount = ( this . drawer . notifications ? 1 : 0 ) + ( this . drawer . api ? 1 : 0 ) ;
159154 const drawerClasses = {
160- "pf-m-expanded" : drawerOpen ,
161- "pf-m-collapsed" : ! drawerOpen ,
155+ "pf-m-expanded" : openDrawerCount !== 0 ,
156+ "pf-m-collapsed" : openDrawerCount === 0 ,
162157 } ;
163158
164159 return html `< div class ="pf-c-page ">
@@ -190,18 +185,7 @@ export class AdminInterface extends WithCapabilitiesConfig(WithSession(Authentic
190185 </ ak-router-outlet >
191186 </ div >
192187 </ div >
193- < ak-notification-drawer
194- class ="pf-c-drawer__panel pf-m-width-33 ${ this . notificationDrawerOpen
195- ? ""
196- : "display-none" } "
197- ?hidden =${ ! this . notificationDrawerOpen }
198- > </ ak-notification-drawer >
199- < ak-api-drawer
200- class ="pf-c-drawer__panel pf-m-width-33 ${ this . apiDrawerOpen
201- ? ""
202- : "display-none" } "
203- ?hidden =${ ! this . apiDrawerOpen }
204- > </ ak-api-drawer >
188+ ${ renderNotificationDrawerPanel ( this . drawer ) }
205189 < ak-about-modal > </ ak-about-modal >
206190 </ div >
207191 </ div >
0 commit comments