diff --git a/.changelog/13588.txt b/.changelog/13588.txt new file mode 100644 index 000000000000..7f694e295768 --- /dev/null +++ b/.changelog/13588.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fixed an issue where editing or running a job with a namespace via the UI would throw a 404 on redirect. +``` diff --git a/ui/app/controllers/jobs/job/definition.js b/ui/app/controllers/jobs/job/definition.js index a428f941b924..2a0616a3be6e 100644 --- a/ui/app/controllers/jobs/job/definition.js +++ b/ui/app/controllers/jobs/job/definition.js @@ -2,6 +2,7 @@ import Controller from '@ember/controller'; import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting'; import { alias } from '@ember/object/computed'; import classic from 'ember-classic-decorator'; +import { inject as service } from '@ember/service'; @classic export default class DefinitionController extends Controller.extend( @@ -9,6 +10,7 @@ export default class DefinitionController extends Controller.extend( ) { @alias('model.job') job; @alias('model.definition') definition; + @service router; isEditing = false; @@ -21,9 +23,7 @@ export default class DefinitionController extends Controller.extend( this.set('isEditing', false); } - onSubmit(id, jobNamespace) { - this.transitionToRoute('jobs.job', id, { - queryParams: { jobNamespace }, - }); + onSubmit() { + this.router.transitionTo('jobs.job', this.job.idWithNamespace); } } diff --git a/ui/app/controllers/jobs/run.js b/ui/app/controllers/jobs/run.js index 5921713017c6..bc2dcb9807df 100644 --- a/ui/app/controllers/jobs/run.js +++ b/ui/app/controllers/jobs/run.js @@ -1,9 +1,9 @@ import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; export default class RunController extends Controller { + @service router; onSubmit(id, namespace) { - this.transitionToRoute('jobs.job', id, { - queryParams: { namespace }, - }); + this.router.transitionTo('jobs.job', `${id}@${namespace || 'default'}`); } } diff --git a/ui/tests/acceptance/job-definition-test.js b/ui/tests/acceptance/job-definition-test.js index c8948645fcf7..ab21d838d03f 100644 --- a/ui/tests/acceptance/job-definition-test.js +++ b/ui/tests/acceptance/job-definition-test.js @@ -95,7 +95,7 @@ module('Acceptance | job definition', function (hooks) { await Definition.editor.run(); assert.equal( currentURL(), - `/jobs/${job.id}`, + `/jobs/${job.id}@default`, 'Now on the job overview page' ); }); diff --git a/ui/tests/acceptance/job-run-test.js b/ui/tests/acceptance/job-run-test.js index 619ae0da79c4..df0b1ae190c3 100644 --- a/ui/tests/acceptance/job-run-test.js +++ b/ui/tests/acceptance/job-run-test.js @@ -9,6 +9,7 @@ import JobRun from 'nomad-ui/tests/pages/jobs/run'; const newJobName = 'new-job'; const newJobTaskGroupName = 'redis'; +const newJobNamespace = 'default'; let managementToken, clientToken; @@ -18,7 +19,7 @@ const jsonJob = (overrides) => { {}, { Name: newJobName, - Namespace: 'default', + Namespace: newJobNamespace, Datacenters: ['dc1'], Priority: 50, TaskGroups: [ @@ -79,7 +80,7 @@ module('Acceptance | job run', function (hooks) { await JobRun.editor.run(); assert.equal( currentURL(), - `/jobs/${newJobName}`, + `/jobs/${newJobName}@${newJobNamespace}`, `Redirected to the job overview page for ${newJobName}` ); }); @@ -97,7 +98,7 @@ module('Acceptance | job run', function (hooks) { await JobRun.editor.run(); assert.equal( currentURL(), - `/jobs/${newJobName}?namespace=${newNamespace}`, + `/jobs/${newJobName}@${newNamespace}`, `Redirected to the job overview page for ${newJobName} and switched the namespace to ${newNamespace}` ); });