Commit b4d265cc authored by Bryce Johnson's avatar Bryce Johnson

Simplify logic for approverNamesStringified.

parent 44fa842f
...@@ -12,25 +12,19 @@ ...@@ -12,25 +12,19 @@
}, },
approverNamesStringified() { approverNamesStringified() {
const approvers = this.suggestedApprovers; const approvers = this.suggestedApprovers;
if (approvers && approvers.length) { if (approvers.length === 1) {
if (approvers.length === 1) { return approvers[0].name;
return approvers[0].name; } else {
}
const lastIndex = approvers.length - 1;
const nextToLastIndex = approvers.length - 2;
return approvers.reduce((memo, curr, index) => { return approvers.reduce((memo, curr, index) => {
let suffix; const nextMemo = `${memo}${curr.name}`;
if (index === nextToLastIndex) { if (index === approvers.length - 2) { // second to last index
suffix = ' or '; return `${nextMemo} or `;
} else if (index === lastIndex) { } else if (index === approvers.length - 1) { // last index
suffix = ''; return nextMemo;
} else {
suffix = ', ';
} }
const nameToAdd = `${curr.name}${suffix}`; return `${nextMemo}, `;
return `${memo}${nameToAdd}`;
}, ''); }, '');
} }
return null; return null;
...@@ -39,7 +33,7 @@ ...@@ -39,7 +33,7 @@
return this.userCanApprove && !this.userHasApproved; return this.userCanApprove && !this.userHasApproved;
}, },
showApprovalsBody() { showApprovalsBody() {
return !this.widgetLoading && this.approvalsLeft; return !this.widgetLoading && this.approvalsLeft && this.suggestedApprovers.length;
} }
}, },
methods: { methods: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment