Skip to content

Commit 83807f2

Browse files
kensternberg-authentikBeryJu
authored andcommitted
\#\# Details
- web: refactor LibraryPage, resolves #5171 \#\# Changes Some changes found in code review, including an embarassing failure to both remove the old internal accessor and propagate the new one for "isAdmin". A pattern is emerging that a LitComponent class should consist of: - styles - properties - states - queries - other object fields - constructor() - connectedCallBack() - disconnectedCallBack() - event listeners - callback helpers - render helpers - render() ... in that order.
1 parent b62e0ee commit 83807f2

5 files changed

Lines changed: 55 additions & 52 deletions

File tree

web/src/user/LibraryPage/ApplicationEmptyState.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,45 @@
1-
import { me } from "@goauthentik/common/users";
21
import { AKElement } from "@goauthentik/elements/Base";
32
import { paramURL } from "@goauthentik/elements/router/RouterOutlet";
43

54
import { t } from "@lingui/macro";
65

76
import { css, html } from "lit";
8-
import { customElement, state } from "lit/decorators.js";
7+
import { customElement, property } from "lit/decorators.js";
98

109
import PFContent from "@patternfly/patternfly/components/Content/content.css";
1110
import PFEmptyState from "@patternfly/patternfly/components/EmptyState/empty-state.css";
1211
import PFBase from "@patternfly/patternfly/patternfly-base.css";
1312
import PFSpacing from "@patternfly/patternfly/utilities/Spacing/spacing.css";
1413

15-
import { SessionUser } from "@goauthentik/api";
16-
1714
/**
1815
* Library Page Application List Empty
1916
*
2017
* Display a message if there are no applications defined in the current instance. If the user is an
2118
* administrator, provide a link to the "Create a new application" page.
2219
*/
2320

21+
const styles = [
22+
PFBase,
23+
PFEmptyState,
24+
PFContent,
25+
PFSpacing,
26+
css`
27+
.cta {
28+
display: inline-block;
29+
font-weight: bold;
30+
color: black;
31+
border: 3px solid var(--pf-c-empty-state__icon--Color);
32+
padding: var(--pf-global--spacer--sm);
33+
}
34+
`,
35+
];
36+
2437
@customElement("ak-library-application-empty-list")
2538
export class LibraryPageApplicationEmptyList extends AKElement {
26-
static styles = [
27-
PFBase,
28-
PFEmptyState,
29-
PFContent,
30-
PFSpacing,
31-
css`
32-
.cta {
33-
display: inline-block;
34-
font-weight: bold;
35-
color: black;
36-
border: 3px solid var(--pf-c-empty-state__icon--Color);
37-
padding: var(--pf-global--spacer--sm);
38-
}
39-
`,
40-
];
41-
42-
@state() isSuperUser = false;
39+
static styles = styles;
4340

44-
connectedCallback() {
45-
super.connectedCallback();
46-
me().then((me: SessionUser) => {
47-
this.isSuperUser = me.user.isSuperuser;
48-
});
49-
}
41+
@property({ attribute: "isadmin", type: Boolean })
42+
isAdmin = false;
5043

5144
renderNewAppButton() {
5245
const href = paramURL("/core/applications", {
@@ -74,7 +67,7 @@ export class LibraryPageApplicationEmptyList extends AKElement {
7467
<div class="pf-c-empty-state__body">
7568
${t`Either no applications are defined, or you don’t have access to any.`}
7669
</div>
77-
${this.isSuperUser ? this.renderNewAppButton() : html``}
70+
${this.isAdmin ? this.renderNewAppButton() : html``}
7871
</div>
7972
</div>`;
8073
}

web/src/user/LibraryPage/ApplicationList.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,34 @@ const LAYOUTS = new Map<string, [string, string]>([
3131
],
3232
]);
3333

34+
const styles = [
35+
PFBase,
36+
PFEmptyState,
37+
PFContent,
38+
PFGrid,
39+
css`
40+
.app-group-header {
41+
margin-bottom: 1em;
42+
margin-top: 1.2em;
43+
}
44+
`,
45+
];
46+
3447
@customElement("ak-library-application-list")
3548
export class LibraryPageApplicationList extends AKElement {
36-
static styles = [
37-
PFBase,
38-
PFEmptyState,
39-
PFContent,
40-
PFGrid,
41-
css`
42-
.app-group-header {
43-
margin-bottom: 1em;
44-
margin-top: 1.2em;
45-
}
46-
`,
47-
];
49+
static styles = styles;
4850

49-
@property({ attribute: true }) layout = "row" as LayoutType;
51+
@property({ attribute: true })
52+
layout = "row" as LayoutType;
5053

51-
@property({ attribute: true }) background: string | undefined = undefined;
54+
@property({ attribute: true })
55+
background: string | undefined = undefined;
5256

53-
@property({ attribute: true }) selected = "";
57+
@property({ attribute: true })
58+
selected = "";
5459

55-
@property() apps: AppGroupList = [];
60+
@property()
61+
apps: AppGroupList = [];
5662

5763
get currentLayout(): Pair {
5864
const layout = LAYOUTS.get(this.layout);

web/src/user/LibraryPage/ApplicationSearch.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ function fuseToApps(apps: Fuse.FuseResult<Application>[]): Application[] {
2222

2323
@customElement("ak-library-list-search")
2424
export class LibraryPageApplicationList extends AKElement {
25-
static style = [PFBase, PFDisplay];
25+
static styles = [PFBase, PFDisplay];
2626

27-
@property() apps: Application[] = [];
27+
@property()
28+
apps: Application[] = [];
2829

2930
@property()
3031
query = getURLParam<string | undefined>("search", undefined);
3132

32-
@query("input") searchInput?: HTMLInputElement;
33+
@query("input")
34+
searchInput?: HTMLInputElement;
3335

3436
fuse: Fuse<Application>;
3537

web/src/user/LibraryPage/LibraryPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class LibraryPage extends AKElement {
8484

8585
running() {
8686
return html`<ak-library-impl
87-
?isAdmin=${this.isAdmin}
87+
?isadmin=${this.isAdmin}
8888
.apps=${this.apps}
8989
.uiConfig=${this.uiConfig}
9090
></ak-library-impl>`;

web/src/user/LibraryPage/LibraryPageImpl.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ import type { AppGroupList, PageUIConfig } from "./types";
3535

3636
@customElement("ak-library-impl")
3737
export class LibraryPage extends AKElement {
38+
static styles = styles;
39+
3840
@property()
3941
apps!: PaginatedResponse<Application>;
4042

41-
@property()
43+
@property({ attribute: "isadmin", type: Boolean })
4244
isAdmin = false;
4345

4446
@property()
@@ -50,8 +52,6 @@ export class LibraryPage extends AKElement {
5052
@state()
5153
filteredApps: Application[] = [];
5254

53-
static styles = styles;
54-
5555
constructor() {
5656
super();
5757
this.searchUpdated = this.searchUpdated.bind(this);
@@ -105,7 +105,9 @@ export class LibraryPage extends AKElement {
105105
}
106106

107107
renderEmptyState() {
108-
return html`<ak-library-application-empty-list></ak-library-application-empty-list>`;
108+
return html`<ak-library-application-empty-list
109+
?isadmin=${this.isAdmin}
110+
></ak-library-application-empty-list>`;
109111
}
110112

111113
renderApps() {

0 commit comments

Comments
 (0)