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 { IOwner } from 'wherehows-web/typings/api/datasets/owners';
import { OwnerSource, OwnerType } from 'wherehows-web/utils/api/datasets/owners'; import { OwnerSource, OwnerType } from 'wherehows-web/utils/api/datasets/owners';
import { action } from '@ember-decorators/object'; 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 * 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 * The owner record being rendered
* @type {IOwner} * @type {OwnerWithAvatarRecord}
* @memberof DatasetAuthor * @memberof DatasetAuthor
*/ */
owner: IOwner; owner: OwnerWithAvatarRecord;
/** /**
* List of suggested owners that have been confirmed by a user * List of suggested owners that have been confirmed by a user
@ -73,14 +74,14 @@ export default class DatasetAuthor extends Component {
* @type {ComputedProperty<boolean>} * @type {ComputedProperty<boolean>}
* @memberof DatasetAuthor * @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 * Negates the owner attribute flag `isActive`, indicating owner record is considered inactive
* @type {ComputedProperty<boolean>} * @type {ComputedProperty<boolean>}
* @memberOf DatasetAuthor * @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 * 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 { const {
commonOwners, commonOwners,
isOwnerMutable, isOwnerMutable,
owner: { userName } owner: {
owner: { userName }
}
} = getProperties(this, ['commonOwners', 'isOwnerMutable', 'owner']); } = getProperties(this, ['commonOwners', 'isOwnerMutable', 'owner']);
return isOwnerMutable ? false : !!commonOwners.findBy('userName', userName); return isOwnerMutable ? false : !!commonOwners.findBy('userName', userName);
@ -123,7 +126,7 @@ export default class DatasetAuthor extends Component {
@action @action
onRemoveOwner(): boolean | void | IOwner { onRemoveOwner(): boolean | void | IOwner {
const { owner, isOwnerMutable, removeOwner } = getProperties(this, ['owner', 'isOwnerMutable', 'removeOwner']); 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 @action
confirmOwner(): Array<IOwner> | void { confirmOwner(): Array<IOwner> | void {
const { owner, confirmSuggestedOwner } = getProperties(this, ['owner', 'confirmSuggestedOwner']); 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' '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; const { avatarProperties } = this;
return { return {
...owner, owner,
avatar: avatarProperties avatar: avatarProperties
? getAvatarProps(avatarProperties)({ userName: owner.userName }) ? getAvatarProps(avatarProperties)({ userName: owner.userName })
: { imageUrl: '', imageUrlFallback: '/assets/assets/images/default_avatar.png' } : { imageUrl: '', imageUrlFallback: '/assets/assets/images/default_avatar.png' }
@ -266,8 +266,10 @@ export default class DatasetAuthors extends Component {
*/ */
@action @action
addOwner(this: DatasetAuthors, newOwner: IOwner): Array<IOwner> | void { addOwner(this: DatasetAuthors, newOwner: IOwner): Array<IOwner> | void {
const owners = get(this, 'owners') || []; const {
const { notify } = get(this, 'notifications'); owners = [],
notifications: { notify }
} = this;
if (ownerAlreadyExists(owners, { userName: newOwner.userName, source: newOwner.source })) { if (ownerAlreadyExists(owners, { userName: newOwner.userName, source: newOwner.source })) {
return void notify(NotificationEvent.info, { content: 'Owner has already been added to "confirmed" list' }); return void notify(NotificationEvent.info, { content: 'Owner has already been added to "confirmed" list' });

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ module('Integration | Component | dataset author', function(hooks) {
test('it renders', async function(assert) { test('it renders', async function(assert) {
this.set('removeOwner', noop); this.set('removeOwner', noop);
this.set('confirmSuggestedOwner', noop); this.set('confirmSuggestedOwner', noop);
this.set('author', confirmedOwner); this.set('author', { owner: confirmedOwner });
this.set('commonOwners', commonOwners); this.set('commonOwners', commonOwners);
await render( await render(
@ -36,7 +36,7 @@ module('Integration | Component | dataset author', function(hooks) {
assert.equal(removeActionCallCount, 1, 'action is called once'); assert.equal(removeActionCallCount, 1, 'action is called once');
}); });
this.set('confirmSuggestedOwner', noop); this.set('confirmSuggestedOwner', noop);
this.set('author', confirmedOwner); this.set('author', { owner: confirmedOwner });
this.set('commonOwners', commonOwners); this.set('commonOwners', commonOwners);
await render( await render(
@ -57,7 +57,7 @@ module('Integration | Component | dataset author', function(hooks) {
confirmSuggestedOwnerActionCallCount++; confirmSuggestedOwnerActionCallCount++;
assert.equal(confirmSuggestedOwnerActionCallCount, 1, 'action is called once'); assert.equal(confirmSuggestedOwnerActionCallCount, 1, 'action is called once');
}); });
this.set('author', suggestedOwner); this.set('author', { owner: suggestedOwner });
this.set('commonOwners', commonOwners); this.set('commonOwners', commonOwners);
await render( 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.ok(confirmedOwner === owner, 'updateOwnerType action is invoked correct owner reference');
assert.equal(type, confirmedOwner.type, 'updateOwnerType action is invoked with selected type'); 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('commonOwners', commonOwners);
this.set('ownerTypes', ownerTypes); 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) { test('it renders for base and empty cases', async function(assert) {
this.setProperties({ this.setProperties({
commonOwners, commonOwners,
author: {}, author: { owner: {} },
ownerTypes: [], ownerTypes: [],
removeOwner: noop, removeOwner: noop,
confirmSuggestedOwner: noop confirmSuggestedOwner: noop
@ -49,7 +49,7 @@ module('Integration | Component | datasets/owners/suggested owner card', functio
this.setProperties({ this.setProperties({
ownerTypes, ownerTypes,
commonOwners, commonOwners,
author: model, author: { owner: model },
removeOwner: noop, removeOwner: noop,
confirmSuggestedOwner: noop confirmSuggestedOwner: noop
}); });
@ -79,7 +79,7 @@ module('Integration | Component | datasets/owners/suggested owner card', functio
this.setProperties({ this.setProperties({
ownerTypes, ownerTypes,
commonOwners, commonOwners,
author: model, author: { owner: model },
removeOwner: noop, removeOwner: noop,
confirmSuggestedOwner: owner => { confirmSuggestedOwner: owner => {
assert.equal(owner.name, model.name, 'Passes the correct information to the confirmOwner function'); assert.equal(owner.name, model.name, 'Passes the correct information to the confirmOwner function');