import Component from '@ember/component'; import { get, set, computed } from '@ember/object'; import ComputedProperty from '@ember/object/computed'; import { IAvatar } from 'wherehows-web/typings/app/avatars'; import { IOwner, IOwnerResponse } from 'wherehows-web/typings/api/datasets/owners'; import { task } from 'ember-concurrency'; import { readDatasetOwnersByUrn } from 'wherehows-web/utils/api/datasets/owners'; import { arrayMap } from 'wherehows-web/utils/array'; import { getAvatarProps } from 'wherehows-web/constants/avatars/avatars'; import { confirmedOwners } from 'wherehows-web/constants/datasets/owner'; export default class DatasetOwnerListContainer extends Component { constructor() { super(...arguments); this.owners || (this.owners = []); } /** * Urn for the related dataset * @type {string} * @memberof DatasetOwnerListContainer */ urn: string; /** * The owners for the dataset * @type {Array} * @memberof DatasetOwnerListContainer */ owners: Array; /** * Lists the avatar objects based off the dataset owners * @type {ComputedProperty>} * @memberof DatasetOwnerListContainer */ avatars: ComputedProperty> = computed('owners', function(): Array { return arrayMap(getAvatarProps)(get(this, 'owners')); }); didInsertElement() { get(this, 'getOwnersTask').perform(); } didUpdateAttrs() { get(this, 'getOwnersTask').perform(); } /** * Reads the owners for this dataset * @type {Task>, () => TaskInstance>>} */ getOwnersTask = task(function*(this: DatasetOwnerListContainer): IterableIterator> { const { owners = [] }: IOwnerResponse = yield readDatasetOwnersByUrn(get(this, 'urn')); set(this, 'owners', confirmedOwners(owners)); }).restartable(); }