Skip to content
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] Title bar job start button now observes job submission variables data #19220

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19220.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: fix an issue where starting a stopped job with default-less variables would not retain those variables when done via the job page start button in the web ui
```
23 changes: 2 additions & 21 deletions ui/app/components/job-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { task } from 'ember-concurrency';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
import localStorageProperty from 'nomad-ui/utils/properties/local-storage';
import { tracked } from '@glimmer/tracking';
import jsonToHcl from 'nomad-ui/utils/json-to-hcl';

/**
* JobEditor component that provides an interface for editing and managing Nomad jobs.
Expand Down Expand Up @@ -39,9 +40,7 @@ export default class JobEditor extends Component {
if (this.args.variables) {
this.args.job.set(
'_newDefinitionVariables',
this.jsonToHcl(this.args.variables.flags).concat(
this.args.variables.literal
)
jsonToHcl(this.args.variables.flags).concat(this.args.variables.literal)
);
}
}
Expand Down Expand Up @@ -258,24 +257,6 @@ export default class JobEditor extends Component {
}
}

/**
* Convert a JSON object to an HCL string.
*
* @param {Object} obj - The JSON object to convert.
* @returns {string} The HCL string representation of the JSON object.
*/
jsonToHcl(obj) {
const hclLines = [];

for (const key in obj) {
const value = obj[key];
const hclValue = typeof value === 'string' ? `"${value}"` : value;
hclLines.push(`${key}=${hclValue}\n`);
}

return hclLines.join('\n');
}

get data() {
return {
cancelable: this.args.cancelable,
Expand Down
11 changes: 11 additions & 0 deletions ui/app/components/job-page/parts/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { inject as service } from '@ember/service';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
import jsonToHcl from 'nomad-ui/utils/json-to-hcl';

@classic
@tagName('')
Expand Down Expand Up @@ -76,6 +77,16 @@ export default class Title extends Component {
// In the event that this fails, fall back to the raw definition.
try {
const specification = yield job.fetchRawSpecification();

let _newDefinitionVariables = job.get('_newDefinitionVariables') || '';
if (specification.VariableFlags) {
_newDefinitionVariables += jsonToHcl(specification.VariableFlags);
}
if (specification.Variables) {
_newDefinitionVariables += specification.Variables;
}
job.set('_newDefinitionVariables', _newDefinitionVariables);

job.set('_newDefinition', specification.Source);
} catch {
const definition = yield job.fetchRawDefinition();
Expand Down
24 changes: 24 additions & 0 deletions ui/app/utils/json-to-hcl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

// @ts-check

/**
* Convert a JSON object to an HCL string.
*
* @param {Object} obj - The JSON object to convert.
* @returns {string} The HCL string representation of the JSON object.
*/
export default function jsonToHcl(obj) {
const hclLines = [];

for (const key in obj) {
const value = obj[key];
const hclValue = typeof value === 'string' ? `"${value}"` : value;
hclLines.push(`${key}=${hclValue}\n`);
}

return hclLines.join('\n');
}
Loading