From 4b001c69317d76961cc5e0e3d1863620ed341106 Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Wed, 19 Jan 2022 18:13:13 +0000 Subject: [PATCH] add ability to hide k/v values matching a key --- src/settings/Settings.ts | 14 +++ src/translations/en.js | 1 + src/ui/elements/CopyableInputBox.tsx | 6 +- .../pages/Secrets/KeyValue/KeyValueView.tsx | 103 +++++++++++------- src/ui/pages/Settings/KeyValueSettings.tsx | 22 +++- 5 files changed, 98 insertions(+), 48 deletions(-) diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index b49e8bc..8f3e030 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -114,4 +114,18 @@ export class Settings { this.storage.setItem("kvViewIndent", String(value)); this.alertChange("kvViewIndent"); } + + get kvHideKeyValues(): string[] { + const value = this.storage.getItem("kvHideKeyValues") || ""; + return value.split(","); + } + + set kvHideKeyValues(value: string[] | string) { + if (typeof value === "string") { + this.storage.setItem("kvHideKeyValues", value); + } else { + this.storage.setItem("kvHideKeyValues", value.join(",")); + } + this.alertChange("kvHideKeyValues"); + } } diff --git a/src/translations/en.js b/src/translations/en.js index 78d4c19..a1db8f6 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -88,6 +88,7 @@ module.exports = { settings_kv_default_editor_language: "Default Editor Syntax", settings_kv_editor_indent: "Editor Indent", settings_kv_always_view_in_code_mode: "Always view in code mode", + settings_kv_hide_values: "Hide values with key (comma seporated)", // Set Vault URL Page set_vault_url_title: "Set Vault URL", diff --git a/src/ui/elements/CopyableInputBox.tsx b/src/ui/elements/CopyableInputBox.tsx index f906b09..a576b14 100644 --- a/src/ui/elements/CopyableInputBox.tsx +++ b/src/ui/elements/CopyableInputBox.tsx @@ -7,6 +7,7 @@ import i18next from "i18next"; export type CopyableInputBoxProps = { text: string; copyable?: boolean; + hideLikePassword?: boolean; }; export class CopyableInputBox extends Component { @@ -18,6 +19,9 @@ export class CopyableInputBox extends Component } render(): JSX.Element { + let type = "text"; + if (this.props.hideLikePassword) type = "password"; + return (
@@ -31,7 +35,7 @@ export class CopyableInputBox extends Component aria-label={i18next.t("copy_input_box_copy_icon_text")} /> )} - +
); diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx index 9879396..a78f8ff 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx @@ -12,13 +12,70 @@ import { kvDeleteURL, kvEditURL, kvVersionsURL } from "../../pageLinks"; import { sortedObjectMap } from "../../../../utils"; import i18next from "i18next"; +type KVSecretViewDataProps = DefaultPageProps & { data: Map }; + +export class KVSecretCodeVew extends Component { + syntaxSelectRef = createRef(); + render() { + const syntax = this.state.syntax || this.props.settings.kvViewDefaultLanguage; + const secretData = Object.fromEntries(this.props.data); + const codeData = dumpData(secretData, this.props.settings.kvViewIndent, syntax); + return ( + <> + + + + + + ); + } +} + +export class KVSecretNormalVew extends Component { + render() { + return ( + <> + {Array.from(this.props.data).map((data: [string, unknown]) => { + const key = data[0]; + const value = data[1] as string; + console.log(this.props.settings.kvHideKeyValues); + return ( + + + + + ); + })} + + ); + } +} + export type KVSecretViewProps = DefaultPageProps & { kvData: Record; }; export class KVSecretVew extends Component { - syntaxSelectRef = createRef(); - render(): JSX.Element { const secretsMap = sortedObjectMap(this.props.kvData); let isMultiLevel = false; @@ -28,47 +85,9 @@ export class KVSecretVew extends Component - - - - - - ); + return ; } else { - return ( - <> - {Array.from(secretsMap).map((data: [string, unknown]) => ( - - - - - ))} - - ); + return ; } } } diff --git a/src/ui/pages/Settings/KeyValueSettings.tsx b/src/ui/pages/Settings/KeyValueSettings.tsx index aece50e..4cb5c75 100644 --- a/src/ui/pages/Settings/KeyValueSettings.tsx +++ b/src/ui/pages/Settings/KeyValueSettings.tsx @@ -49,11 +49,10 @@ export class KeyValueViewSettings extends Component { /> - ) + ); } } - export class KeyValueEditorSettings extends Component { editorSyntaxSelectRef = createRef(); editorIndentInputRef = createRef(); @@ -99,14 +98,13 @@ export class KeyValueEditorSettings extends Component { /> - ) + ); } } - - export class KeyValueSettings extends Component { codeModeToggleRef = createRef(); + hideKeysRef = createRef(); render() { return ( @@ -130,6 +128,20 @@ export class KeyValueSettings extends Component { }} /> + + {/* hide values on keys */} + + { + const value = this.hideKeysRef.current.value; + this.props.settings.kvHideKeyValues = value; + settingsSavedNotification(); + }} + /> + ); }