Skip to content

Commit

Permalink
[ui] A few variables-ui-related bugfixes (#17319)
Browse files Browse the repository at this point in the history
* A few variable-adding bugfixes

* Disable Delete button if only one KV is left, and remove entity warnings on Add More
  • Loading branch information
philrenaud authored May 25, 2023
1 parent 4510f6d commit 087ac3a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .changelog/17319.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: fixed a handful of UX-related bugs during variable editing
```
22 changes: 12 additions & 10 deletions ui/app/components/variable-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
Format: <code>nomad/jobs/&lt;jobname&gt;</code>, <code>nomad/jobs/&lt;jobname&gt;/&lt;groupname&gt;</code>, <code>nomad/jobs/&lt;jobname&gt;/&lt;groupname&gt;/&lt;taskname&gt;</code></p>
</div>
{{/unless}}

{{#if this.shouldShowLinkedEntities}}
<VariableForm::RelatedEntities
@new={{true}}
@job={{@model.pathLinkedEntities.job}}
@group={{@model.pathLinkedEntities.group}}
@task={{@model.pathLinkedEntities.task}}
@namespace={{this.variableNamespace}}
/>
{{/if}}

{{/if}}

{{#if this.hasConflict}}
Expand Down Expand Up @@ -137,6 +148,7 @@
class="delete-row button is-danger is-inverted"
type="button"
{{on "click" (action this.deleteRow entry)}}
disabled={{eq this.keyValues.length 1}}
>
Delete
</button>
Expand All @@ -150,16 +162,6 @@
{{/if}}
{{/if}}

{{#if (and this.shouldShowLinkedEntities @model.isNew)}}
<VariableForm::RelatedEntities
@new={{true}}
@job={{@model.pathLinkedEntities.job}}
@group={{@model.pathLinkedEntities.group}}
@task={{@model.pathLinkedEntities.task}}
@namespace={{this.variableNamespace}}
/>
{{/if}}

<footer>
{{#unless this.isJSONView}}
{{#unless this.isJobTemplateVariable}}
Expand Down
12 changes: 9 additions & 3 deletions ui/app/components/variable-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ export default class VariableFormComponent extends Component {
let existingVariable = existingVariables
.without(this.args.model)
.find(
(v) => v.path === pathValue && v.namespace === this.variableNamespace
(v) =>
v.path === pathValue &&
(v.namespace === this.variableNamespace || !this.variableNamespace)
);
if (existingVariable) {
return {
Expand Down Expand Up @@ -180,7 +182,10 @@ export default class VariableFormComponent extends Component {
}

@action appendRow() {
this.keyValues.pushObject(copy(EMPTY_KV));
// Clear our any entity errors
let newRow = copy(EMPTY_KV);
newRow.warnings = EmberObject.create();
this.keyValues.pushObject(newRow);
}

@action deleteRow(row) {
Expand Down Expand Up @@ -372,7 +377,8 @@ export default class VariableFormComponent extends Component {
return (
this.args.model.pathLinkedEntities?.job ||
this.args.model.pathLinkedEntities?.group ||
this.args.model.pathLinkedEntities?.task
this.args.model.pathLinkedEntities?.task ||
trimPath([this.path]) === 'nomad/jobs'
);
}

Expand Down
4 changes: 3 additions & 1 deletion ui/app/components/variable-form/related-entities.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
{{else if @group}}
group <LinkTo @route="jobs.job.task-group" @models={{array (concat @job "@" @namespace) @group}}>{{@group}} <FlightIcon @name="external-link" /></LinkTo>
{{else if @job}}
job <LinkTo @route="jobs.job" @model={{concat @job "@" @namespace}}>{{@job}} <FlightIcon @name="external-link" /></LinkTo><
job <LinkTo @route="jobs.job" @model={{concat @job "@" @namespace}}>{{@job}} <FlightIcon @name="external-link" /></LinkTo>
{{else}}
all nomad jobs in this namespace
{{/if}}
</span>
</p>
3 changes: 2 additions & 1 deletion ui/app/controllers/variables/variable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export default class VariablesVariableIndexController extends Controller {
return (
this.model.pathLinkedEntities?.job ||
this.model.pathLinkedEntities?.group ||
this.model.pathLinkedEntities?.task
this.model.pathLinkedEntities?.task ||
this.model.path === 'nomad/jobs'
);
}

Expand Down

0 comments on commit 087ac3a

Please sign in to comment.