From f50aff562cf2a566273dcbe9c18b47165f00c0ef Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 20 Jul 2018 14:29:51 -0700 Subject: [PATCH] Treat filtering on an async relationship as async --- .../components/job-page/parts/recent-allocations.js | 13 +++++++++---- ui/app/utils/classes/promise-array.js | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 ui/app/utils/classes/promise-array.js diff --git a/ui/app/components/job-page/parts/recent-allocations.js b/ui/app/components/job-page/parts/recent-allocations.js index d7d2ce0a2..c50ff7f02 100644 --- a/ui/app/components/job-page/parts/recent-allocations.js +++ b/ui/app/components/job-page/parts/recent-allocations.js @@ -1,14 +1,19 @@ import Component from '@ember/component'; import { computed } from '@ember/object'; +import PromiseArray from 'nomad-ui/utils/classes/promise-array'; export default Component.extend({ sortProperty: 'modifyIndex', sortDescending: true, sortedAllocations: computed('job.allocations.@each.modifyIndex', function() { - return this.get('job.allocations') - .sortBy('modifyIndex') - .reverse() - .slice(0, 5); + return new PromiseArray({ + promise: this.get('job.allocations').then(allocations => + allocations + .sortBy('modifyIndex') + .reverse() + .slice(0, 5) + ), + }); }), actions: { diff --git a/ui/app/utils/classes/promise-array.js b/ui/app/utils/classes/promise-array.js new file mode 100644 index 000000000..0fd302aec --- /dev/null +++ b/ui/app/utils/classes/promise-array.js @@ -0,0 +1,4 @@ +import ArrayProxy from '@ember/array/proxy'; +import PromiseProxyMixin from '@ember/object/promise-proxy-mixin'; + +export default ArrayProxy.extend(PromiseProxyMixin);