open-nomad/ui/app/utils/generate-exec-url.js
Buck Doyle 588164ef44
Change exec URL-generation to use Ember get (#7963)
This fixes a bug in #7815 where you can’t open an exec window from
the allocation overview because accessing `allocation.job.plainId`
fails across the proxied relationship.
2020-05-14 14:09:09 -05:00

21 lines
802 B
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) {
return router.urlFor('exec', get(job, 'plainId'), { queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } });
} else {
return router.urlFor('exec', get(job, 'plainId'), { queryParams });
}
}