Skip to content

Commit

Permalink
Reworked as Clone and Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Oct 21, 2024
1 parent a79a6f2 commit a5d6f63
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 31 deletions.
27 changes: 25 additions & 2 deletions ui/app/components/job-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class JobVersion extends Component {
/**
* @type {'idle' | 'confirming'}
*/
@tracked revertButtonStatus = 'idle';
@tracked cloneButtonStatus = 'idle';

@task(function* () {
try {
Expand All @@ -95,6 +95,7 @@ export default class JobVersion extends Component {

const versionAfterReversion = this.version.get('job.version');
if (versionBeforeReversion === versionAfterReversion) {
// TODO: I don't think this is ever hit, we have template checks against it.
this.args.handleError({
level: 'warn',
title: 'Reversion Had No Effect',
Expand All @@ -115,7 +116,7 @@ export default class JobVersion extends Component {
})
revertTo;

@action async editFromVersion() {
@action async cloneAsNewVersion() {
try {
this.router.transitionTo(
'jobs.job.definition',
Expand All @@ -135,6 +136,28 @@ export default class JobVersion extends Component {
}
}

@action async cloneAsNewJob() {
console.log('cloneAsNewJob');
try {
// TODO: copy the job definition over there.
console.log('Do I have submission info???', this.version);
let job = await this.version.get('job');
let specification = await job.fetchRawSpecification(this.version.number);
console.log('Do I have specification???', specification);
let specificationSourceString = specification.Source; // TODO: should do some Format checking here, at the very least.
this.router.transitionTo('jobs.run', {
queryParams: {
sourceString: specificationSourceString,
},
});
} catch (e) {
this.args.handleError({
level: 'danger',
title: 'Could Not Clone as New Job',
});
}
}

@action
handleKeydown(event) {
if (event.key === 'Escape') {
Expand Down
1 change: 1 addition & 0 deletions ui/app/routes/jobs/job/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class DefinitionRoute extends Route {
*/
async model({ version }) {
version = +version; // query parameter is a string; convert to number
/** @type {import('../../../models/job').default} */
const job = this.modelFor('jobs.job');
if (!job) return;

Expand Down
11 changes: 10 additions & 1 deletion ui/app/routes/jobs/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export default class JobsRunIndexRoute extends Route {
template: {
refreshModel: true,
},
sourceString: {
refreshModel: true,
},
};

beforeModel(transition) {
Expand All @@ -33,7 +36,7 @@ export default class JobsRunIndexRoute extends Route {
}
}

async model({ template }) {
async model({ template, sourceString }) {
try {
// When jobs are created with a namespace attribute, it is verified against
// available namespaces to prevent redirecting to a non-existent namespace.
Expand All @@ -45,6 +48,12 @@ export default class JobsRunIndexRoute extends Route {
return this.store.createRecord('job', {
_newDefinition: templateRecord.items.template,
});
} else if (sourceString) {
console.log('elsif', sourceString);
// Add an alert to the page to let the user know that they are submitting a job from a template, and that they should change the name!
return this.store.createRecord('job', {
_newDefinition: sourceString,
});
} else {
return this.store.createRecord('job');
}
Expand Down
63 changes: 35 additions & 28 deletions ui/app/templates/components/job-version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,53 +81,60 @@
<div class="version-options">
{{#unless this.isCurrent}}
{{#if (can "run job" namespace=this.version.job.namespace)}}
{{#if (eq this.revertButtonStatus 'idle')}}
{{#if (eq this.cloneButtonStatus 'idle')}}
<Hds::Button
data-test-revert-to
@text="Revert Version"
@color="critical"
data-test-clone-and-edit
@text="Clone and Edit"
@color="secondary"
@size="small"
@isInline={{true}}
@disabled={{this.revertTo.isRunning}}
{{on "click" (action (mut this.revertButtonStatus) "confirming")}}
{{!-- @disabled={{this.revertTo.isRunning}} --}}
{{on "click" (action (mut this.cloneButtonStatus) "confirming")}}
/>
{{else if (eq this.revertButtonStatus 'confirming')}}
<span data-test-confirmation-message class="confirmation-text is-right-aligned has-text-inline">

<TwoStepButton
data-test-revert-to
@classes={{hash
idleButton="is-warning is-outlined"
confirmButton="is-warning"}}
@fadingBackground={{true}}
@idleText="Revert Version"
@cancelText="Cancel"
@confirmText="Yes, Revert Version"
@confirmationMessage="Are you sure you want to revert to this version?"
@inlineText={{true}}
@size="small"
@awaitingConfirmation={{this.revertTo.isRunning}}
@onConfirm={{perform this.revertTo}} />


{{else if (eq this.cloneButtonStatus 'confirming')}}
{{!-- <span data-test-confirmation-message class="confirmation-text is-right-aligned has-text-inline">
Are you sure you want to revert to this version?
</span>
</span> --}}
<Hds::Button
data-test-revert-to
data-test-cancel-clone
@text="Cancel"
@color="secondary"
@size="small"
@isInline={{true}}
{{on "click" (action (mut this.revertButtonStatus) "idle")}}
{{on "click" (action (mut this.cloneButtonStatus) "idle")}}
/>
<Hds::Button
data-test-revert-to
@text="Edit from Version"
data-test-clone-as-new-version
@text="Clone as New Version of {{this.version.job.name}}"
@color="secondary"
@size="small"
@isInline={{true}}
{{on "click" (action this.editFromVersion)}}
{{on "click" (action this.cloneAsNewVersion)}}
/>
<Hds::Button
data-test-revert-to
@text="Yes, Revert Now"
@color="critical"
@size="small"
@isInline={{true}}
@disabled={{this.revertTo.isRunning}}
{{on "click" (perform this.revertTo)}}
/>
{{else if (eq this.revertButtonStatus 'running')}}
<Hds::Button
data-test-revert-to
@text="Reverting..."
@color="critical"
data-test-clone-as-new-job
@text="Clone as New Job"
@color="secondary"
@size="small"
@isInline={{true}}
@disabled={{true}}
{{on "click" (action this.cloneAsNewJob)}}
/>
{{/if}}
{{else}}
Expand Down

0 comments on commit a5d6f63

Please sign in to comment.