diff --git a/web/package.json b/web/package.json index 84898a33ef..fa1346a1b5 100644 --- a/web/package.json +++ b/web/package.json @@ -14,8 +14,8 @@ "build": "run-s build-locales esbuild:build", "build-proxy": "run-s build-locales esbuild:build-proxy", "watch": "run-s build-locales esbuild:watch", - "lint": "cross-env NODE_OPTIONS='--max_old_space_size=16384' eslint . --max-warnings 0 --fix", - "lint:precommit": "cross-env NODE_OPTIONS='--max_old_space_size=16384' node scripts/eslint-precommit.mjs", + "lint": "cross-env NODE_OPTIONS='--max_old_space_size=65536' eslint . --max-warnings 0 --fix", + "lint:precommit": "cross-env NODE_OPTIONS='--max_old_space_size=65536' node scripts/eslint-precommit.mjs", "lint:spelling": "node scripts/check-spelling.mjs", "lit-analyse": "lit-analyzer src", "precommit": "npm-run-all --parallel tsc lit-analyse lint:spelling --sequential lint:precommit prettier", diff --git a/web/src/elements/utils/tryCatch.ts b/web/src/elements/utils/tryCatch.ts index ae028d1fdf..c005754ebf 100644 --- a/web/src/elements/utils/tryCatch.ts +++ b/web/src/elements/utils/tryCatch.ts @@ -3,23 +3,24 @@ type CatchFn = (error: unknown) => T; type TryCatchArgs = { tryFn: TryFn; - catchFn: CatchFn; + catchFn?: CatchFn; }; -export function tryCatch({ tryFn, catchFn }: TryCatchArgs): T; -export function tryCatch(tryFn: TryFn, catchFn: CatchFn): T; - +// eslint-disable-next-line @typescript-eslint/no-explicit-any const isTryCatchArgs = (t: any): t is TryCatchArgs => typeof t === "object" && "tryFn" in t && "catchFn" in t; -export function tryCatch(tryFn: TryFn | TryCatchProps, catchFn?: CatchFn): T { +export function tryCatch({ tryFn, catchFn }: TryCatchArgs): T; +export function tryCatch(tryFn: TryFn): T; +export function tryCatch(tryFn: TryFn, catchFn: CatchFn): T; +export function tryCatch(tryFn: TryFn | TryCatchArgs, catchFn?: CatchFn): T { if (isTryCatchArgs(tryFn)) { catchFn = tryFn.catchFn; tryFn = tryFn.tryFn; } if (catchFn === undefined) { - catchFn = () => null; + catchFn = () => null as T; } try { diff --git a/web/src/user/LibraryPage/ApplicationList.ts b/web/src/user/LibraryPage/ApplicationList.ts index c7f75627fc..5601c639ed 100644 --- a/web/src/user/LibraryPage/ApplicationList.ts +++ b/web/src/user/LibraryPage/ApplicationList.ts @@ -1,6 +1,7 @@ import { PFSize } from "@goauthentik/common/enums.js"; import { LayoutType } from "@goauthentik/common/ui/config"; import { AKElement, rootInterface } from "@goauthentik/elements/Base"; +import { UserInterface } from "@goauthentik/user/UserInterface"; import { msg } from "@lit/localize"; import { css, html, nothing } from "lit"; @@ -9,33 +10,14 @@ import { classMap } from "lit/directives/class-map.js"; import { ifDefined } from "lit/directives/if-defined.js"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; -import PFContent from "@patternfly/patternfly/components/Content/content.css"; import PFEmptyState from "@patternfly/patternfly/components/EmptyState/empty-state.css"; import PFTable from "@patternfly/patternfly/components/Table/table.css"; -import PFGrid from "@patternfly/patternfly/layouts/Grid/grid.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import type { Application } from "@goauthentik/api"; import type { AppGroupEntry, AppGroupList } from "./types"; -type Pair = [string, string]; - -// prettier-ignore -const LAYOUTS = new Map([ - [ - "row", - ["pf-m-12-col", "pf-m-all-6-col-on-sm pf-m-all-4-col-on-md pf-m-all-5-col-on-lg pf-m-all-2-col-on-xl"]], - [ - "2-column", - ["pf-m-6-col", "pf-m-all-12-col-on-sm pf-m-all-12-col-on-md pf-m-all-4-col-on-lg pf-m-all-4-col-on-xl"], - ], - [ - "3-column", - ["pf-m-4-col", "pf-m-all-12-col-on-sm pf-m-all-12-col-on-md pf-m-all-6-col-on-lg pf-m-all-6-col-on-xl"], - ], -]); - @customElement("ak-library-application-list") export class LibraryPageApplicationList extends AKElement { static get styles() { @@ -66,19 +48,10 @@ export class LibraryPageApplicationList extends AKElement { expanded = new Set(); - get currentLayout(): Pair { - const layout = LAYOUTS.get(this.layout); - if (!layout) { - console.warn(`Unrecognized layout: ${this.layout || "-undefined-"}`); - return LAYOUTS.get("row") as Pair; - } - return layout; - } - render() { + const me = rootInterface()?.me; const canEdit = - rootInterface()?.uiConfig?.enabledFeatures.applicationEdit && - rootInterface()?.me?.user.isSuperuser; + rootInterface()?.uiConfig?.enabledFeatures.applicationEdit && me?.user.isSuperuser; const toggleExpansion = (pk: string) => { if (this.expanded.has(pk)) { @@ -89,8 +62,6 @@ export class LibraryPageApplicationList extends AKElement { this.requestUpdate(); }; - const [groupClass, groupGrid] = this.currentLayout; - const expandedClass = (pk: string) => ({ "pf-m-expanded": this.expanded.has(pk), }); diff --git a/web/src/user/LibraryPage/LibraryPageImpl.ts b/web/src/user/LibraryPage/LibraryPageImpl.ts index 5a568872b2..a1fdac7078 100644 --- a/web/src/user/LibraryPage/LibraryPageImpl.ts +++ b/web/src/user/LibraryPage/LibraryPageImpl.ts @@ -76,11 +76,8 @@ export class LibraryPage extends AKElement { this.viewPreference = this.viewPreference ?? tryCatch( - () => window.localStorage.getItem(VIEW_KEY), - (e) => { - console.log(e); - return "card"; - }, + () => window.localStorage.getItem(VIEW_KEY) ?? undefined, + (e) => "card", ); if (this.filteredApps === undefined) { throw new Error( @@ -128,7 +125,9 @@ export class LibraryPage extends AKElement { setView(view: string) { this.viewPreference = view; - tryCatch(() => window.localStorage.setItem(VIEW_KEY, view)); + tryCatch(() => { + window.localStorage.setItem(VIEW_KEY, view); + }); } renderEmptyState() {