Append an empty item when editing an existing Secure Variable (#13436)

* Did-insert modifier to add an extra row when editing

* Defensive logic on model existing

* Defensive pattern on copy keyValues
This commit is contained in:
Phil Renaud 2022-06-20 16:39:16 -04:00 committed by Tim Gross
parent 7de6301054
commit 7ddbd36443
2 changed files with 14 additions and 2 deletions

View File

@ -1,4 +1,6 @@
<form class="new-secure-variables" autocomplete="off" {{on "submit" this.save}}>
<form class="new-secure-variables" autocomplete="off" {{on "submit" this.save}}
{{did-insert this.appendItemIfEditing}}
>
{{!-- TODO: {{if this.parseError 'is-danger'}} on inputs --}}
<div>
<label>

View File

@ -26,7 +26,7 @@ export default class SecureVariableFormComponent extends Component {
return !this.args.model?.path;
}
@tracked keyValues = copy(this.args.model?.keyValues)?.map((kv) => {
@tracked keyValues = copy(this.args.model?.keyValues || [])?.map((kv) => {
return {
key: kv.key,
value: kv.value,
@ -109,4 +109,14 @@ export default class SecureVariableFormComponent extends Component {
});
}
}
/**
* Appends a row to the end of the Items list if you're editing an existing variable.
* This will allow it to auto-focus and make all other rows deletable
*/
@action appendItemIfEditing() {
if (!this.args.model?.isNew) {
this.appendRow();
}
}
}