retain owner object referential integrity when augmenting with avatars. fix failing suggested owners and dataset author tests

This commit is contained in:
Seyi Adebajo 2018-09-13 23:07:47 -07:00
parent f153186095
commit 71f32d80d1
8 changed files with 118 additions and 110 deletions

View File

@ -6,6 +6,7 @@ import { assert } from '@ember/debug';
import { IOwner } from 'wherehows-web/typings/api/datasets/owners';
import { OwnerSource, OwnerType } from 'wherehows-web/utils/api/datasets/owners';
import { action } from '@ember-decorators/object';
import { OwnerWithAvatarRecord } from 'wherehows-web/typings/app/datasets/owners';
/**
* This component renders a single owner record and also provides functionality for interacting with the component
@ -26,10 +27,10 @@ export default class DatasetAuthor extends Component {
/**
* The owner record being rendered
* @type {IOwner}
* @type {OwnerWithAvatarRecord}
* @memberof DatasetAuthor
*/
owner: IOwner;
owner: OwnerWithAvatarRecord;
/**
* List of suggested owners that have been confirmed by a user
@ -73,14 +74,14 @@ export default class DatasetAuthor extends Component {
* @type {ComputedProperty<boolean>}
* @memberof DatasetAuthor
*/
isOwnerMutable: ComputedProperty<boolean> = equal('owner.source', OwnerSource.Ui);
isOwnerMutable: ComputedProperty<boolean> = equal('owner.owner.source', OwnerSource.Ui);
/**
* Negates the owner attribute flag `isActive`, indicating owner record is considered inactive
* @type {ComputedProperty<boolean>}
* @memberOf DatasetAuthor
*/
isOwnerInActive: ComputedProperty<boolean> = not('owner.isActive');
isOwnerInActive: ComputedProperty<boolean> = not('owner.owner.isActive');
/**
* Determines if the owner record is a system suggested owner and if this record is confirmed by a user
@ -93,7 +94,9 @@ export default class DatasetAuthor extends Component {
const {
commonOwners,
isOwnerMutable,
owner: { userName }
owner: {
owner: { userName }
}
} = getProperties(this, ['commonOwners', 'isOwnerMutable', 'owner']);
return isOwnerMutable ? false : !!commonOwners.findBy('userName', userName);
@ -123,7 +126,7 @@ export default class DatasetAuthor extends Component {
@action
onRemoveOwner(): boolean | void | IOwner {
const { owner, isOwnerMutable, removeOwner } = getProperties(this, ['owner', 'isOwnerMutable', 'removeOwner']);
return isOwnerMutable && removeOwner(owner);
return isOwnerMutable && removeOwner(owner.owner);
}
/**
@ -133,7 +136,7 @@ export default class DatasetAuthor extends Component {
@action
confirmOwner(): Array<IOwner> | void {
const { owner, confirmSuggestedOwner } = getProperties(this, ['owner', 'confirmSuggestedOwner']);
return confirmSuggestedOwner(owner);
return confirmSuggestedOwner(owner.owner);
}
/**
@ -149,6 +152,6 @@ export default class DatasetAuthor extends Component {
'updateOwnerType'
]);
return isOwnerMutable && updateOwnerType(owner, type);
return isOwnerMutable && updateOwnerType(owner.owner, type);
}
}

View File

@ -175,7 +175,7 @@ export default class DatasetAuthors extends Component {
const { avatarProperties } = this;
return {
...owner,
owner,
avatar: avatarProperties
? getAvatarProps(avatarProperties)({ userName: owner.userName })
: { imageUrl: '', imageUrlFallback: '/assets/assets/images/default_avatar.png' }
@ -266,8 +266,10 @@ export default class DatasetAuthors extends Component {
*/
@action
addOwner(this: DatasetAuthors, newOwner: IOwner): Array<IOwner> | void {
const owners = get(this, 'owners') || [];
const { notify } = get(this, 'notifications');
const {
owners = [],
notifications: { notify }
} = this;
if (ownerAlreadyExists(owners, { userName: newOwner.userName, source: newOwner.source })) {
return void notify(NotificationEvent.info, { content: 'Owner has already been added to "confirmed" list' });

View File

@ -1,75 +1,76 @@
<td>
{{#unless isOwnerInActive}}
{{avatars/avatar-image avatar=@owner.avatar}}
{{/unless}}
{{@owner.userName}}
{{#if isOwnerInActive}}
<span class="nacho-button nacho-button--small dataset-author-record__indicator--inactive">
Inactive
</span>
{{/if}}
</td>
<td>
{{@owner.name}}
</td>
<td>
{{@owner.idType}}
</td>
{{!-- hides source column for confirmed owners--}}
{{#unless isOwnerMutable}}
{{#let @owner.owner as |ownerRecord|}}
<td>
{{@owner.source}}
{{#unless isOwnerInActive}}
{{avatars/avatar-image avatar=@owner.avatar}}
{{/unless}}
{{ownerRecord.userName}}
{{#if isOwnerInActive}}
<span class="nacho-button nacho-button--small dataset-author-record__indicator--inactive">
Inactive
</span>
{{/if}}
</td>
{{/unless}}
<td>
{{ownerRecord.name}}
</td>
<td>
{{ember-selector
class=(unless isOwnerMutable "nacho-select--hidden-state")
values=ownerTypes
selected=@owner.type
disabled=(not isOwnerMutable)
selectionDidChange=(action "changeOwnerType")
}}
</td>
<td>
{{ownerRecord.idType}}
</td>
<td>
{{#if isOwnerMutable}}
{{!-- hides source column for confirmed owners--}}
{{#unless isOwnerMutable}}
<button
class="nacho-button nacho-button--small remove-dataset-author"
{{action "onRemoveOwner"}}>
<i class="fa fa-trash"
aria-label="Remove Owner"></i>
</button>
<td>
{{ownerRecord.source}}
</td>
{{else}}
{{/unless}}
{{#if isConfirmedSuggestedOwner}}
<td>
{{ember-selector
class=(unless isOwnerMutable "nacho-select--hidden-state")
values=ownerTypes
selected=ownerRecord.type
disabled=(not isOwnerMutable)
selectionDidChange=(action "changeOwnerType")
}}
</td>
<span
class="nacho-button nacho-button--small dataset-author-record__indicator--disabled">
Added
</span>
<td>
{{#if isOwnerMutable}}
<button
class="nacho-button nacho-button--small remove-dataset-author"
{{action "onRemoveOwner"}}>
<i class="fa fa-trash"
aria-label="Remove Owner"></i>
</button>
{{else}}
<button
class="nacho-button nacho-button--small confirm-suggested-dataset-author"
{{action "confirmOwner"}}>
<i class="fa fa-plus" title="Add an Owner"></i>
</button>
{{#if isConfirmedSuggestedOwner}}
<span
class="nacho-button nacho-button--small dataset-author-record__indicator--disabled">
Added
</span>
{{else}}
<button
class="nacho-button nacho-button--small confirm-suggested-dataset-author"
{{action "confirmOwner"}}>
<i class="fa fa-plus" title="Add an Owner"></i>
</button>
{{/if}}
{{/if}}
{{/if}}
</td>
</td>
{{/let}}

View File

@ -35,8 +35,8 @@
</tr>
</thead>
{{#each confirmedOwnersWithAvatars as |confirmedOwnerWithAvatar|}}
<tbody>
<tbody>
{{#each confirmedOwnersWithAvatars as |confirmedOwnerWithAvatar|}}
{{dataset-author
owner=confirmedOwnerWithAvatar
ownerTypes=ownerTypes
@ -44,8 +44,8 @@
confirmSuggestedOwner=(action "confirmSuggestedOwner")
updateOwnerType=(action "updateOwnerType")
}}
</tbody>
{{/each}}
{{/each}}
</tbody>
<tbody>
<tr>

View File

@ -1,28 +1,30 @@
<section class="suggested-owner-card__owner-info">
<div class="suggested-owner-card__owner-info__profile">
{{avatars/avatar-image avatar=@owner.avatar class="suggested-owner-card__owner-info__profile__pic"}}
{{#let @owner.owner as |ownerRecord|}}
<section class="suggested-owner-card__owner-info">
<div class="suggested-owner-card__owner-info__profile">
{{avatars/avatar-image avatar=@owner.avatar class="suggested-owner-card__owner-info__profile__pic"}}
<div class="suggested-owner-card__owner-info__profile__name">
<h5 class="suggested-owner-card__owner-info__profile__name__full">
{{@owner.name}}
</h5>
<p class="suggested-owner-card__owner-info__profile__name__username">
{{@owner.userName}}
</p>
<div class="suggested-owner-card__owner-info__profile__name">
<h5 class="suggested-owner-card__owner-info__profile__name__full">
{{ownerRecord.name}}
</h5>
<p class="suggested-owner-card__owner-info__profile__name__username">
{{ownerRecord.userName}}
</p>
</div>
</div>
</div>
<div class="suggested-owner-card__owner-info__add">
{{#if isConfirmedSuggestedOwner}}
{{fa-icon "check-circle-o" title="Added Owner" size="2"}}
<span class="suggested-owner-card__owner-info__add--disabled">Added</span>
{{else}}
<button class="nacho-button--secondary nacho-button--medium"
{{action "confirmOwner"}}>
Add as owner
</button>
{{/if}}
</div>
</section>
<section class="suggested-owner-card__source-info">
Source: {{@owner.source}}
</section>
<div class="suggested-owner-card__owner-info__add">
{{#if isConfirmedSuggestedOwner}}
{{fa-icon "check-circle-o" title="Added Owner" size="2"}}
<span class="suggested-owner-card__owner-info__add--disabled">Added</span>
{{else}}
<button class="nacho-button--secondary nacho-button--medium"
{{action "confirmOwner"}}>
Add as owner
</button>
{{/if}}
</div>
</section>
<section class="suggested-owner-card__source-info">
Source: {{ownerRecord.source}}
</section>
{{/let}}

View File

@ -6,6 +6,6 @@ import { IAvatar } from 'wherehows-web/typings/app/avatars';
* @type OwnerWithAvatarRecord
* @alias
*/
type OwnerWithAvatarRecord = IOwner & Record<'avatar', IAvatar>;
type OwnerWithAvatarRecord = Record<'owner', IOwner> & Record<'avatar', IAvatar>;
export { OwnerWithAvatarRecord };

View File

@ -17,7 +17,7 @@ module('Integration | Component | dataset author', function(hooks) {
test('it renders', async function(assert) {
this.set('removeOwner', noop);
this.set('confirmSuggestedOwner', noop);
this.set('author', confirmedOwner);
this.set('author', { owner: confirmedOwner });
this.set('commonOwners', commonOwners);
await render(
@ -36,7 +36,7 @@ module('Integration | Component | dataset author', function(hooks) {
assert.equal(removeActionCallCount, 1, 'action is called once');
});
this.set('confirmSuggestedOwner', noop);
this.set('author', confirmedOwner);
this.set('author', { owner: confirmedOwner });
this.set('commonOwners', commonOwners);
await render(
@ -57,7 +57,7 @@ module('Integration | Component | dataset author', function(hooks) {
confirmSuggestedOwnerActionCallCount++;
assert.equal(confirmSuggestedOwnerActionCallCount, 1, 'action is called once');
});
this.set('author', suggestedOwner);
this.set('author', { owner: suggestedOwner });
this.set('commonOwners', commonOwners);
await render(
@ -78,7 +78,7 @@ module('Integration | Component | dataset author', function(hooks) {
assert.ok(confirmedOwner === owner, 'updateOwnerType action is invoked correct owner reference');
assert.equal(type, confirmedOwner.type, 'updateOwnerType action is invoked with selected type');
});
this.set('author', confirmedOwner);
this.set('author', { owner: confirmedOwner });
this.set('commonOwners', commonOwners);
this.set('ownerTypes', ownerTypes);

View File

@ -23,7 +23,7 @@ module('Integration | Component | datasets/owners/suggested owner card', functio
test('it renders for base and empty cases', async function(assert) {
this.setProperties({
commonOwners,
author: {},
author: { owner: {} },
ownerTypes: [],
removeOwner: noop,
confirmSuggestedOwner: noop
@ -49,7 +49,7 @@ module('Integration | Component | datasets/owners/suggested owner card', functio
this.setProperties({
ownerTypes,
commonOwners,
author: model,
author: { owner: model },
removeOwner: noop,
confirmSuggestedOwner: noop
});
@ -79,7 +79,7 @@ module('Integration | Component | datasets/owners/suggested owner card', functio
this.setProperties({
ownerTypes,
commonOwners,
author: model,
author: { owner: model },
removeOwner: noop,
confirmSuggestedOwner: owner => {
assert.equal(owner.name, model.name, 'Passes the correct information to the confirmOwner function');