Commit c0574309 authored by Bryce Johnson's avatar Bryce Johnson

Clean up approvals body computed logic.

parent 9e874405
...@@ -7,24 +7,23 @@ ...@@ -7,24 +7,23 @@
props: ['approvedBy', 'approvalsLeft', 'userCanApprove', 'userHasApproved', 'suggestedApprovers', 'widgetLoading'], props: ['approvedBy', 'approvalsLeft', 'userCanApprove', 'userHasApproved', 'suggestedApprovers', 'widgetLoading'],
computed: { computed: {
approvalsRequiredStringified() { approvalsRequiredStringified() {
return this.approvalsLeft === 1 ? 'one more approval' : const baseString = `${this.approvalsLeft} more approval`;
`${this.approvalsLeft} more approvals`; return this.approvalsLeft === 1 ? baseString : `${baseString}s`;
}, },
approverNamesStringified() { approverNamesStringified() {
const approvers = this.suggestedApprovers; const approvers = this.suggestedApprovers;
return approvers.length === 1 ? approvers[0].name : return approvers.length === 1 ? approvers[0].name :
approvers.reduce((memo, curr, index) => { approvers.reduce((memo, curr, index) => {
const nextMemo = `${memo}${curr.name}`; const nextMemo = `${memo}${curr.name}`;
if (index === approvers.length - 2) { // second to last index if (index === approvers.length - 2) { // second to last index
return `${nextMemo} or `; return `${nextMemo} or `;
} else if (index === approvers.length - 1) { // last index } else if (index === approvers.length - 1) { // last index
return nextMemo; return nextMemo;
} }
return `${nextMemo}, `; return `${nextMemo}, `;
}, ''); }, '');
}
}, },
showApproveButton() { showApproveButton() {
return this.userCanApprove && !this.userHasApproved; return this.userCanApprove && !this.userHasApproved;
...@@ -41,7 +40,7 @@ ...@@ -41,7 +40,7 @@
template: ` template: `
<div class='approvals-body mr-widget-body'> <div class='approvals-body mr-widget-body'>
<h4> Requires {{ approvalsRequiredStringified }} <h4> Requires {{ approvalsRequiredStringified }}
<span v-if='!!suggestedApprovers.length'> (from {{ approverNamesStringified }}) </span> <span> (from {{ approverNamesStringified }}) </span>
</h4> </h4>
<div v-if='showApproveButton' class='append-bottom-10'> <div v-if='showApproveButton' class='append-bottom-10'>
<button <button
......
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