From b2e1ab3057b25a326c53e8702c090560370b1643 Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Tue, 11 Jan 2022 14:56:39 +0000 Subject: [PATCH] lint code --- src/api/API.ts | 10 +++--- src/pages.tsx | 8 +++-- src/ui/elements/CodeEditor.tsx | 6 +++- .../pages/Secrets/KeyValue/KeyValueDelete.tsx | 8 ++--- .../Secrets/KeyValue/KeyValueVersions.tsx | 14 +++----- .../pages/Secrets/KeyValue/KeyValueView.tsx | 25 ++++++++------ src/ui/pages/Secrets/SecretTitleElement.tsx | 33 +++++++++++-------- src/ui/pages/SetLanguage.tsx | 1 - src/ui/pages/pageLinks.tsx | 14 ++++++-- 9 files changed, 72 insertions(+), 47 deletions(-) diff --git a/src/api/API.ts b/src/api/API.ts index 331cff7..8067199 100644 --- a/src/api/API.ts +++ b/src/api/API.ts @@ -356,11 +356,11 @@ export class API { baseMount: string, secretPath: string[], name: string, - version: string = "null", + version = "null", ): Promise { let secretURL = ""; - let request; + let request: Request; const mountInfo = await this.getMount(baseMount); const mountVersion = mountInfo.options.version; @@ -396,7 +396,7 @@ export class API { baseMount: string, secretPath: string[], name: string, - version: string = "null", + version = "null", ): Promise { let secretURL = `/v1/${baseMount}/undelete/${secretPath.join("/")}/${name}`; secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); @@ -442,7 +442,7 @@ export class API { baseMount: string, secretPath: string[], name: string, - version: string = "null", + version = "null", ): Promise> { let secretURL = ""; @@ -464,7 +464,7 @@ export class API { baseMount: string, secretPath: string[], name: string, - version: string = "null", + version = "null", ): Promise> { const mountInfo = await this.getMount(baseMount); if (mountInfo.options.version == "2") { diff --git a/src/pages.tsx b/src/pages.tsx index e4377ad..fa6388c 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -11,6 +11,7 @@ import { KeyValueDelete } from "./ui/pages/Secrets/KeyValue/KeyValueDelete"; import { KeyValueEdit } from "./ui/pages/Secrets/KeyValue/KeyValueEdit"; import { KeyValueList } from "./ui/pages/Secrets/KeyValue/KeyValueList"; import { KeyValueNew } from "./ui/pages/Secrets/KeyValue/KeyValueNew"; +import { KeyValueVersions } from "./ui/pages/Secrets/KeyValue/KeyValueVersions"; import { KeyValueView } from "./ui/pages/Secrets/KeyValue/KeyValueView"; import { Login } from "./ui/pages/Login"; import { Me } from "./ui/pages/Me"; @@ -43,7 +44,6 @@ import { UserPassUserEdit } from "./ui/pages/Access/Auth/userpass/UserPassUserEd import { UserPassUserNew } from "./ui/pages/Access/Auth/userpass/UserPassUserNew"; import { UserPassUserView } from "./ui/pages/Access/Auth/userpass/UserPassUserView"; import { UserPassUsersList } from "./ui/pages/Access/Auth/userpass/UserPassUsersList"; -import { KeyValueVersions } from "./ui/pages/Secrets/KeyValue/KeyValueVersions"; export const Main = () => ( @@ -89,7 +89,11 @@ export const Main = () => ( - + diff --git a/src/ui/elements/CodeEditor.tsx b/src/ui/elements/CodeEditor.tsx index 367eaf4..cd430ca 100644 --- a/src/ui/elements/CodeEditor.tsx +++ b/src/ui/elements/CodeEditor.tsx @@ -50,7 +50,11 @@ export class CodeEditor extends Component { render(): JSX.Element { return ( -
+
); } } diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx index c5c5c2c..6480637 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx @@ -1,9 +1,9 @@ import { Component } from "preact"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { SecretTitleElement } from "../SecretTitleElement"; -import i18next from "i18next"; -import { route } from "preact-router"; import { kvListURL, kvViewURL } from "../../pageLinks"; +import { route } from "preact-router"; +import i18next from "i18next"; export class KeyValueDelete extends Component { render() { @@ -28,9 +28,9 @@ export class KeyValueDelete extends Component { onClick={async () => { await this.props.api.deleteSecret(baseMount, secretPath, item, version); if (version == "null") { - route(kvListURL(baseMount, secretPath)) + route(kvListURL(baseMount, secretPath)); } else { - route(kvViewURL(baseMount, secretPath, item, "null")) + route(kvViewURL(baseMount, secretPath, item, "null")); } }} > diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueVersions.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueVersions.tsx index 29e4fb9..55c9550 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueVersions.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueVersions.tsx @@ -2,21 +2,17 @@ import { Component } from "preact"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { SecretTitleElement } from "../SecretTitleElement"; import { kvViewURL } from "../../pageLinks"; -import { route } from "preact-router"; import { objectToMap } from "../../../../utils"; +import { route } from "preact-router"; -export class KeyValueVersions extends Component { +export class KeyValueVersions extends Component { async componentDidMount() { const baseMount = this.props.matches["baseMount"]; const secretPath = this.props.matches["secretPath"].split("/"); const secretItem = this.props.matches["item"]; - const metadata = await this.props.api.getSecretMetadata( - baseMount, - secretPath, - secretItem, - ); - + const metadata = await this.props.api.getSecretMetadata(baseMount, secretPath, secretItem); + const versions = Array.from(objectToMap(metadata.versions).keys()); this.setState({ versions }); @@ -52,4 +48,4 @@ export class KeyValueVersions extends Component ); } -} \ No newline at end of file +} diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx index bb4dd02..e52b5c9 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx @@ -2,13 +2,13 @@ import { CodeBlock } from "../../../elements/CodeBlock"; import { Component, JSX } from "preact"; import { CopyableInputBox } from "../../../elements/CopyableInputBox"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; +import { DoesNotExistError } from "../../../../types/internalErrors"; import { Grid, GridSizes } from "../../../elements/Grid"; import { SecretTitleElement } from "../SecretTitleElement"; import { kvDeleteURL, kvEditURL, kvVersionsURL } from "../../pageLinks"; import { route } from "preact-router"; import { sortedObjectMap } from "../../../../utils"; import i18next from "i18next"; -import { DoesNotExistError } from "../../../../types/internalErrors"; export type KVSecretViewProps = { kvData: Record; @@ -63,13 +63,18 @@ export class KeyValueView extends Component .capabilities; const mountInfo = await this.props.api.getMount(baseMount); - let kvVersion = mountInfo.options.version; + const kvVersion = mountInfo.options.version; let secretInfo: Record; if (kvVersion == "2") { try { - secretInfo = await this.props.api.getSecretKV2(baseMount, secretPath, secretItem, secretVersion); + secretInfo = await this.props.api.getSecretKV2( + baseMount, + secretPath, + secretItem, + secretVersion, + ); } catch (e) { if (e == DoesNotExistError) { secretInfo = null; @@ -79,7 +84,7 @@ export class KeyValueView extends Component secretInfo = await this.props.api.getSecretKV1(baseMount, secretPath, secretItem); } - let isDeleted = (secretInfo == null) && (kvVersion == "2"); + const isDeleted = secretInfo == null && kvVersion == "2"; this.setState({ baseMount, @@ -127,10 +132,7 @@ export class KeyValueView extends Component if (this.state.kvVersion == "2" && this.state.secretVersion == "null") { // Delete All deleteButtonText = i18next.t("kv_secret_delete_all_btn"); - } else if ( - this.state.kvVersion == "2" && - this.state.secretVersion != "null" - ) { + } else if (this.state.kvVersion == "2" && this.state.secretVersion != "null") { // Delete Version X deleteButtonText = i18next.t("kv_secret_delete_version_btn", { version: this.state.secretVersion, @@ -158,14 +160,17 @@ export class KeyValueView extends Component class="uk-button uk-button-secondary" onClick={async () => { route( - kvVersionsURL(this.state.baseMount, this.state.secretPath, this.state.secretItem), + kvVersionsURL( + this.state.baseMount, + this.state.secretPath, + this.state.secretItem, + ), ); }} > {i18next.t("kv_secret_versions_btn")} )} -

{!this.state.isDeleted && } diff --git a/src/ui/pages/Secrets/SecretTitleElement.tsx b/src/ui/pages/Secrets/SecretTitleElement.tsx index 0a893f3..b740deb 100644 --- a/src/ui/pages/Secrets/SecretTitleElement.tsx +++ b/src/ui/pages/Secrets/SecretTitleElement.tsx @@ -54,19 +54,26 @@ export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element ); })} - {item.length != 0 && (() => { - if (["kv", "transit"].includes(type)) { - return { - if (type == "kv") { - route(kvViewURL(baseMount, secretPath, item)) - } else if (type == "transit") { - route(transitViewSecretURL(baseMount, item)) - } - }}>{item} - } else { - return {item} - } - })()} + {item.length != 0 && + (() => { + if (["kv", "transit"].includes(type)) { + return ( + { + if (type == "kv") { + route(kvViewURL(baseMount, secretPath, item)); + } else if (type == "transit") { + route(transitViewSecretURL(baseMount, item)); + } + }} + > + {item} + + ); + } else { + return {item}; + } + })()} {suffix.length != 0 && {suffix}}
diff --git a/src/ui/pages/SetLanguage.tsx b/src/ui/pages/SetLanguage.tsx index a5e04b5..9e77427 100644 --- a/src/ui/pages/SetLanguage.tsx +++ b/src/ui/pages/SetLanguage.tsx @@ -8,7 +8,6 @@ import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { MarginInline } from "../elements/MarginInline"; import { PageTitle } from "../elements/PageTitle"; -import { route } from "preact-router"; import i18next from "i18next"; const languageIDs = Object.getOwnPropertyNames(translations); diff --git a/src/ui/pages/pageLinks.tsx b/src/ui/pages/pageLinks.tsx index 5d49da8..164fcee 100644 --- a/src/ui/pages/pageLinks.tsx +++ b/src/ui/pages/pageLinks.tsx @@ -10,7 +10,12 @@ export function kvNewURL(baseMount: string, secretPath?: string[]): string { return `/secrets/kv/new/${baseMount}` + (secretPath ? `/${secretPath.join("/")}` : ""); } -export function kvDeleteURL(baseMount: string, secretPath: string[], secret: string, version: string = "null"): string { +export function kvDeleteURL( + baseMount: string, + secretPath: string[], + secret: string, + version = "null", +): string { return `/secrets/kv/delete/${secret}/${version}/${baseMount}/${secretPath.join("/")}`; } @@ -22,7 +27,12 @@ export function kvVersionsURL(baseMount: string, secretPath: string[], secret: s return `/secrets/kv/versions/${secret}/${baseMount}/${secretPath.join("/")}`; } -export function kvViewURL(baseMount: string, secretPath: string[], secret: string, version: string = "null"): string { +export function kvViewURL( + baseMount: string, + secretPath: string[], + secret: string, + version = "null", +): string { return `/secrets/kv/view/${secret}/${version}/${baseMount}/${secretPath.join("/")}`; }