open-nomad/ui/app/utils/generate-exec-url.js
Buck Doyle 7f0177548d
Add specificity to exec allocation URL generation (#8463)
Thanks to @notnoop for this UX improvement suggestion.
The allocation’s task group is always known, so it
might as well be preselected in the sidebar when the
exec window opens. Also, if the task group only has
one task, might as well preselect it too.
2020-07-20 16:07:39 -05:00

44 lines
1.3 KiB
JavaScript

import { get } from '@ember/object';
export default function generateExecUrl(router, { job, taskGroup, task, allocation }) {
const queryParams = router.currentRoute.queryParams;
if (task) {
return router.urlFor(
'exec.task-group.task',
get(job, 'plainId'),
get(taskGroup, 'name'),
get(task, 'name'),
{
queryParams: {
allocation: get(allocation, 'shortId'),
...queryParams,
},
}
);
} else if (taskGroup) {
return router.urlFor('exec.task-group', get(job, 'plainId'), get(taskGroup, 'name'), {
queryParams,
});
} else if (allocation) {
if (get(allocation, 'taskGroup.tasks.length') === 1) {
return router.urlFor(
'exec.task-group.task',
get(job, 'plainId'),
get(allocation, 'taskGroup.name'),
get(allocation, 'taskGroup.tasks.firstObject.name'),
{ queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
);
} else {
return router.urlFor(
'exec.task-group',
get(job, 'plainId'),
get(allocation, 'taskGroup.name'),
{ queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
);
}
} else {
return router.urlFor('exec', get(job, 'plainId'), { queryParams });
}
}