diff --git a/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx b/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx index 1ef2eda..bcd65b0 100644 --- a/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx @@ -15,13 +15,13 @@ export type KVEditProps = { type KVEditState = | { - dataLoaded: false; - } + dataLoaded: false; + } | { - dataLoaded: true; - kvData: Record; - code: string; - }; + dataLoaded: true; + kvData: Record; + code: string; + }; export class KVEditor extends Component { constructor() { @@ -34,6 +34,7 @@ export class KVEditor extends Component { async editorSave(): Promise { if (!this.state.dataLoaded) return; const editorContent = this.state.code; + if (!verifyJSONString(editorContent)) { setErrorText(i18next.t("kv_sec_edit_invalid_json_err")); return; @@ -65,6 +66,7 @@ export class KVEditor extends Component { this.setState({ dataLoaded: true, kvData: kvData, + code: this.getStringKVData(kvData), }); }); return; @@ -76,24 +78,27 @@ export class KVEditor extends Component { } } + getStringKVData(data: Record): string { + return JSON.stringify( + Object.fromEntries(sortedObjectMap(data)), + null, + 4, + ); + } + render(): JSX.Element { if (!this.state.dataLoaded) { return

{i18next.t("kv_sec_edit_loading")}

; } - const secretsJSON = JSON.stringify( - Object.fromEntries(sortedObjectMap(this.state.kvData)), - null, - 4, - ); - return (

{}} - code={secretsJSON} + highlight={() => { }} + code={this.getStringKVData(this.state.kvData)} onUpdate={(code) => this.onCodeUpdate(code)} + options={{ tab: " ".repeat(4) }} />