From 3619d530c7353bea311fdab6e81e10b702a137c9 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Thu, 4 Feb 2021 10:20:42 -0600 Subject: [PATCH] =?UTF-8?q?Change=20exec=20URLs=20to=20use=20job=E2=80=99s?= =?UTF-8?q?=20namespace/region?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This closes #9966. It was looking at the query parameters for the namespace and region, but allocation (and task!) routes don’t have a namespace query parameter. Since the URL generator requires the job for all calls, it makes sense to extract the namespace and region from the job instead. --- ui/app/utils/generate-exec-url.js | 13 ++++++++++++- ui/tests/unit/utils/generate-exec-url-test.js | 15 ++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ui/app/utils/generate-exec-url.js b/ui/app/utils/generate-exec-url.js index f4740d15d881..a5b5d0fb723b 100644 --- a/ui/app/utils/generate-exec-url.js +++ b/ui/app/utils/generate-exec-url.js @@ -1,7 +1,18 @@ import { get } from '@ember/object'; export default function generateExecUrl(router, { job, taskGroup, task, allocation }) { - const queryParams = router.currentRoute.queryParams; + const queryParams = {}; + + const namespace = get(job, 'namespace.name'); + const region = get(job, 'region'); + + if (namespace) { + queryParams.namespace = namespace; + } + + if (region) { + queryParams.region = region; + } if (task) { const queryParamsOptions = { diff --git a/ui/tests/unit/utils/generate-exec-url-test.js b/ui/tests/unit/utils/generate-exec-url-test.js index 6be39412ddd9..b2897cc4e8d1 100644 --- a/ui/tests/unit/utils/generate-exec-url-test.js +++ b/ui/tests/unit/utils/generate-exec-url-test.js @@ -96,14 +96,15 @@ module('Unit | Utility | generate-exec-url', function(hooks) { ); }); - test('it includes query parameters from the current route', function(assert) { - this.router.currentRoute.queryParams = { - namespace: 'a-namespace', - region: 'a-region', - }; - + test('it includes job namespace and region when they exist', function(assert) { generateExecUrl(this.router, { - job: { plainId: 'job-name' }, + job: { + namespace: { + name: 'a-namespace', + }, + plainId: 'job-name', + region: 'a-region', + }, allocation: { shortId: 'id', taskGroup: { name: 'task-group-name', tasks: [0, 1] } }, });