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

Backport of ui: fix navigation for namespaced jobs in search and job version into release/1.4.x #15911

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/15906.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix navigation to pages for jobs that are not in the default namespace
```
15 changes: 11 additions & 4 deletions ui/app/components/global-search/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const MAXIMUM_RESULTS = 10;
export default class GlobalSearchControl extends Component {
@service router;
@service token;
@service store;

searchString = null;

Expand Down Expand Up @@ -180,14 +181,20 @@ export default class GlobalSearchControl extends Component {
@action
selectOption(model) {
if (model.type === 'job') {
this.router.transitionTo('jobs.job', model.id, {
queryParams: { namespace: model.namespace },
const fullId = JSON.stringify([model.id, model.namespace]);
this.store.findRecord('job', fullId).then((job) => {
this.router.transitionTo('jobs.job', job.idWithNamespace);
});
} else if (model.type === 'node') {
this.router.transitionTo('clients.client', model.id);
} else if (model.type === 'task-group') {
this.router.transitionTo('jobs.job.task-group', model.jobId, model.id, {
queryParams: { namespace: model.namespace },
const fullJobId = JSON.stringify([model.jobId, model.namespace]);
this.store.findRecord('job', fullJobId).then((job) => {
this.router.transitionTo(
'jobs.job.task-group',
job.idWithNamespace,
model.id
);
});
} else if (model.type === 'plugin') {
this.router.transitionTo('csi.plugins.plugin', model.id);
Expand Down
16 changes: 0 additions & 16 deletions ui/app/components/gutter-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,4 @@ export default class GutterMenu extends Component {
transitionTo(destination) {
return this.router.transitionTo(destination);
}

gotoJobsForNamespace(namespace) {
if (!namespace || !namespace.get('id')) return;

// Jobs and CSI Volumes are both namespace-sensitive. Changing namespaces is
// an intent to reset context, but where to reset to depends on where the namespace
// is being switched from. Jobs take precedence, but if the namespace is switched from
// a storage-related page, context should be reset to volumes.
const destination = this.router.currentRouteName.startsWith('csi.')
? 'csi.volumes'
: 'jobs';

this.router.transitionTo(destination, {
queryParams: { namespace: namespace.get('id') },
});
}
}
5 changes: 1 addition & 4 deletions ui/app/components/job-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ export default class JobVersion extends Component {
});
} else {
const job = this.get('version.job');

this.router.transitionTo('jobs.job', job.get('plainId'), {
queryParams: { namespace: job.get('namespace.name') },
});
this.router.transitionTo('jobs.job.index', job.get('idWithNamespace'));
}
} catch (e) {
this.handleError({
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/job-versions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module('Acceptance | job versions', function (hooks) {
JobVersion: versionNumberRevertingTo,
});

assert.equal(currentURL(), `/jobs/${job.id}?namespace=${namespace.id}`);
assert.equal(currentURL(), `/jobs/${job.id}@${namespace.id}`);
}
});

Expand Down
32 changes: 28 additions & 4 deletions ui/tests/acceptance/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module('Acceptance | search', function (hooks) {
server.create('node', { name: 'xyz' });
const otherNode = server.create('node', { name: 'ghi' });

server.create('namespace');
server.create('namespace', { id: 'dev' });

server.create('job', {
id: 'vwxyz',
namespaceId: 'default',
Expand All @@ -30,6 +33,13 @@ module('Acceptance | search', function (hooks) {
groupsCount: 1,
groupTaskCount: 1,
});
server.create('job', {
id: 'xyzw',
name: 'xyzw job',
namespaceId: 'dev',
groupsCount: 1,
groupTaskCount: 1,
});
server.create('job', {
id: 'abc',
namespaceId: 'default',
Expand All @@ -39,6 +49,7 @@ module('Acceptance | search', function (hooks) {

const firstAllocation = server.schema.allocations.all().models[0];
const firstTaskGroup = server.schema.taskGroups.all().models[0];
const namespacedTaskGroup = server.schema.taskGroups.all().models[2];

server.create('csi-plugin', { id: 'xyz-plugin', createVolumes: false });

Expand All @@ -50,10 +61,11 @@ module('Acceptance | search', function (hooks) {
assert.equal(search.groups.length, 5);

search.groups[0].as((jobs) => {
assert.equal(jobs.name, 'Jobs (2)');
assert.equal(jobs.options.length, 2);
assert.equal(jobs.name, 'Jobs (3)');
assert.equal(jobs.options.length, 3);
assert.equal(jobs.options[0].text, 'default > vwxyz');
assert.equal(jobs.options[1].text, 'default > xyz job');
assert.equal(jobs.options[2].text, 'dev > xyzw job');
});

search.groups[1].as((clients) => {
Expand All @@ -80,7 +92,11 @@ module('Acceptance | search', function (hooks) {
});

await Layout.navbar.search.groups[0].options[1].click();
assert.equal(currentURL(), '/jobs/xyz');
assert.equal(currentURL(), '/jobs/xyz@default');

await selectSearch(Layout.navbar.search.scope, 'xy');
await Layout.navbar.search.groups[0].options[2].click();
assert.equal(currentURL(), '/jobs/xyzw@dev');

await selectSearch(Layout.navbar.search.scope, otherNode.name);
await Layout.navbar.search.groups[1].options[0].click();
Expand All @@ -100,7 +116,15 @@ module('Acceptance | search', function (hooks) {
`default > vwxyz > ${firstTaskGroup.name}`
);
await Layout.navbar.search.groups[3].options[0].click();
assert.equal(currentURL(), `/jobs/vwxyz/${firstTaskGroup.name}`);
assert.equal(currentURL(), `/jobs/vwxyz@default/${firstTaskGroup.name}`);

await selectSearch(Layout.navbar.search.scope, namespacedTaskGroup.name);
assert.equal(
Layout.navbar.search.groups[3].options[0].text,
`dev > xyzw > ${namespacedTaskGroup.name}`
);
await Layout.navbar.search.groups[3].options[0].click();
assert.equal(currentURL(), `/jobs/xyzw@dev/${namespacedTaskGroup.name}`);

await selectSearch(Layout.navbar.search.scope, 'xy');
await Layout.navbar.search.groups[4].options[0].click();
Expand Down