Commit d9ba6c77 authored by Paul Slaughter's avatar Paul Slaughter

Add default approvals obj to rules mr component

**Why?**
This helps eliminate a handful of nested null checks since the
computed property defaults to an empty object.

Also, transform some of the computed props to use `!!` to
ensure a Boolean representation.
parent b51bcb35
...@@ -42,23 +42,29 @@ export default { ...@@ -42,23 +42,29 @@ export default {
}; };
}, },
computed: { computed: {
approvals() {
return this.mr.approvals || {};
},
hasFooter() { hasFooter() {
return this.mr.approvals && this.mr.approvals.has_approval_rules; return !!this.approvals.has_approval_rules;
}, },
approvedBy() { approvedBy() {
return this.mr.approvals ? this.mr.approvals.approved_by.map(x => x.user) : []; return this.approvals.approved_by ? this.approvals.approved_by.map(x => x.user) : [];
},
isApproved() {
return !!this.approvals.approved;
}, },
approvalsRequired() { approvalsRequired() {
return this.mr.approvals ? this.mr.approvals.approvals_required : 0; return this.approvals.approvals_required || 0;
}, },
isOptional() { isOptional() {
return !this.approvedBy.length && !this.approvalsRequired; return !this.approvedBy.length && !this.approvalsRequired;
}, },
userHasApproved() { userHasApproved() {
return this.mr.approvals.user_has_approved; return !!this.approvals.user_has_approved;
}, },
userCanApprove() { userCanApprove() {
return this.mr.approvals.user_can_approve; return !!this.approvals.user_can_approve;
}, },
showApprove() { showApprove() {
return !this.userHasApproved && this.userCanApprove && this.mr.isOpen; return !this.userHasApproved && this.userCanApprove && this.mr.isOpen;
...@@ -68,9 +74,9 @@ export default { ...@@ -68,9 +74,9 @@ export default {
}, },
action() { action() {
if (this.showApprove) { if (this.showApprove) {
const inverted = this.mr.approvals.approved; const inverted = this.isApproved;
const text = const text =
this.mr.approvals.approved && this.approvedBy.length this.isApproved && this.approvedBy.length > 0
? s__('mrWidget|Approve additionally') ? s__('mrWidget|Approve additionally')
: s__('mrWidget|Approve'); : s__('mrWidget|Approve');
...@@ -178,9 +184,9 @@ export default { ...@@ -178,9 +184,9 @@ export default {
/> />
<approvals-summary <approvals-summary
v-else v-else
:approved="mr.approvals.approved" :approved="isApproved"
:approvals-left="mr.approvals.approvals_left" :approvals-left="approvals.approvals_left"
:rules-left="mr.approvals.approvalRuleNamesLeft" :rules-left="approvals.approvalRuleNamesLeft"
:approvers="approvedBy" :approvers="approvedBy"
/> />
</template> </template>
...@@ -189,7 +195,7 @@ export default { ...@@ -189,7 +195,7 @@ export default {
v-if="hasFooter" v-if="hasFooter"
slot="footer" slot="footer"
v-model="isExpanded" v-model="isExpanded"
:suggested-approvers="mr.approvals.suggested_approvers" :suggested-approvers="approvals.suggested_approvers"
:approval-rules="mr.approvalRules" :approval-rules="mr.approvalRules"
:is-loading-rules="isLoadingRules" :is-loading-rules="isLoadingRules"
/> />
......
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