-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ui] "Clone and Edit" functionality for versions #24168
base: main
Are you sure you want to change the base?
Changes from all commits
5658869
3be63be
58e514a
1090dc3
97d3f8c
acd3294
ff5374e
3d532cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ui: Add an Edit From Version button as an option when reverting from an older job version | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,33 +5,67 @@ | |
|
||
// @ts-check | ||
import Route from '@ember/routing/route'; | ||
|
||
import { inject as service } from '@ember/service'; | ||
/** | ||
* Route for fetching and displaying a job's definition and specification. | ||
*/ | ||
export default class DefinitionRoute extends Route { | ||
@service notifications; | ||
|
||
queryParams = { | ||
version: { | ||
refreshModel: true, | ||
}, | ||
}; | ||
|
||
/** | ||
* Fetch the job's definition, specification, and variables from the API. | ||
* | ||
* @returns {Promise<Object>} A promise that resolves to an object containing the job, definition, format, | ||
* specification, variableFlags, and variableLiteral. | ||
*/ | ||
async model() { | ||
async model({ version }) { | ||
version = version ? +version : undefined; // query parameter is a string; convert to number | ||
/** @type {import('../../../models/job').default} */ | ||
const job = this.modelFor('jobs.job'); | ||
if (!job) return; | ||
|
||
const definition = await job.fetchRawDefinition(); | ||
let definition; | ||
|
||
if (version !== undefined) { | ||
// Not (!version) because version can be 0 | ||
try { | ||
const versionResponse = await job.getVersions(); | ||
const versions = versionResponse.Versions; | ||
definition = versions.findBy('Version', version); | ||
if (!definition) { | ||
throw new Error('Version not found'); | ||
} | ||
} catch (e) { | ||
console.error('error fetching job version definition', e); | ||
this.notifications.add({ | ||
title: 'Error Fetching Job Version Definition', | ||
message: `There was an error fetching the versions for this job: ${e.message}`, | ||
color: 'critical', | ||
}); | ||
} | ||
} else { | ||
definition = await job.fetchRawDefinition(); | ||
} | ||
|
||
console.log({ definition }); | ||
|
||
let format = 'json'; // default to json in network request errors | ||
let specification; | ||
let variableFlags; | ||
let variableLiteral; | ||
try { | ||
const specificationResponse = await job.fetchRawSpecification(); | ||
const specificationResponse = await job.fetchRawSpecification(version); | ||
specification = specificationResponse?.Source ?? null; | ||
variableFlags = specificationResponse?.VariableFlags ?? null; | ||
variableLiteral = specificationResponse?.Variables ?? null; | ||
format = specificationResponse?.Format ?? 'json'; | ||
console.log({ specification, variableFlags, variableLiteral, format }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More debugging? |
||
} catch (e) { | ||
// Swallow the error because Nomad job pre-1.6 will not have a specification | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,11 @@ | |
<Breadcrumb @crumb={{hash label="Run" args=(array "jobs.run")}} /> | ||
{{page-title "Run a job"}} | ||
<section class="section"> | ||
{{#if (and this.sourceString (not this.disregardNameWarning))}} | ||
<Hds::Alert @type="inline" @color="warning" data-test-job-name-warning as |A|> | ||
<A.Title>Don't forget to change the job name!</A.Title> | ||
<A.Description>Since you're cloning a job version's source as a new job, you'll want to change the job name. Otherwise, this will appear as a new version of the original job, rather than a new job.</A.Description> | ||
</Hds::Alert> | ||
{{/if}} | ||
Comment on lines
+9
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be nice to swap out the job name with an empty string to prevent accidental overwrites. Unfortunately we don't a JS parser for HCL2. My first pass at a regexp was something like |
||
<JobEditor @job={{this.model}} @context="new" @onSubmit={{action this.onSubmit}} @handleSaveAsTemplate={{this.handleSaveAsTemplate}} data-test-job-editor /> | ||
</section> | ||
</section> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debris from debugging, I think?