From ab460daec89524c2d718d62d795f6407145e465c Mon Sep 17 00:00:00 2001 From: Jai Bhagat Date: Mon, 13 Dec 2021 10:29:25 -0500 Subject: [PATCH] fix: handle case for async relationships --- ui/app/components/breadcrumbs/job.hbs | 2 +- ui/app/components/breadcrumbs/job.js | 6 ++++ ui/app/controllers/allocations/allocation.js | 38 +++++++++++++------- ui/app/routes/allocations/allocation.js | 10 +++++- ui/app/routes/jobs/job.js | 6 +--- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/ui/app/components/breadcrumbs/job.hbs b/ui/app/components/breadcrumbs/job.hbs index b702cf5f661..09ae5d420f1 100644 --- a/ui/app/components/breadcrumbs/job.hbs +++ b/ui/app/components/breadcrumbs/job.hbs @@ -1,4 +1,4 @@ - + {{did-insert trigger.fns.do}} {{#if trigger.data.isBusy}}
  • diff --git a/ui/app/components/breadcrumbs/job.js b/ui/app/components/breadcrumbs/job.js index b4286a847ba..da688a0e977 100644 --- a/ui/app/components/breadcrumbs/job.js +++ b/ui/app/components/breadcrumbs/job.js @@ -1,3 +1,4 @@ +import { assert } from '@ember/debug'; import { action } from '@ember/object'; import Component from '@glimmer/component'; @@ -6,6 +7,11 @@ export default class BreadcrumbsJob extends Component { return this.args.crumb.job; } + @action + onError(err) { + assert(`Error: ${err.message}`); + } + @action fetchParent() { const hasParent = !!this.job.belongsTo('parent').id(); diff --git a/ui/app/controllers/allocations/allocation.js b/ui/app/controllers/allocations/allocation.js index 2491bfd290c..d2c2aee4034 100644 --- a/ui/app/controllers/allocations/allocation.js +++ b/ui/app/controllers/allocations/allocation.js @@ -1,30 +1,44 @@ import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; import { qpBuilder } from 'nomad-ui/utils/classes/query-params'; export default class AllocationsAllocationController extends Controller { + @service store; + + get allocation() { + return this.model; + } + + get job() { + const allocation = this.model; + const jobId = allocation.belongsTo('job').id(); + const job = this.store.peekRecord('job', jobId); + return job; + } + + get jobNamespace() { + const jobNamespaceId = this.job.belongsTo('namespace').id(); + + return jobNamespaceId || 'default'; + } // Allocation breadcrumbs extend from job / task group breadcrumbs // even though the route structure does not. get breadcrumbs() { - const model = this.model; + const { allocation, job, jobNamespace } = this; const jobQueryParams = qpBuilder({ - jobNamespace: model.get('job.namespace.name') || 'default', + jobNamespace, }); return [ { label: 'Jobs', args: ['jobs.index', jobQueryParams] }, - { type: 'job', job: model.get('job') }, + { type: 'job', job: job }, { - label: model.get('taskGroupName'), - args: [ - 'jobs.job.task-group', - model.get('job.plainId'), - model.get('taskGroupName'), - jobQueryParams, - ], + label: allocation.taskGroupName, + args: ['jobs.job.task-group', job.plainId, allocation.taskGroupName, jobQueryParams], }, { - label: model.get('shortId'), - args: ['allocations.allocation', model], + label: allocation.shortId, + args: ['allocations.allocation', allocation], }, ]; } diff --git a/ui/app/routes/allocations/allocation.js b/ui/app/routes/allocations/allocation.js index 917d3edae00..a8a7b0962b1 100644 --- a/ui/app/routes/allocations/allocation.js +++ b/ui/app/routes/allocations/allocation.js @@ -1,9 +1,12 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; import { collect } from '@ember/object/computed'; import { watchRecord } from 'nomad-ui/utils/properties/watch'; import WithWatchers from 'nomad-ui/mixins/with-watchers'; import notifyError from 'nomad-ui/utils/notify-error'; export default class AllocationRoute extends Route.extend(WithWatchers) { + @service store; + startWatchers(controller, model) { if (model) { controller.set('watcher', this.watch.perform(model)); @@ -14,7 +17,12 @@ export default class AllocationRoute extends Route.extend(WithWatchers) { // Preload the job for the allocation since it's required for the breadcrumb trail return super .model(...arguments) - .then(allocation => allocation.get('job').then(() => allocation)) + .then(allocation => + allocation + .get('job') + .then(() => this.store.findAll('namespace')) + .then(() => allocation) + ) .catch(notifyError(this)); } diff --git a/ui/app/routes/jobs/job.js b/ui/app/routes/jobs/job.js index b665f4e2b2d..971d5be805c 100644 --- a/ui/app/routes/jobs/job.js +++ b/ui/app/routes/jobs/job.js @@ -18,11 +18,7 @@ export default class JobRoute extends Route { const namespace = transition.to.queryParams.namespace || 'default'; const name = params.job_name; const fullId = JSON.stringify([name, namespace]); - console.log( - this.store - .findRecord('job', fullId, { reload: true }) - .then(job => console.log('model\n\n', job)) - ); + return this.store .findRecord('job', fullId, { reload: true }) .then(job => {