Prettier and ESLint had opinions.

This commit is contained in:
Ken Sternberg
2024-05-06 14:47:50 -07:00
parent 5c85c2c9e6
commit c8be337414
4 changed files with 17 additions and 46 deletions

View File

@ -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",

View File

@ -3,23 +3,24 @@ type CatchFn<T> = (error: unknown) => T;
type TryCatchArgs<T> = {
tryFn: TryFn<T>;
catchFn: CatchFn<T>;
catchFn?: CatchFn<T>;
};
export function tryCatch<T>({ tryFn, catchFn }: TryCatchArgs<T>): T;
export function tryCatch<T>(tryFn: TryFn<T>, catchFn: CatchFn<T>): T;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isTryCatchArgs = <T>(t: any): t is TryCatchArgs<T> =>
typeof t === "object" && "tryFn" in t && "catchFn" in t;
export function tryCatch<T>(tryFn: TryFn<T> | TryCatchProps<T>, catchFn?: CatchFn<T>): T {
export function tryCatch<T>({ tryFn, catchFn }: TryCatchArgs<T>): T;
export function tryCatch<T>(tryFn: TryFn<T>): T;
export function tryCatch<T>(tryFn: TryFn<T>, catchFn: CatchFn<T>): T;
export function tryCatch<T>(tryFn: TryFn<T> | TryCatchArgs<T>, catchFn?: CatchFn<T>): T {
if (isTryCatchArgs(tryFn)) {
catchFn = tryFn.catchFn;
tryFn = tryFn.tryFn;
}
if (catchFn === undefined) {
catchFn = () => null;
catchFn = () => null as T;
}
try {

View File

@ -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<string, [string, string]>([
[
"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<string>();
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<UserInterface>()?.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),
});

View File

@ -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() {