From bce75dc04704364ccdd1448339fd48eac47dc1bc Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 1 Dec 2020 13:59:59 +0100 Subject: [PATCH] web: fix formatting mostly, add pipeline --- web/.eslintrc.js | 19 -------- web/.eslintrc.json | 25 +++++++++++ web/azure-pipelines.yml | 42 ++++++++++++++++++ web/package-lock.json | 6 +++ web/package.json | 3 +- web/src/api/admin_overview.ts | 18 +++++--- web/src/api/application.ts | 24 ++++++----- web/src/api/config.ts | 14 +++--- web/src/api/user.ts | 16 ++++--- web/src/elements/sidebar/Sidebar.ts | 43 ++++++++----------- web/src/elements/sidebar/SidebarBrand.ts | 4 +- web/src/pages/AdminOverviewPage.ts | 24 +++++------ .../pages/applications/ApplicationViewPage.ts | 11 +++-- 13 files changed, 159 insertions(+), 90 deletions(-) delete mode 100644 web/.eslintrc.js create mode 100644 web/.eslintrc.json create mode 100644 web/azure-pipelines.yml diff --git a/web/.eslintrc.js b/web/.eslintrc.js deleted file mode 100644 index feac03d31..000000000 --- a/web/.eslintrc.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = { - env: { - browser: true, - es2021: true, - }, - extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], - parser: "@typescript-eslint/parser", - parserOptions: { - ecmaVersion: 12, - sourceType: "module", - }, - plugins: ["@typescript-eslint"], - rules: { - indent: ["error", 4], - "linebreak-style": ["error", "unix"], - quotes: ["error", "double"], - semi: ["error", "always"], - }, -}; diff --git a/web/.eslintrc.json b/web/.eslintrc.json new file mode 100644 index 000000000..fa72b5bff --- /dev/null +++ b/web/.eslintrc.json @@ -0,0 +1,25 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "indent": ["error", 4], + "linebreak-style": ["error", "unix"], + "quotes": ["error", "double"], + "semi": ["error", "always"], + "@typescript-eslint/ban-ts-comment": "off" + } +} diff --git a/web/azure-pipelines.yml b/web/azure-pipelines.yml new file mode 100644 index 000000000..5a141da86 --- /dev/null +++ b/web/azure-pipelines.yml @@ -0,0 +1,42 @@ +trigger: +- main + +stages: + - stage: link + jobs: + - job: lint + pool: + vmImage: 'ubuntu-latest' + steps: + - task: NodeTool@0 + inputs: + versionSpec: '12.x' + displayName: 'Install Node.js' + - task: Npm@1 + inputs: + command: 'install' + workingDir: 'web/' + - task: Npm@1 + inputs: + command: 'custom' + workingDir: 'web/' + customCommand: 'run lint' + - stage: Build + jobs: + - job: build + pool: + vmImage: 'ubuntu-latest' + steps: + - task: NodeTool@0 + inputs: + versionSpec: '12.x' + displayName: 'Install Node.js' + - task: Npm@1 + inputs: + command: 'install' + workingDir: 'web/' + - task: Npm@1 + inputs: + command: 'custom' + workingDir: 'web/' + customCommand: 'run build' diff --git a/web/package-lock.json b/web/package-lock.json index c3a95b719..51ccce51c 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -816,6 +816,12 @@ } } }, + "eslint-config-google": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/eslint-config-google/-/eslint-config-google-0.14.0.tgz", + "integrity": "sha512-WsbX4WbjuMvTdeVL6+J3rK1RGhCTqjsFjX7UMSMgZiyxxaNLkoJENbrGExzERFeoTpGw3F3FypTiWAP9ZXzkEw==", + "dev": true + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", diff --git a/web/package.json b/web/package.json index e73067d31..0c12ee942 100644 --- a/web/package.json +++ b/web/package.json @@ -3,7 +3,7 @@ "scripts": { "build": "rollup -c ./rollup.config.js", "watch": "rollup -c -w", - "lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix" + "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { "@fortawesome/fontawesome-free": "^5.15.1", @@ -28,6 +28,7 @@ "@typescript-eslint/eslint-plugin": "^4.9.0", "@typescript-eslint/parser": "^4.9.0", "eslint": "^7.14.0", + "eslint-config-google": "^0.14.0", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-minify-html-literals": "^1.2.5", "rollup-plugin-node-resolve": "^5.2.0", diff --git a/web/src/api/admin_overview.ts b/web/src/api/admin_overview.ts index e6cf251b8..28185eb3d 100644 --- a/web/src/api/admin_overview.ts +++ b/web/src/api/admin_overview.ts @@ -1,13 +1,17 @@ import { DefaultClient } from "./client"; export class AdminOverview { - version?: string; - version_latest?: string; - worker_count?: number; - providers_without_application?: number; - policies_without_binding?: number; - cached_policies?: number; - cached_flows?: number; + version: string; + version_latest: string; + worker_count: number; + providers_without_application: number; + policies_without_binding: number; + cached_policies: number; + cached_flows: number; + + constructor() { + throw Error(); + } static get(): Promise { return DefaultClient.fetch(["admin", "overview"]); diff --git a/web/src/api/application.ts b/web/src/api/application.ts index 838debc03..9448e8001 100644 --- a/web/src/api/application.ts +++ b/web/src/api/application.ts @@ -1,17 +1,21 @@ import { DefaultClient, PBResponse } from "./client"; export class Application { - pk?: string; - name?: string; - slug?: string; - provider?: number; + pk: string; + name: string; + slug: string; + provider: number; - launch_url?: string; - meta_launch_url?: string; - meta_icon?: string; - meta_description?: string; - meta_publisher?: string; - policies?: string[]; + launch_url: string; + meta_launch_url: string; + meta_icon: string; + meta_description: string; + meta_publisher: string; + policies: string[]; + + constructor() { + throw Error(); + } static get(slug: string): Promise { return DefaultClient.fetch(["core", "applications", slug]); diff --git a/web/src/api/config.ts b/web/src/api/config.ts index 179999e60..411b3005b 100644 --- a/web/src/api/config.ts +++ b/web/src/api/config.ts @@ -4,12 +4,16 @@ import { Integrations } from "@sentry/tracing"; import { VERSION } from "../constants"; export class Config { - branding_logo?: string; - branding_title?: string; + branding_logo: string; + branding_title: string; - error_reporting_enabled?: boolean; - error_reporting_environment?: string; - error_reporting_send_pii?: boolean; + error_reporting_enabled: boolean; + error_reporting_environment: string; + error_reporting_send_pii: boolean; + + constructor() { + throw Error(); + } static get(): Promise { return DefaultClient.fetch(["root", "config"]).then((config) => { diff --git a/web/src/api/user.ts b/web/src/api/user.ts index 50621cfa0..6dc555df9 100644 --- a/web/src/api/user.ts +++ b/web/src/api/user.ts @@ -1,12 +1,16 @@ import { DefaultClient, PBResponse } from "./client"; export class User { - pk?: number; - username?: string; - name?: string; - is_superuser?: boolean; - email?: boolean; - avatar?: string; + pk: number; + username: string; + name: string; + is_superuser: boolean; + email: boolean; + avatar: string; + + constructor() { + throw Error(); + } static me(): Promise { return DefaultClient.fetch(["core", "users", "me"]); diff --git a/web/src/elements/sidebar/Sidebar.ts b/web/src/elements/sidebar/Sidebar.ts index 7240d7986..51233ebfb 100644 --- a/web/src/elements/sidebar/Sidebar.ts +++ b/web/src/elements/sidebar/Sidebar.ts @@ -24,7 +24,7 @@ export const SIDEBAR_ITEMS: SidebarItem[] = [ name: "Monitor", path: ["/audit/audit/"], condition: (sb: Sidebar) => { - return sb.user?.is_superuser!; + return sb.user?.is_superuser || false; }, }, { @@ -124,7 +124,7 @@ export const SIDEBAR_ITEMS: SidebarItem[] = [ }, ], condition: (sb: Sidebar) => { - return sb.user?.is_superuser!; + return sb.user?.is_superuser || false; }, }, ]; @@ -181,29 +181,22 @@ export class Sidebar extends LitElement { return html``; } } - return html`
  • - ${item.path - ? html` - ${item.name} - ` - : html`${item.name} - - - - -
    -
      - ${item.children?.map((i) => this.renderItem(i))} -
    -
    `} + return html`
  • + ${item.path ? + html` + ${item.name} + ` : + html` + ${item.name} + + + + +
    +
      + ${item.children?.map((i) => this.renderItem(i))} +
    +
    `}
  • `; } diff --git a/web/src/elements/sidebar/SidebarBrand.ts b/web/src/elements/sidebar/SidebarBrand.ts index 74adf6d79..8323194c5 100644 --- a/web/src/elements/sidebar/SidebarBrand.ts +++ b/web/src/elements/sidebar/SidebarBrand.ts @@ -53,8 +53,8 @@ export class SidebarBrand extends LitElement {
    passbook icon ${this.config.branding_title - ? html`${this.config.branding_title}` - : ""} + ? html`${this.config.branding_title}` + : ""}
    `; } diff --git a/web/src/pages/AdminOverviewPage.ts b/web/src/pages/AdminOverviewPage.ts index 2d33e45f0..5e5b9cf64 100644 --- a/web/src/pages/AdminOverviewPage.ts +++ b/web/src/pages/AdminOverviewPage.ts @@ -82,39 +82,39 @@ export class AdminOverviewPage extends LitElement { ${this.data ? - this.data?.worker_count! < 1 ? - html`

    + this.data?.worker_count < 1 ? + html`

    ${this.data.worker_count}

    ${gettext("No workers connected.")}

    ` : - html`

    + html`

    ${this.data.worker_count}

    ` - : html``} + : html``}
    ${this.data ? - this.data?.providers_without_application! < 1 ? - html`

    + this.data?.providers_without_application < 1 ? + html`

    0

    ${gettext("At least one Provider has no application assigned.")}

    ` : - html`

    + html`

    0

    ` - : html``} + : html``}
    ${this.data ? - this.data?.policies_without_binding! < 1 ? - html`

    + this.data?.policies_without_binding < 1 ? + html`

    0

    ${gettext("Policies without binding exist.")}

    ` : - html`

    + html`

    0

    ` - : html``} + : html``}
    - Logins over the last 24 hours + ${gettext("Logins over the last 24 hours")}
    ${this.application ? - html`` : ""} + html` + + ` + : ""}