updates last saved by to integrate with newly added properties on GET response for owner and actor

This commit is contained in:
Seyi Adebajo 2018-09-28 12:49:22 -07:00
parent ddb680c38b
commit 3553c95f16
9 changed files with 38 additions and 47 deletions

View File

@ -1,7 +1,7 @@
import Component from '@ember/component'; import Component from '@ember/component';
import { get, set, getProperties, setProperties } from '@ember/object'; import { get, set, getProperties, setProperties } from '@ember/object';
import { task, TaskInstance } from 'ember-concurrency'; import { task, TaskInstance } from 'ember-concurrency';
import { action, computed } from '@ember-decorators/object'; import { action } from '@ember-decorators/object';
import Notifications from 'wherehows-web/services/notifications'; import Notifications from 'wherehows-web/services/notifications';
import { NotificationEvent } from 'wherehows-web/services/notifications'; import { NotificationEvent } from 'wherehows-web/services/notifications';
import { IOwner, IOwnerResponse } from 'wherehows-web/typings/api/datasets/owners'; import { IOwner, IOwnerResponse } from 'wherehows-web/typings/api/datasets/owners';
@ -69,6 +69,12 @@ export default class DatasetOwnershipContainer extends Component {
*/ */
avatarProperties: IAppConfig['userEntityProps'] | undefined; avatarProperties: IAppConfig['userEntityProps'] | undefined;
/**
* Metadata related to the ownership properties for the dataset
* @type {{ actor: string, lastModified: number }}
* @memberof DatasetOwnershipContainer
*/
ownershipMetadata: { actor: string; lastModified: number } = { actor: '', lastModified: 0 };
/** /**
* An async parent task to group all data tasks for this container component * An async parent task to group all data tasks for this container component
* @type {Task<TaskInstance<Promise<any>>, (a?: any) => TaskInstance<TaskInstance<Promise<any>>>>} * @type {Task<TaskInstance<Promise<any>>, (a?: any) => TaskInstance<TaskInstance<Promise<any>>>>}
@ -103,34 +109,13 @@ export default class DatasetOwnershipContainer extends Component {
* @type {Task<Promise<Array<IOwner>>, (a?: any) => TaskInstance<Promise<IOwnerResponse>>>} * @type {Task<Promise<Array<IOwner>>, (a?: any) => TaskInstance<Promise<IOwnerResponse>>>}
*/ */
getDatasetOwnersTask = task(function*(this: DatasetOwnershipContainer): IterableIterator<Promise<IOwnerResponse>> { getDatasetOwnersTask = task(function*(this: DatasetOwnershipContainer): IterableIterator<Promise<IOwnerResponse>> {
const { owners = [], fromUpstream, datasetUrn }: IOwnerResponse = yield readDatasetOwnersByUrn(get(this, 'urn')); const { owners = [], fromUpstream, datasetUrn, lastModified, actor }: IOwnerResponse = yield readDatasetOwnersByUrn(
this.urn
);
setProperties(this, { owners, fromUpstream, upstreamUrn: datasetUrn }); setProperties(this, { owners, fromUpstream, upstreamUrn: datasetUrn, ownershipMetadata: { lastModified, actor } });
}); });
/**
* Retrieves metadata about the current ownership records including modificationTime and actor
* @readonly
* @type {(Record<'actor' | 'modificationTime', string>)}
* @memberof DatasetOwnershipContainer
*/
@computed('owners.[]')
get ownershipMetadata(): Record<'actor' | 'modificationTime', string> {
const {
owners: [owner]
} = this;
const ownershipMetadata = { actor: '', modificationTime: '' };
if (owner) {
const { confirmedBy, modifiedTime } = owner;
const modificationTime = modifiedTime ? String(modifiedTime) : '';
return { ...ownershipMetadata, actor: confirmedBy || '', modificationTime };
}
return ownershipMetadata;
}
/** /**
* Fetches the suggested owners for this dataset * Fetches the suggested owners for this dataset
* @type {Task<Promise<Array<IOwner>>, (a?: any) => TaskInstance<Promise<IOwnerResponse>>>} * @type {Task<Promise<Array<IOwner>>, (a?: any) => TaskInstance<Promise<IOwnerResponse>>>}

View File

@ -1,4 +1,3 @@
@import 'owner-table'; @import 'owner-table';
@import 'dataset-author'; @import 'dataset-author';
@import 'suggested-owners'; @import 'suggested-owners';
@import 'ownership-metadata';

View File

@ -1,3 +0,0 @@
.ownership-metadata {
text-align: right;
}

View File

@ -40,9 +40,3 @@
color: set-color(red, red5); color: set-color(red, red5);
} }
} }
.policy-last-saved {
margin-left: auto;
text-align: right;
max-width: 300px;
}

View File

@ -10,3 +10,9 @@
margin: item-spacing(0 1); margin: item-spacing(0 1);
} }
} }
.last-saved-by-container {
text-align: right;
margin-left: auto;
padding: item-spacing(3 0);
}

View File

@ -77,7 +77,7 @@
{{/if}} {{/if}}
<div class="secondary-actions"> <div class="secondary-actions">
<div class="policy-last-saved"> <div class="last-saved-by-container">
{{last-saved-by actor=complianceInfo.modifiedBy time=complianceInfo.modifiedTime}} {{last-saved-by actor=complianceInfo.modifiedBy time=complianceInfo.modifiedTime}}
</div> </div>
</div> </div>

View File

@ -30,8 +30,8 @@
{{else}} {{else}}
<div class="ownership-metadata"> <div class="last-saved-by-container">
{{last-saved-by actor=ownershipMetadata.actor time=ownershipMetadata.modificationTime}} {{last-saved-by actor=ownershipMetadata.actor time=ownershipMetadata.lastModified}}
</div> </div>
{{dataset-authors {{dataset-authors

View File

@ -27,6 +27,10 @@ interface IOwnerResponse {
owners?: Array<IOwner>; owners?: Array<IOwner>;
fromUpstream: boolean; fromUpstream: boolean;
datasetUrn: string; datasetUrn: string;
// date the ownership information was last modified
lastModified: number;
// entity that performed the modification
actor: string;
} }
/** /**

View File

@ -103,14 +103,18 @@ const ownersWithModifiedTimeAsDate = arrayMap(ownerWithModifiedTimeAsDate);
const readDatasetOwnersByUrn = async (urn: string): Promise<IOwnerResponse> => { const readDatasetOwnersByUrn = async (urn: string): Promise<IOwnerResponse> => {
let owners: Array<IOwner> = [], let owners: Array<IOwner> = [],
fromUpstream = false, fromUpstream = false,
datasetUrn = ''; datasetUrn = '',
lastModified = 0,
actor = '';
try { try {
({ owners = [], fromUpstream, datasetUrn } = await getJSON<IOwnerResponse>({ url: datasetOwnersUrlByUrn(urn) })); ({ owners = [], fromUpstream, datasetUrn, actor, lastModified } = await getJSON<IOwnerResponse>({
return { owners: ownersWithModifiedTimeAsDate(owners), fromUpstream, datasetUrn }; url: datasetOwnersUrlByUrn(urn)
}));
return { owners: ownersWithModifiedTimeAsDate(owners), fromUpstream, datasetUrn, actor, lastModified };
} catch (e) { } catch (e) {
if (isNotFoundApiError(e)) { if (isNotFoundApiError(e)) {
return { owners, fromUpstream, datasetUrn }; return { owners, fromUpstream, datasetUrn, actor, lastModified };
} else { } else {
throw e; throw e;
} }
@ -125,16 +129,18 @@ const readDatasetOwnersByUrn = async (urn: string): Promise<IOwnerResponse> => {
const readDatasetSuggestedOwnersByUrn = async (urn: string): Promise<IOwnerResponse> => { const readDatasetSuggestedOwnersByUrn = async (urn: string): Promise<IOwnerResponse> => {
let owners: Array<IOwner> = [], let owners: Array<IOwner> = [],
fromUpstream = false, fromUpstream = false,
datasetUrn = ''; datasetUrn = '',
lastModified = 0,
actor = '';
try { try {
({ owners = [], fromUpstream, datasetUrn } = await getJSON<IOwnerResponse>({ ({ owners = [], fromUpstream, datasetUrn, actor, lastModified } = await getJSON<IOwnerResponse>({
url: datasetSuggestedOwnersUrlByUrn(urn) url: datasetSuggestedOwnersUrlByUrn(urn)
})); }));
return { owners: ownersWithModifiedTimeAsDate(owners), fromUpstream, datasetUrn }; return { owners: ownersWithModifiedTimeAsDate(owners), fromUpstream, datasetUrn, actor, lastModified };
} catch (e) { } catch (e) {
if (isNotFoundApiError(e)) { if (isNotFoundApiError(e)) {
return { owners, fromUpstream, datasetUrn }; return { owners, fromUpstream, datasetUrn, actor, lastModified };
} else { } else {
throw e; throw e;
} }