From 67fd9ffee1d48c45d949d2e41696f75dcbcf0dff Mon Sep 17 00:00:00 2001 From: Jai <41024828+ChaiWithJai@users.noreply.github.com> Date: Thu, 20 Oct 2022 14:25:41 -0400 Subject: [PATCH] refact: upgrade Promise.then to async/await (#14798) * refact: upgrade Promise.then to async/await * naive solution (#14800) * refact: use id instead of model * chore: add changelog entry * refact: add conditional safety around alloc --- .changelog/14798.txt | 3 +++ ui/app/routes/allocations/allocation.js | 24 +++++++++---------- .../templates/components/allocation-row.hbs | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 .changelog/14798.txt diff --git a/.changelog/14798.txt b/.changelog/14798.txt new file mode 100644 index 000000000..5a64b1ad6 --- /dev/null +++ b/.changelog/14798.txt @@ -0,0 +1,3 @@ +```release-note:bug-fix +ui: always show ports on allocations page +``` diff --git a/ui/app/routes/allocations/allocation.js b/ui/app/routes/allocations/allocation.js index eb5d80200..186a26ccc 100644 --- a/ui/app/routes/allocations/allocation.js +++ b/ui/app/routes/allocations/allocation.js @@ -36,18 +36,18 @@ export default class AllocationRoute extends Route.extend(WithWatchers) { } } - model() { - // Preload the job for the allocation since it's required for the breadcrumb trail - return super - .model(...arguments) - .then((allocation) => { - const jobId = allocation.belongsTo('job').id(); - return this.store - .findRecord('job', jobId) - .then(() => this.store.findAll('namespace')) // namespaces belong to a job and are an asynchronous relationship so we can peak them later on - .then(() => allocation); - }) - .catch(notifyError(this)); + async model() { + try { + // Preload the job for the allocation since it's required for the breadcrumb trail + const allocation = await super.model(...arguments); + const jobId = allocation?.belongsTo('job').id(); + const getJob = this.store.findRecord('job', jobId); + const getNamespaces = this.store.findAll('namespace'); + await Promise.all([getJob, getNamespaces]); + return allocation; + } catch { + notifyError(this); + } } @watchRecord('allocation') watch; diff --git a/ui/app/templates/components/allocation-row.hbs b/ui/app/templates/components/allocation-row.hbs index a6df15060..7cc380fc1 100644 --- a/ui/app/templates/components/allocation-row.hbs +++ b/ui/app/templates/components/allocation-row.hbs @@ -33,7 +33,7 @@ {{this.allocation.shortId}}