fix: handle case for async relationships
This commit is contained in:
parent
f7602d9a2a
commit
1188a5632f
|
@ -1,4 +1,4 @@
|
|||
<Trigger @do={{this.fetchParent}} as |trigger|>
|
||||
<Trigger @onError={{action this.onError}} @do={{this.fetchParent}} as |trigger|>
|
||||
{{did-insert trigger.fns.do}}
|
||||
{{#if trigger.data.isBusy}}
|
||||
<li>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in a new issue