From f545264c4b106a27b9d3e14223d4fa48d8bb0864 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Thu, 19 Sep 2024 11:03:00 -0400 Subject: [PATCH 1/7] Timeline styles and their buttons modernized, and tags added --- ui/app/models/job-version.js | 2 + ui/app/models/version-tag.js | 13 ++++++ ui/app/styles/components/timeline.scss | 41 +++++++++++++++++++ ui/app/templates/components/job-version.hbs | 40 ++++++++++++++---- .../templates/components/two-step-button.hbs | 6 +-- 5 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 ui/app/models/version-tag.js diff --git a/ui/app/models/job-version.js b/ui/app/models/job-version.js index c4a0ef5f729..8fc1b3700b0 100644 --- a/ui/app/models/job-version.js +++ b/ui/app/models/job-version.js @@ -4,6 +4,7 @@ */ import Model from '@ember-data/model'; +import { fragment } from 'ember-data-model-fragments/attributes'; import { attr, belongsTo } from '@ember-data/model'; export default class JobVersion extends Model { @@ -12,6 +13,7 @@ export default class JobVersion extends Model { @attr('date') submitTime; @attr('number') number; @attr() diff; + @fragment('version-tag') taggedVersion; revertTo() { return this.store.adapterFor('job-version').revertTo(this); diff --git a/ui/app/models/version-tag.js b/ui/app/models/version-tag.js new file mode 100644 index 00000000000..1218498dde8 --- /dev/null +++ b/ui/app/models/version-tag.js @@ -0,0 +1,13 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +import Fragment from 'ember-data-model-fragments/fragment'; +import { attr } from '@ember-data/model'; + +export default class VersionTagModel extends Fragment { + @attr() name; + @attr() description; + @attr() taggedTime; +} diff --git a/ui/app/styles/components/timeline.scss b/ui/app/styles/components/timeline.scss index bb60059d306..cd1f5269a60 100644 --- a/ui/app/styles/components/timeline.scss +++ b/ui/app/styles/components/timeline.scss @@ -60,6 +60,47 @@ > .boxed-section { margin-bottom: 0; + + .boxed-section-head { + box-shadow: var(--token-surface-mid-box-shadow); + border: none; + &.tagged { + border-top: 1px solid var(--token-color-border-highlight); + } + } + } + + .timeline-tag { + display: grid; + grid-template-areas: 'title description options'; + grid-template-columns: auto 1fr auto; + gap: 0.5rem; + align-items: center; + margin: 0 0.5rem; + font-size: 0.875rem; + + .tag-name { + grid-area: title; + background: var(--token-color-surface-highlight); + border: 1px solid var(--token-color-border-highlight); + border-bottom: none; + border-top-left-radius: 0.25rem; + border-top-right-radius: 0.25rem; + padding: 0.25rem 0.5rem; + } + + .options { + grid-area: options; + } + + .tag-description { + grid-area: description; + white-space: no-wrap; + overflow: hidden; + text-overflow: ellipsis; + text-wrap: nowrap; + font-style: italic; + } } } } diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index 19cceffe0ca..ba266db5624 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -3,7 +3,19 @@ SPDX-License-Identifier: BUSL-1.1 ~}} -
+{{#if this.version.taggedVersion}} +
+ {{!-- --}} + + {{this.version.taggedVersion.name}} + + + {{this.version.taggedVersion.description}} + +
+{{/if}} + +
Version #{{this.version.number}} Stable @@ -27,24 +39,34 @@ @confirmText="Yes, Revert Version" @confirmationMessage="Are you sure you want to revert to this version?" @inlineText={{true}} + @size="small" @fadingBackground={{true}} @awaitingConfirmation={{this.revertTo.isRunning}} @onConfirm={{perform this.revertTo}} /> {{else}} - + @size="small" + @color="secondary" + @isInline={{true}} + @text="Revert" + title="You don’t have permission to revert" + /> {{/if}} {{/unless}} {{#if this.version.diff}} - + {{!-- --}} + {{!-- ^--- convert to --}} + {{else}}
No Changes
{{/if}} diff --git a/ui/app/templates/components/two-step-button.hbs b/ui/app/templates/components/two-step-button.hbs index 4931e3983b7..a25a2935376 100644 --- a/ui/app/templates/components/two-step-button.hbs +++ b/ui/app/templates/components/two-step-button.hbs @@ -6,7 +6,7 @@ {{#if this.isIdle}} Date: Thu, 19 Sep 2024 16:01:25 -0400 Subject: [PATCH 2/7] styled but not yet functional version blocks --- ui/app/components/job-version.js | 33 ++--- ui/app/styles/components/timeline.scss | 98 ++++++++----- ui/app/templates/components/job-version.hbs | 155 +++++++++++--------- 3 files changed, 164 insertions(+), 122 deletions(-) diff --git a/ui/app/components/job-version.js b/ui/app/components/job-version.js index e05c54b8f70..d235017cb43 100644 --- a/ui/app/components/job-version.js +++ b/ui/app/components/job-version.js @@ -3,21 +3,19 @@ * SPDX-License-Identifier: BUSL-1.1 */ -import Component from '@ember/component'; +import Component from '@glimmer/component'; import { action, computed } from '@ember/object'; -import { classNames } from '@ember-decorators/component'; +import { alias } from '@ember/object/computed'; import { inject as service } from '@ember/service'; +import { tracked } from '@glimmer/tracking'; import { task } from 'ember-concurrency'; import messageForError from 'nomad-ui/utils/message-from-adapter-error'; -import classic from 'ember-classic-decorator'; const changeTypes = ['Added', 'Deleted', 'Edited']; -@classic -@classNames('job-version', 'boxed-section') export default class JobVersion extends Component { - version = null; - isOpen = false; + @alias('args.version') version; + @tracked isOpen = false; // Passes through to the job-diff component verbose = true; @@ -26,7 +24,7 @@ export default class JobVersion extends Component { @computed('version.diff') get changeCount() { - const diff = this.get('version.diff'); + const diff = this.version.diff; const taskGroups = diff.TaskGroups || []; if (!diff) { @@ -44,36 +42,35 @@ export default class JobVersion extends Component { @computed('version.{number,job.version}') get isCurrent() { - return this.get('version.number') === this.get('version.job.version'); + return this.version.number === this.version.get('job.version'); } @action toggleDiff() { - this.toggleProperty('isOpen'); + this.isOpen = !this.isOpen; } @task(function* () { try { - const versionBeforeReversion = this.get('version.job.version'); - + const versionBeforeReversion = this.version.get('job.version'); yield this.version.revertTo(); - yield this.version.job.reload(); - - const versionAfterReversion = this.get('version.job.version'); + yield this.version.get('job').reload(); + const versionAfterReversion = this.version.get('job.version'); if (versionBeforeReversion === versionAfterReversion) { - this.handleError({ + this.args.handleError({ level: 'warn', title: 'Reversion Had No Effect', description: 'Reverting to an identical older version doesn’t produce a new version', }); } else { - const job = this.get('version.job'); + const job = this.version.get('job'); this.router.transitionTo('jobs.job.index', job.get('idWithNamespace')); } } catch (e) { - this.handleError({ + console.log('catchy', e); + this.args.handleError({ level: 'danger', title: 'Could Not Revert', description: messageForError(e, 'revert'), diff --git a/ui/app/styles/components/timeline.scss b/ui/app/styles/components/timeline.scss index cd1f5269a60..fcae340887b 100644 --- a/ui/app/styles/components/timeline.scss +++ b/ui/app/styles/components/timeline.scss @@ -60,46 +60,78 @@ > .boxed-section { margin-bottom: 0; + } - .boxed-section-head { - box-shadow: var(--token-surface-mid-box-shadow); - border: none; + .job-version { + margin-bottom: 0; + & > .boxed-section { + box-shadow: var(--token-surface-high-box-shadow); + border-radius: 0.25rem; &.tagged { - border-top: 1px solid var(--token-color-border-highlight); + border: 1px solid var(--token-color-border-highlight); + } + header, + footer { + border: none; + padding: 0.5rem 1rem; } - } - } - .timeline-tag { - display: grid; - grid-template-areas: 'title description options'; - grid-template-columns: auto 1fr auto; - gap: 0.5rem; - align-items: center; - margin: 0 0.5rem; - font-size: 0.875rem; - - .tag-name { - grid-area: title; - background: var(--token-color-surface-highlight); - border: 1px solid var(--token-color-border-highlight); - border-bottom: none; - border-top-left-radius: 0.25rem; - border-top-right-radius: 0.25rem; - padding: 0.25rem 0.5rem; - } + // .boxed-section-body { + // } - .options { - grid-area: options; + footer { + background-color: var(--token-color-surface-faint); + border-top: 1px solid var(--token-color-border-faint); + display: grid; + grid-template-columns: 1fr 1fr; + align-items: center; + gap: 0.5rem; + & > .tag-options { + justify-self: start; + } + & > .version-options { + justify-self: end; + } + } } - .tag-description { - grid-area: description; - white-space: no-wrap; - overflow: hidden; - text-overflow: ellipsis; - text-wrap: nowrap; - font-style: italic; + .timeline-tag { + display: grid; + grid-template-areas: 'title description options'; + grid-template-columns: auto 1fr auto; + gap: 0.5rem; + align-items: center; + margin: 0 0.5rem; + font-size: 0.875rem; + + .tag-name { + grid-area: title; + background: var(--token-color-surface-highlight); + border: 1px solid var(--token-color-border-highlight); + border-bottom: none; + border-top-left-radius: 0.25rem; + border-top-right-radius: 0.25rem; + padding: 0.25rem 0.5rem; + // .tag-icon { + // vertical-align: text-bottom; + // height: 1rem; + // width: 1rem; + // opacity: 0.8; + // } + } + + .options { + grid-area: options; + } + + .tag-description { + grid-area: description; + white-space: no-wrap; + overflow: hidden; + text-overflow: ellipsis; + text-wrap: nowrap; + font-style: italic; + } } } } diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index ba266db5624..2bec03ef98c 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -3,77 +3,90 @@ SPDX-License-Identifier: BUSL-1.1 ~}} -{{#if this.version.taggedVersion}} -
- {{!-- --}} - - {{this.version.taggedVersion.name}} - - - {{this.version.taggedVersion.description}} - -
-{{/if}} - -
- Version #{{this.version.number}} - - Stable - {{this.version.stable}} - - - Submitted - {{format-ts this.version.submitTime}} - -
- {{#unless this.isCurrent}} - {{#if (can "run job" namespace=this.version.job.namespace)}} - - {{else}} - - {{/if}} - {{/unless}} +
+ {{#if this.version.taggedVersion}} +
+ + {{!-- {{x-icon "tag" class="tag-icon"}} --}} + {{this.version.taggedVersion.name}} + + + {{this.version.taggedVersion.description}} + +
+ {{/if}} - {{#if this.version.diff}} - {{!-- --}} - {{!-- ^--- convert to --}} - - {{else}} -
No Changes
+
+
+ Version #{{this.version.number}} + + Stable + {{this.version.stable}} + + + Submitted + {{format-ts this.version.submitTime}} + +
+ {{#if this.version.diff}} + + {{else}} +
No Changes
+ {{/if}} +
+
+ {{#if this.isOpen}} +
+ +
{{/if}} +
+
+ {{#if this.version.taggedVersion}} + + {{else}} + + {{/if}} +
+
+ {{#unless this.isCurrent}} + {{#if (can "run job" namespace=this.version.job.namespace)}} + + {{else}} + + {{/if}} + {{/unless}} +
+
-
-{{#if this.isOpen}} -
- -
-{{/if}} + From ae21a50a48aac5ab381ceb24e1573e6baa0f6c4f Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Thu, 19 Sep 2024 17:00:38 -0400 Subject: [PATCH 3/7] Rough pass at edit/unedit UX --- ui/app/components/job-version.js | 21 +++++++++++ ui/app/styles/components/timeline.scss | 3 -- ui/app/templates/components/job-version.hbs | 40 ++++++++++++++------- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/ui/app/components/job-version.js b/ui/app/components/job-version.js index d235017cb43..db288d88215 100644 --- a/ui/app/components/job-version.js +++ b/ui/app/components/job-version.js @@ -16,6 +16,7 @@ const changeTypes = ['Added', 'Deleted', 'Edited']; export default class JobVersion extends Component { @alias('args.version') version; @tracked isOpen = false; + @tracked isEditing = false; // Passes through to the job-diff component verbose = true; @@ -78,6 +79,26 @@ export default class JobVersion extends Component { } }) revertTo; + + @action + toggleEditTag() { + this.isEditing = !this.isEditing; + } + + @action + saveTag() { + this.isEditing = false; + this.editableTag.save(); + } + + @action + cancelEditTag() { + this.isEditing = false; + } + + get editableTag() { + return this.version.taggedVersion || {}; + } } const flatten = (accumulator, array) => accumulator.concat(array); diff --git a/ui/app/styles/components/timeline.scss b/ui/app/styles/components/timeline.scss index fcae340887b..a92853dd469 100644 --- a/ui/app/styles/components/timeline.scss +++ b/ui/app/styles/components/timeline.scss @@ -76,9 +76,6 @@ padding: 0.5rem 1rem; } - // .boxed-section-body { - // } - footer { background-color: var(--token-color-surface-faint); border-top: 1px solid var(--token-color-border-faint); diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index 2bec03ef98c..603c4ea4777 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -4,17 +4,28 @@ ~}}
- {{#if this.version.taggedVersion}}
- - {{!-- {{x-icon "tag" class="tag-icon"}} --}} - {{this.version.taggedVersion.name}} - - - {{this.version.taggedVersion.description}} - + {{#if this.isEditing}} + + + {{else}} + {{#if this.version.taggedVersion}} + + {{this.version.taggedVersion.name}} + + + {{this.version.taggedVersion.description}} + + {{/if}} + {{/if}}
- {{/if}}
@@ -50,10 +61,15 @@ {{/if}}
- {{#if this.version.taggedVersion}} - + {{#if this.isEditing}} + + {{else}} - + {{#if this.version.taggedVersion}} + + {{else}} + + {{/if}} {{/if}}
From e817acac399d630069a6ea024a572100787844ce Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Fri, 20 Sep 2024 16:53:03 -0400 Subject: [PATCH 4/7] Styles consolidated --- ui/app/components/job-version.js | 7 ++ ui/app/styles/components/timeline.scss | 91 ++++++++------- ui/app/templates/components/job-version.hbs | 122 ++++++++++---------- 3 files changed, 114 insertions(+), 106 deletions(-) diff --git a/ui/app/components/job-version.js b/ui/app/components/job-version.js index db288d88215..3b254cfa251 100644 --- a/ui/app/components/job-version.js +++ b/ui/app/components/job-version.js @@ -96,6 +96,13 @@ export default class JobVersion extends Component { this.isEditing = false; } + @action + deleteTag() { + this.isEditing = false; + this.editableTag.destroy(); + this.version.taggedVersion = null; + } + get editableTag() { return this.version.taggedVersion || {}; } diff --git a/ui/app/styles/components/timeline.scss b/ui/app/styles/components/timeline.scss index a92853dd469..89908d66693 100644 --- a/ui/app/styles/components/timeline.scss +++ b/ui/app/styles/components/timeline.scss @@ -67,67 +67,72 @@ & > .boxed-section { box-shadow: var(--token-surface-high-box-shadow); border-radius: 0.25rem; - &.tagged { - border: 1px solid var(--token-color-border-highlight); - } header, footer { border: none; - padding: 0.5rem 1rem; + padding: 0.75rem; } footer { background-color: var(--token-color-surface-faint); border-top: 1px solid var(--token-color-border-faint); display: grid; - grid-template-columns: 1fr 1fr; + grid-template-columns: auto auto; align-items: center; gap: 0.5rem; & > .tag-options { justify-self: start; + display: grid; + grid-template-areas: 'name description save cancel delete'; + grid-template-columns: auto 1fr auto auto auto; + gap: 0.5rem; + align-items: center; + + // Match the height of HDS:Button's @size="small" + input { + padding: 0.375rem 0.6875rem; + line-height: 100%; + } + + .tag-button-primary { + grid-area: name; + background-color: var(--token-color-surface-highlight); + color: var(--token-color-foreground-highlight-on-surface); + border-color: var(--token-color-foreground-highlight); + &:focus:before { + border-color: var(--token-color-foreground-highlight); + } + &:hover { + background-color: var(--token-color-border-highlight); + } + } + .tag-button-secondary { + grid-area: name; + } + .tag-description { + grid-area: description; + font-style: italic; + font-size: 0.875rem; + white-space: no-wrap; + overflow: hidden; + text-overflow: ellipsis; + text-wrap: nowrap; + max-width: 100%; + } + & > .tag-name { + grid-area: name; + } } & > .version-options { justify-self: end; } - } - } - - .timeline-tag { - display: grid; - grid-template-areas: 'title description options'; - grid-template-columns: auto 1fr auto; - gap: 0.5rem; - align-items: center; - margin: 0 0.5rem; - font-size: 0.875rem; - .tag-name { - grid-area: title; - background: var(--token-color-surface-highlight); - border: 1px solid var(--token-color-border-highlight); - border-bottom: none; - border-top-left-radius: 0.25rem; - border-top-right-radius: 0.25rem; - padding: 0.25rem 0.5rem; - // .tag-icon { - // vertical-align: text-bottom; - // height: 1rem; - // width: 1rem; - // opacity: 0.8; - // } - } - - .options { - grid-area: options; - } - - .tag-description { - grid-area: description; - white-space: no-wrap; - overflow: hidden; - text-overflow: ellipsis; - text-wrap: nowrap; - font-style: italic; + &.editing { + grid-template-columns: 1fr; + & > .tag-options { + width: 100%; + } + } } } } diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index 603c4ea4777..66faef88775 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -4,29 +4,6 @@ ~}}
-
- {{#if this.isEditing}} - - - {{else}} - {{#if this.version.taggedVersion}} - - {{this.version.taggedVersion.name}} - - - {{this.version.taggedVersion.description}} - - {{/if}} - {{/if}} -
-
Version #{{this.version.number}} @@ -59,50 +36,69 @@
{{/if}} -
-
- {{#if this.isEditing}} +
+ {{#if this.isEditing}} +
+ + - - {{else}} + {{#if this.version.taggedVersion}} - + + {{/if}} +
+ + {{else}} +
+ {{#if this.version.taggedVersion}} + {{else}} - + {{/if}} - {{/if}} -
-
- {{#unless this.isCurrent}} - {{#if (can "run job" namespace=this.version.job.namespace)}} - - {{else}} - - {{/if}} - {{/unless}} -
+ + {{this.version.taggedVersion.description}} + +
+
+ {{#unless this.isCurrent}} + {{#if (can "run job" namespace=this.version.job.namespace)}} + + {{else}} + + {{/if}} + {{/unless}} +
+ {{/if}}
From 38cb9ab4060aa196c80820c635ab6370cd0fd898 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Mon, 23 Sep 2024 22:27:32 -0400 Subject: [PATCH 5/7] better UX around version tag crud, plus adapter and serializers --- nomad/job_endpoint.go | 6 ++ ui/app/adapters/version-tag.js | 30 +++++++ ui/app/components/job-version.js | 86 +++++++++++++++++---- ui/app/models/version-tag.js | 2 + ui/app/serializers/job-version.js | 7 ++ ui/app/serializers/version-tag.js | 22 ++++++ ui/app/templates/components/job-version.hbs | 14 +++- 7 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 ui/app/adapters/version-tag.js create mode 100644 ui/app/serializers/version-tag.js diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index b355640d40f..dae43c70c3c 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -2429,5 +2429,11 @@ func (j *Job) TagVersion(args *structs.JobApplyTagRequest, reply *structs.JobTag } reply.Index = index + if args.Tag != nil { + reply.Name = args.Tag.Name + reply.Description = args.Tag.Description + reply.TaggedTime = args.Tag.TaggedTime + } + return nil } diff --git a/ui/app/adapters/version-tag.js b/ui/app/adapters/version-tag.js new file mode 100644 index 00000000000..4ffc55f71cb --- /dev/null +++ b/ui/app/adapters/version-tag.js @@ -0,0 +1,30 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +// @ts-check + +import ApplicationAdapter from './application'; +import classic from 'ember-classic-decorator'; + +@classic +export default class VersionTagAdapter extends ApplicationAdapter { + urlForCreateRecord(_modelName, model) { + const tagName = model.attr('name'); + const jobName = model.attr('jobName'); + return `${this.buildURL()}/job/${jobName}/versions/${tagName}/tag`; + } + + async deleteTag(jobName, tagName) { + let deletion = this.ajax( + this.urlForDeleteRecord(jobName, tagName), + 'DELETE' + ); + return deletion; + } + + urlForDeleteRecord(jobName, tagName) { + return `${this.buildURL()}/job/${jobName}/versions/${tagName}/tag`; + } +} diff --git a/ui/app/components/job-version.js b/ui/app/components/job-version.js index 3b254cfa251..3ee2c0769c3 100644 --- a/ui/app/components/job-version.js +++ b/ui/app/components/job-version.js @@ -14,14 +14,35 @@ import messageForError from 'nomad-ui/utils/message-from-adapter-error'; const changeTypes = ['Added', 'Deleted', 'Edited']; export default class JobVersion extends Component { + @service store; + @service notifications; + @service router; + @alias('args.version') version; @tracked isOpen = false; @tracked isEditing = false; + @tracked editableTag; // Passes through to the job-diff component verbose = true; - @service router; + constructor() { + super(...arguments); + this.initializeEditableTag(); + } + + initializeEditableTag() { + if (this.version.taggedVersion) { + this.editableTag = this.store.createRecord('versionTag', { + name: this.version.taggedVersion.name, + description: this.version.taggedVersion.description, + }); + } else { + this.editableTag = this.store.createRecord('versionTag'); + } + this.editableTag.versionNumber = this.version.number; + this.editableTag.jobName = this.version.get('job.plainId'); + } @computed('version.diff') get changeCount() { @@ -70,7 +91,6 @@ export default class JobVersion extends Component { this.router.transitionTo('jobs.job.index', job.get('idWithNamespace')); } } catch (e) { - console.log('catchy', e); this.args.handleError({ level: 'danger', title: 'Could Not Revert', @@ -80,31 +100,71 @@ export default class JobVersion extends Component { }) revertTo; + @action + handleKeydown(event) { + if (event.key === 'Escape') { + this.cancelEditTag(); + } + } + @action toggleEditTag() { this.isEditing = !this.isEditing; } @action - saveTag() { - this.isEditing = false; - this.editableTag.save(); + async saveTag(event) { + event.preventDefault(); + try { + const savedTag = await this.editableTag.save(); + this.version.taggedVersion = savedTag; + this.version.taggedVersion.setProperties({ + ...savedTag.toJSON(), + }); + this.initializeEditableTag(); + this.isEditing = false; + + this.notifications.add({ + title: 'Job Version Tagged', + color: 'success', + }); + } catch (error) { + console.log('error tagging job version', error); + this.notifications.add({ + title: 'Error Tagging Job Version', + message: messageForError(error), + color: 'critical', + }); + } } @action cancelEditTag() { this.isEditing = false; + this.initializeEditableTag(); } @action - deleteTag() { - this.isEditing = false; - this.editableTag.destroy(); - this.version.taggedVersion = null; - } - - get editableTag() { - return this.version.taggedVersion || {}; + async deleteTag() { + try { + await this.store + .adapterFor('version-tag') + .deleteTag(this.editableTag.jobName, this.editableTag.name); + this.notifications.add({ + title: 'Job Version Un-Tagged', + color: 'success', + }); + // this.version.set('taggedVersion', null); + this.version.taggedVersion = null; + this.initializeEditableTag(); + this.isEditing = false; + } catch (error) { + this.notifications.add({ + title: 'Error Un-Tagging Job Version', + message: messageForError(error), + color: 'critical', + }); + } } } diff --git a/ui/app/models/version-tag.js b/ui/app/models/version-tag.js index 1218498dde8..6aec72a602c 100644 --- a/ui/app/models/version-tag.js +++ b/ui/app/models/version-tag.js @@ -10,4 +10,6 @@ export default class VersionTagModel extends Fragment { @attr() name; @attr() description; @attr() taggedTime; + @attr('number') versionNumber; + @attr('string') jobName; } diff --git a/ui/app/serializers/job-version.js b/ui/app/serializers/job-version.js index 4982501588e..814b3b4e655 100644 --- a/ui/app/serializers/job-version.js +++ b/ui/app/serializers/job-version.js @@ -13,6 +13,13 @@ export default class JobVersionSerializer extends ApplicationSerializer { number: 'Version', }; + normalize(typeHash, hash) { + if (hash.TaggedVersion) { + hash.TaggedVersion.VersionNumber = hash.Version; + } + return super.normalize(typeHash, hash); + } + normalizeFindHasManyResponse(store, modelClass, hash, id, requestType) { const zippedVersions = hash.Versions.map((version, index) => assign({}, version, { diff --git a/ui/app/serializers/version-tag.js b/ui/app/serializers/version-tag.js new file mode 100644 index 00000000000..b7c7c177d2a --- /dev/null +++ b/ui/app/serializers/version-tag.js @@ -0,0 +1,22 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +// @ts-check +import ApplicationSerializer from './application'; +import { inject as service } from '@ember/service'; + +export default class VersionTagSerializer extends ApplicationSerializer { + @service store; + + serialize(snapshot, options) { + const hash = super.serialize(snapshot, options); + hash.Version = hash.VersionNumber; // TODO: delete versionNumber and jobName? + return hash; + } + + // normalize(typeHash, hash) { + // return super.normalize(typeHash, hash); + // } +} diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index 66faef88775..02e01e2c7a3 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -38,23 +38,31 @@ {{/if}}