From e180c44e50b0bfceebd0bb9c8c6f946eda273531 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sat, 8 May 2021 03:07:57 +0100 Subject: [PATCH] Add typing to KeyValueSecret.ts. --- src/allPages.ts | 2 +- .../{KeyValueSecret.js => KeyValueSecret.ts} | 24 +++++++++---------- src/utils.ts | 2 +- tsconfig.json | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) rename src/pages/KeyValue/{KeyValueSecret.js => KeyValueSecret.ts} (86%) diff --git a/src/allPages.ts b/src/allPages.ts index d54d9bb..92c7185 100644 --- a/src/allPages.ts +++ b/src/allPages.ts @@ -2,7 +2,7 @@ import { HomePage } from "./pages/Home"; import { KeyValueDeletePage } from "./pages/KeyValue/KeyValueDelete.js"; import { KeyValueNewPage } from "./pages/KeyValue/KeyValueNew.js"; import { KeyValueSecretEditPage } from "./pages/KeyValue/KeyValueSecretsEdit"; -import { KeyValueSecretPage } from "./pages/KeyValue/KeyValueSecret.js"; +import { KeyValueSecretPage } from "./pages/KeyValue/KeyValueSecret"; import { KeyValueVersionsPage } from "./pages/KeyValue/KeyValueVersions"; import { KeyValueViewPage } from "./pages/KeyValue/KeyValueView"; import { LoginPage } from "./pages/Login"; diff --git a/src/pages/KeyValue/KeyValueSecret.js b/src/pages/KeyValue/KeyValueSecret.ts similarity index 86% rename from src/pages/KeyValue/KeyValueSecret.js rename to src/pages/KeyValue/KeyValueSecret.ts index 207c1b9..2bdd594 100644 --- a/src/pages/KeyValue/KeyValueSecret.js +++ b/src/pages/KeyValue/KeyValueSecret.ts @@ -4,7 +4,7 @@ import { changePage, setPageContent, setTitleElement } from "../../pageUtils"; import { getCapabilities } from "../../api/getCapabilities"; import { getSecret } from "../../api/getSecret"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.ts"; +import { pageState } from "../../globalPageState"; import { sortedObjectMap } from "../../utils"; import { undeleteSecret } from "../../api/undeleteSecret"; import Prism from "prismjs"; @@ -15,7 +15,7 @@ export class KeyValueSecretPage extends Page { constructor() { super(); } - goBack() { + goBack(): void { if (pageState.currentSecretVersion != null) { pageState.currentSecretVersion = null; changePage("KEY_VALUE_VERSIONS"); @@ -25,7 +25,7 @@ export class KeyValueSecretPage extends Page { } } - async render() { + async render(): Promise { setTitleElement(pageState); setPageContent(makeElement({ tag: "div", @@ -46,10 +46,10 @@ export class KeyValueSecretPage extends Page { ] })); - let buttonsBlock = document.querySelector("#buttonsBlock"); - let kvList = document.querySelector("#kvList"); + const buttonsBlock = document.querySelector("#buttonsBlock"); + const kvList = document.querySelector("#kvList"); let isSecretNestedJson = false; - let caps = await getCapabilities(pageState.currentBaseMount, pageState.currentSecretPath, pageState.currentSecret); + const caps = await getCapabilities(pageState.currentBaseMount, pageState.currentSecretPath, pageState.currentSecret); if (caps.includes("delete")) { let deleteButtonText = i18next.t("kv_secret_delete_btn"); if (pageState.currentMountType == "kv-v2" && pageState.currentSecretVersion == null) { @@ -119,7 +119,7 @@ export class KeyValueSecretPage extends Page { pageState.currentSecret, pageState.currentSecretVersion ).then(_ => { - changePage(pageState.currentPage); + changePage(pageState.currentPageString); }); }, })); @@ -128,12 +128,12 @@ export class KeyValueSecretPage extends Page { const secretsMap = sortedObjectMap(secretInfo); - for (let value of secretsMap.values()) { + for (const value of secretsMap.values()) { if (typeof value == 'object') isSecretNestedJson = true; } if (isSecretNestedJson) { - let jsonText = JSON.stringify(Object.fromEntries(secretsMap), null, 4); + const jsonText = JSON.stringify(sortedObjectMap(secretsMap as Record), null, 4); kvList.appendChild(makeElement({ tag: "pre", class: ["code-block", "language-json", "line-numbers"], @@ -141,14 +141,14 @@ export class KeyValueSecretPage extends Page { })); } else { secretsMap.forEach((value, key) => { - let kvListElement = this.makeKVListElement(key, value); + const kvListElement = this.makeKVListElement(key, value); kvList.appendChild(kvListElement); }, this); } document.getElementById("loadingText").remove(); }); } - makeKVListElement(key, value) { + makeKVListElement(key: string, value: string): HTMLElement { return makeElement({ tag: "div", class: ["uk-grid", "uk-grid-small", "uk-text-left"], @@ -156,7 +156,7 @@ export class KeyValueSecretPage extends Page { }); } - get name() { + get name(): string { return i18next.t("kv_secret_title"); } } \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 404e5d4..4fda6c1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,7 +5,7 @@ export function removeDoubleSlash(str: string): string { export const getObjectKeys = (obj: Record): string[] => Object.getOwnPropertyNames(obj); export const objectToMap = - (obj: Record): Map => new Map(Object.entries(obj)); + (obj: Record): Map => new Map(Object.entries(obj)); export const sortedObjectMap = (obj: Record): Map => new Map(Object.entries(obj).sort()); diff --git a/tsconfig.json b/tsconfig.json index 1cb4723..5e15dbd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "noImplicitAny": false, "allowSyntheticDefaultImports": true, "module": "es6", - "target": "es5", + "target": "es2015", "jsx": "react", "allowJs": true, "moduleResolution": "node",