-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathApplicationList.ts
More file actions
119 lines (105 loc) · 4.05 KB
/
Copy pathApplicationList.ts
File metadata and controls
119 lines (105 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { LibraryAppRow } from "./LibraryAppRow.js";
import { type AppGroupEntry, ViewMode } from "./types.js";
import { LayoutType } from "#common/ui/config";
import { ApplicationRoute } from "#elements/router/builders";
import { LitFC } from "#elements/types";
import { ifPresent } from "#elements/utils/attributes";
import { AnchorPositionSupported } from "#user/LibraryApplication/CardMenu";
import { AKLibraryApp } from "#user/LibraryApplication/index";
import { Application } from "@goauthentik/api";
import { spread } from "@open-wc/lit-helpers";
import { kebabCase } from "change-case";
import { HTMLAttributes } from "react";
import { msg } from "@lit/localize";
import { html } from "lit";
import { RefOrCallback } from "lit/directives/ref.js";
import { repeat } from "lit/directives/repeat.js";
const LayoutColumnCount = {
[LayoutType.row]: 1,
[LayoutType.column_2]: 2,
[LayoutType.column_3]: 3,
} as const satisfies Record<LayoutType, number>;
export interface AKLibraryApplicationListProps extends HTMLAttributes<HTMLDivElement> {
editable?: boolean;
groupedApps: AppGroupEntry[];
layout: LayoutType;
viewMode?: ViewMode;
background?: string | null;
selectedApp?: Application | null;
targetRef?: RefOrCallback | null;
}
/**
* Renders the current library list of a User's Applications.
*/
export const AKLibraryApplicationList: LitFC<AKLibraryApplicationListProps> = ({
editable,
groupedApps,
layout = LayoutType.row,
viewMode = ViewMode.Grid,
background,
selectedApp,
targetRef,
...props
}) => {
const columnCount = LayoutColumnCount[layout] ?? 1;
const isList = viewMode === ViewMode.List;
return html`<div
role="presentation"
part="app-list"
data-view-mode=${viewMode}
data-anchor-strategy=${AnchorPositionSupported ? "anchor-position" : "fallback"}
style="--app-list-column-count: ${columnCount}"
${spread(props)}
>
${repeat(
groupedApps,
([groupLabel]) => groupLabel,
([groupLabel, apps], groupIndex) => {
const groupID = kebabCase(groupLabel);
const inner = repeat(
apps,
(application) => application.pk,
(application) => {
const selected = selectedApp === application;
const editURL = editable
? ApplicationRoute.EditURL(application.slug)
: null;
if (isList) {
return LibraryAppRow({
application,
editURL,
targetRef: selected ? targetRef : null,
});
}
return AKLibraryApp({
application,
background,
editURL,
targetRef: selected ? targetRef : null,
});
},
);
return html`<fieldset
class="ak-c-fieldset"
data-group-id=${ifPresent(groupID)}
part="app-group"
data-group-index=${groupIndex}
data-app-count=${apps.length}
>
<legend
class="pf-c-content ${!groupLabel ? "sr-only more-contrast-only" : ""}"
part="app-group-header"
>
<h2 id=${`app-group-${groupID}`}>${groupLabel || msg("Ungrouped")}</h2>
</legend>
${isList
? html`<ul part="app-group-rows" class="app-group-rows" role="list">
${inner}
</ul>`
: inner}
<hr part="app-group-separator" aria-hidden="true" />
</fieldset>`;
},
)}
</div>`;
};