fix saving a KV secret when no changes have been made.
This commit is contained in:
parent
7a43686676
commit
44c17988e8
|
@ -15,13 +15,13 @@ export type KVEditProps = {
|
||||||
|
|
||||||
type KVEditState =
|
type KVEditState =
|
||||||
| {
|
| {
|
||||||
dataLoaded: false;
|
dataLoaded: false;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
dataLoaded: true;
|
dataLoaded: true;
|
||||||
kvData: Record<string, unknown>;
|
kvData: Record<string, unknown>;
|
||||||
code: string;
|
code: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class KVEditor extends Component<KVEditProps, KVEditState> {
|
export class KVEditor extends Component<KVEditProps, KVEditState> {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -34,6 +34,7 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
|
||||||
async editorSave(): Promise<void> {
|
async editorSave(): Promise<void> {
|
||||||
if (!this.state.dataLoaded) return;
|
if (!this.state.dataLoaded) return;
|
||||||
const editorContent = this.state.code;
|
const editorContent = this.state.code;
|
||||||
|
|
||||||
if (!verifyJSONString(editorContent)) {
|
if (!verifyJSONString(editorContent)) {
|
||||||
setErrorText(i18next.t("kv_sec_edit_invalid_json_err"));
|
setErrorText(i18next.t("kv_sec_edit_invalid_json_err"));
|
||||||
return;
|
return;
|
||||||
|
@ -65,6 +66,7 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
|
||||||
this.setState({
|
this.setState({
|
||||||
dataLoaded: true,
|
dataLoaded: true,
|
||||||
kvData: kvData,
|
kvData: kvData,
|
||||||
|
code: this.getStringKVData(kvData),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -76,24 +78,27 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getStringKVData(data: Record<string, unknown>): string {
|
||||||
|
return JSON.stringify(
|
||||||
|
Object.fromEntries(sortedObjectMap(data)),
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
if (!this.state.dataLoaded) {
|
if (!this.state.dataLoaded) {
|
||||||
return <p>{i18next.t("kv_sec_edit_loading")}</p>;
|
return <p>{i18next.t("kv_sec_edit_loading")}</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const secretsJSON = JSON.stringify(
|
|
||||||
Object.fromEntries(sortedObjectMap(this.state.kvData)),
|
|
||||||
null,
|
|
||||||
4,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p class="uk-text-danger" id="errorText" />
|
<p class="uk-text-danger" id="errorText" />
|
||||||
<CodeJarEditor
|
<CodeJarEditor
|
||||||
highlight={() => {}}
|
highlight={() => { }}
|
||||||
code={secretsJSON}
|
code={this.getStringKVData(this.state.kvData)}
|
||||||
onUpdate={(code) => this.onCodeUpdate(code)}
|
onUpdate={(code) => this.onCodeUpdate(code)}
|
||||||
|
options={{ tab: " ".repeat(4) }}
|
||||||
/>
|
/>
|
||||||
<button class="uk-button uk-button-primary" onClick={() => this.editorSave()}>
|
<button class="uk-button uk-button-primary" onClick={() => this.editorSave()}>
|
||||||
{i18next.t("kv_sec_edit_btn")}
|
{i18next.t("kv_sec_edit_btn")}
|
||||||
|
|
Loading…
Reference in a new issue