From b0320ca407920653108e21b8e87cc6eb23de2d4b Mon Sep 17 00:00:00 2001 From: cptran777 Date: Tue, 8 May 2018 10:01:46 -0700 Subject: [PATCH 1/2] On ownership tab, disables save button when no changes have been made and adds owners to bottom of table instead of top --- .../app/components/dataset-authors.ts | 31 +++++++++++++++++-- .../templates/components/dataset-authors.hbs | 12 ++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/wherehows-web/app/components/dataset-authors.ts b/wherehows-web/app/components/dataset-authors.ts index 64b62a55c1..6fcf591bdf 100644 --- a/wherehows-web/app/components/dataset-authors.ts +++ b/wherehows-web/app/components/dataset-authors.ts @@ -21,6 +21,8 @@ import { import { OwnerSource, OwnerType } from 'wherehows-web/utils/api/datasets/owners'; import Notifications, { NotificationEvent } from 'wherehows-web/services/notifications'; +type Comparator = -1 | 0 | 1; + /** * Defines properties for the component that renders a list of owners and provides functionality for * interacting with the list items or the list as whole @@ -64,6 +66,20 @@ export default class DatasetAuthors extends Component { */ userLookup: ComputedProperty = inject(); + /** + * If there are no changes to the ownership tab, we want to keep the save button disabled. Rather than + * try to compare two sets of prev vs new data, we just have a flag here that short stops the validation + * function. + * Note: hasChanged has 3 states: + * -1 Component hasn't completed initialization yet, and no changes have been made. When + * requiredMinNotConfirmed is run on init/render, this gets incremented to its neutral state at 0 + * 0 No changes have been made yet + * 1 At least one change has been made + * @type {number} + * @memberof DatasetAuthors + */ + hasChanged: Comparator = -1; + /** * Reference to the userNamesResolver function to asynchronously match userNames * @type {UserLookup.userNamesResolver} @@ -86,7 +102,14 @@ export default class DatasetAuthors extends Component { requiredMinNotConfirmed: ComputedProperty = computed('confirmedOwners.@each.type', function( this: DatasetAuthors ) { - return isRequiredMinOwnersNotConfirmed(get(this, 'confirmedOwners')); + const hasChanged = get(this, 'hasChanged'); + + if (hasChanged < 1) { + set(this, 'hasChanged', (hasChanged + 1)); + } + // If there have been no changes, then we want to automatically set true in order to disable save button + // when no changes have been made + return hasChanged === -1 ? true : isRequiredMinOwnersNotConfirmed(get(this, 'confirmedOwners')); }); /** @@ -94,7 +117,9 @@ export default class DatasetAuthors extends Component { * @type {ComputedProperty} * @memberof DatasetAuthors */ - ownersRequiredCount: ComputedProperty = computed('confirmedOwners.[]', function(this: DatasetAuthors) { + ownersRequiredCount: ComputedProperty = computed('confirmedOwners.@each.type', function( + this: DatasetAuthors + ) { return minRequiredConfirmedOwners - validConfirmedOwners(get(this, 'confirmedOwners')).length; }); @@ -180,7 +205,7 @@ export default class DatasetAuthors extends Component { } const { userName } = get(get(this, 'currentUser'), 'currentUser'); - const updatedOwners = [newOwner, ...owners]; + const updatedOwners = [...owners, newOwner]; confirmOwner(newOwner, userName); return owners.setObjects(updatedOwners); diff --git a/wherehows-web/app/templates/components/dataset-authors.hbs b/wherehows-web/app/templates/components/dataset-authors.hbs index b8c05e2c19..4921351a02 100644 --- a/wherehows-web/app/templates/components/dataset-authors.hbs +++ b/wherehows-web/app/templates/components/dataset-authors.hbs @@ -233,11 +233,15 @@

{{fa-icon "times-circle-o" class="dataset-authors-save-error__icon"}} - {{#if (eq ownersRequiredCount 2)}} - Add at least 2 DataOwners. + {{#unless hasChanged}} + Please make changes to save. {{else}} - Add at least {{ownersRequiredCount}} more DataOwner(s). - {{/if}} + {{#if (eq ownersRequiredCount 2)}} + Add at least 2 DataOwners. + {{else}} + Add at least {{ownersRequiredCount}} more DataOwner(s). + {{/if}} + {{/unless}}

{{/if}} From 997b32698cf7307e6614e0fc7a4317476c5e859e Mon Sep 17 00:00:00 2001 From: cptran777 Date: Tue, 8 May 2018 11:10:21 -0700 Subject: [PATCH 2/2] Change property name to reduce code ambiguity --- wherehows-web/app/components/dataset-authors.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wherehows-web/app/components/dataset-authors.ts b/wherehows-web/app/components/dataset-authors.ts index 6fcf591bdf..77ac051316 100644 --- a/wherehows-web/app/components/dataset-authors.ts +++ b/wherehows-web/app/components/dataset-authors.ts @@ -70,7 +70,7 @@ export default class DatasetAuthors extends Component { * If there are no changes to the ownership tab, we want to keep the save button disabled. Rather than * try to compare two sets of prev vs new data, we just have a flag here that short stops the validation * function. - * Note: hasChanged has 3 states: + * Note: changedState has 3 states: * -1 Component hasn't completed initialization yet, and no changes have been made. When * requiredMinNotConfirmed is run on init/render, this gets incremented to its neutral state at 0 * 0 No changes have been made yet @@ -78,7 +78,7 @@ export default class DatasetAuthors extends Component { * @type {number} * @memberof DatasetAuthors */ - hasChanged: Comparator = -1; + changedState: Comparator = -1; /** * Reference to the userNamesResolver function to asynchronously match userNames @@ -102,14 +102,14 @@ export default class DatasetAuthors extends Component { requiredMinNotConfirmed: ComputedProperty = computed('confirmedOwners.@each.type', function( this: DatasetAuthors ) { - const hasChanged = get(this, 'hasChanged'); + const changedState = get(this, 'changedState'); - if (hasChanged < 1) { - set(this, 'hasChanged', (hasChanged + 1)); + if (changedState < 1) { + set(this, 'changedState', (changedState + 1)); } // If there have been no changes, then we want to automatically set true in order to disable save button // when no changes have been made - return hasChanged === -1 ? true : isRequiredMinOwnersNotConfirmed(get(this, 'confirmedOwners')); + return changedState === -1 ? true : isRequiredMinOwnersNotConfirmed(get(this, 'confirmedOwners')); }); /**