Skip to content

Commit

Permalink
fix: handle case for async relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaiWithJai committed Dec 13, 2021
1 parent e94a979 commit ab460da
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ui/app/components/breadcrumbs/job.hbs
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
6 changes: 6 additions & 0 deletions ui/app/components/breadcrumbs/job.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert } from '@ember/debug';
import { action } from '@ember/object';
import Component from '@glimmer/component';

Expand All @@ -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();
Expand Down
38 changes: 26 additions & 12 deletions ui/app/controllers/allocations/allocation.js
Original file line number Diff line number Diff line change
@@ -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],
},
];
}
Expand Down
10 changes: 9 additions & 1 deletion ui/app/routes/allocations/allocation.js
Original file line number Diff line number Diff line change
@@ -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));
Expand All @@ -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));
}

Expand Down
6 changes: 1 addition & 5 deletions ui/app/routes/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit ab460da

Please sign in to comment.