diff --git a/src/pages/Secrets/KeyValue/KeyValueSecret.tsx b/src/pages/Secrets/KeyValue/KeyValueSecret.tsx index cffe87e..ff47038 100644 --- a/src/pages/Secrets/KeyValue/KeyValueSecret.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueSecret.tsx @@ -3,12 +3,53 @@ import { Page } from "../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; import { getCapabilities } from "../../../api/sys/getCapabilities"; import { getSecret } from "../../../api/kv/getSecret"; -import { render } from "preact"; +import { Component, JSX, render } from "preact"; import { sortedObjectMap } from "../../../utils"; import { undeleteSecret } from "../../../api/kv/undeleteSecret"; import Prism from "prismjs"; import i18next from "i18next"; +export type KVSecretViewProps = { + kvData: Record; +}; + +export class KVSecretVew extends Component { + render(): JSX.Element { + const secretsMap = sortedObjectMap(this.props.kvData); + let isMultiLevelJSON = false; + + for (const value of secretsMap.values()) { + if (typeof value == "object") isMultiLevelJSON = true; + } + + if (isMultiLevelJSON) { + const jsonText = JSON.stringify( + sortedObjectMap(secretsMap as unknown as Record), + null, + 4, + ); + const highlightedJson = Prism.highlight(jsonText, Prism.languages.json, "json"); + return ( +
+      );
+    } else {
+      return (
+        <>
+          {Array.from(secretsMap).map((data: [string, string]) => (
+            
+ + +
+ ))} + + ); + } + } +} + export class KeyValueSecretPage extends Page { constructor() { super(); @@ -28,64 +69,6 @@ export class KeyValueSecretPage extends Page { this.state.secretPath, this.state.secretItem, ); - render( -
-

- { - // Delete Button - caps.includes("delete") && ( - - ) - } - {caps.includes("update") && this.state.secretVersion == null && ( - - )} - {this.state.secretMountType == "kv-v2" && ( - - )} -

-

{i18next.t("kv_secret_loading")}

-
-
, - this.router.pageContentElement, - ); - - const kvList = document.querySelector("#kvList"); - let isSecretNestedJson = false; const secretInfo = await getSecret( this.state.baseMount, @@ -96,70 +79,95 @@ export class KeyValueSecretPage extends Page { ); // On kv-v2, secrets can be deleted temporarily with the ability to restore - if (secretInfo == null && this.state.secretMountType == "kv-v2") { - try { - document.querySelector("#buttonsBlock").remove(); - document.getElementById("loadingText").remove(); - } catch (_) { - // Do Nothing - } - render( - <> -

{i18next.t("kv_secret_deleted_text")}

- - , - kvList, - ); - return; - } + // Do not show any buttons when the secret is deleted. + let secretIsDeleted = secretInfo == null && this.state.secretMountType == "kv-v2"; - const secretsMap = sortedObjectMap(secretInfo); + render( +
+

+ { + // Delete Button + !secretIsDeleted && + caps.includes("delete") && ( + + ) + } + { + !secretIsDeleted && + caps.includes("update") && this.state.secretVersion == null && ( + + )} + { + !secretIsDeleted && + this.state.secretMountType == "kv-v2" && ( + + )} +

- for (const value of secretsMap.values()) { - if (typeof value == "object") isSecretNestedJson = true; - } + {!secretIsDeleted && + + } - if (isSecretNestedJson) { - const jsonText = JSON.stringify( - sortedObjectMap(secretsMap as unknown as Record), - null, - 4, - ); - const highlightedJson = Prism.highlight(jsonText, Prism.languages.json, "json"); - render( -
,
-        kvList,
-      );
-    } else {
-      render(
-        <>
-          {Array.from(secretsMap).map((data: [string, string]) => (
-            
- - -
- ))} - , - kvList, - ); - } - document.getElementById("loadingText").remove(); + {secretIsDeleted && + <> +

{i18next.t("kv_secret_deleted_text")}

+ + + } + +
, + this.router.pageContentElement, + ); } async renderPageTitle(): Promise {