Commit 551ae71c authored by Samantha Ming's avatar Samantha Ming Committed by Kushal Pandya

Display indicator to rule name

- if rule is overridden from the project setting
- if rule is locally defined
parent b9997292
<script> <script>
import { __ } from '~/locale';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { RULE_TYPE_ANY_APPROVER, RULE_TYPE_REGULAR, RULE_NAME_ANY_APPROVER } from '../../constants'; import { RULE_TYPE_ANY_APPROVER, RULE_TYPE_REGULAR, RULE_NAME_ANY_APPROVER } from '../../constants';
import UserAvatarList from '~/vue_shared/components/user_avatar/user_avatar_list.vue'; import UserAvatarList from '~/vue_shared/components/user_avatar/user_avatar_list.vue';
...@@ -93,6 +94,15 @@ export default { ...@@ -93,6 +94,15 @@ export default {
this.fetchRules(this.targetBranch); this.fetchRules(this.targetBranch);
} }
}, },
indicatorText(rule) {
if (rule.hasSource) {
if (rule.overridden) {
return __('Overridden');
}
return '';
}
return __('Added for this merge request');
},
}, },
}; };
</script> </script>
...@@ -102,7 +112,7 @@ export default { ...@@ -102,7 +112,7 @@ export default {
<template slot="thead" slot-scope="{ name, members, approvalsRequired }"> <template slot="thead" slot-scope="{ name, members, approvalsRequired }">
<tr> <tr>
<th :class="hasNamedRule ? 'w-25' : 'w-75'">{{ hasNamedRule ? name : members }}</th> <th :class="hasNamedRule ? 'w-25' : 'w-75'">{{ hasNamedRule ? name : members }}</th>
<th :class="hasNamedRule ? 'w-75' : null"> <th :class="hasNamedRule ? 'w-50' : null">
<span v-if="hasNamedRule">{{ members }}</span> <span v-if="hasNamedRule">{{ members }}</span>
</th> </th>
<th>{{ approvalsRequired }}</th> <th>{{ approvalsRequired }}</th>
...@@ -120,7 +130,12 @@ export default { ...@@ -120,7 +130,12 @@ export default {
:can-edit="canEdit" :can-edit="canEdit"
/> />
<tr v-else :key="index"> <tr v-else :key="index">
<td class="js-name">{{ rule.name }}</td> <td>
<div class="js-name">{{ rule.name }}</div>
<div ref="indicator" class="text-muted">
{{ indicatorText(rule) }}
</div>
</td>
<td class="js-members" :class="settings.allowMultiRule ? 'd-none d-sm-table-cell' : null"> <td class="js-members" :class="settings.allowMultiRule ? 'd-none d-sm-table-cell' : null">
<user-avatar-list :items="rule.approvers" :img-size="24" /> <user-avatar-list :items="rule.approvers" :img-size="24" />
</td> </td>
......
...@@ -19,6 +19,7 @@ function withDefaultEmptyRule(rules = []) { ...@@ -19,6 +19,7 @@ function withDefaultEmptyRule(rules = []) {
groups: [], groups: [],
ruleType: RULE_TYPE_ANY_APPROVER, ruleType: RULE_TYPE_ANY_APPROVER,
protectedBranches: [], protectedBranches: [],
overridden: false,
}, },
]; ];
} }
...@@ -48,6 +49,7 @@ export const mapApprovalRuleResponse = res => ({ ...@@ -48,6 +49,7 @@ export const mapApprovalRuleResponse = res => ({
groups: res.groups, groups: res.groups,
ruleType: res.rule_type, ruleType: res.rule_type,
protectedBranches: res.protected_branches, protectedBranches: res.protected_branches,
overridden: res.overridden,
}); });
export const mapApprovalSettingsResponse = res => ({ export const mapApprovalSettingsResponse = res => ({
......
---
title: Display indicator to rule name in approval rules
merge_request: 29315
author:
type: added
...@@ -31,7 +31,8 @@ describe('EE Approvals MRRules', () => { ...@@ -31,7 +31,8 @@ describe('EE Approvals MRRules', () => {
}; };
const findHeaders = () => wrapper.findAll('thead th').wrappers.map(x => x.text()); const findHeaders = () => wrapper.findAll('thead th').wrappers.map(x => x.text());
const findRuleName = () => wrapper.find('td.js-name'); const findRuleName = () => wrapper.find('.js-name');
const findRuleIndicator = () => wrapper.find({ ref: 'indicator' });
const findRuleMembers = () => const findRuleMembers = () =>
wrapper wrapper
.find('td.js-members') .find('td.js-members')
...@@ -123,6 +124,22 @@ describe('EE Approvals MRRules', () => { ...@@ -123,6 +124,22 @@ describe('EE Approvals MRRules', () => {
wrapper.destroy(); wrapper.destroy();
expect(mockDisconnect).toHaveBeenCalled(); expect(mockDisconnect).toHaveBeenCalled();
}); });
describe('rule indicator', () => {
const falseOverriddenRule = createMRRuleWithSource({ overridden: false });
it.each`
rules | indicator | desc
${createMRRuleWithSource()} | ${'Overridden'} | ${'indicates "Overridden" for overridden rules'}
${createMRRule()} | ${'Added for this merge request'} | ${'indicates "Added for this merge request" for local rules'}
${falseOverriddenRule} | ${''} | ${'has no indicator for non-overridden rules'}
`('$desc', ({ rules, indicator }) => {
store.modules.approvals.state.rules = [rules];
factory();
expect(findRuleIndicator().text()).toBe(indicator);
});
});
}); });
describe('when allow multiple rules', () => { describe('when allow multiple rules', () => {
......
...@@ -16,10 +16,12 @@ export const createEmptyRule = () => ({ ...@@ -16,10 +16,12 @@ export const createEmptyRule = () => ({
ruleType: 'any_approver', ruleType: 'any_approver',
}); });
export const createMRRuleWithSource = () => ({ export const createMRRuleWithSource = (rule = {}) => ({
...createEmptyRule(), ...createEmptyRule(),
...createMRRule(), ...createMRRule(),
minApprovalsRequired: 1, minApprovalsRequired: 1,
hasSource: true, hasSource: true,
sourceId: 3, sourceId: 3,
overridden: true,
...rule,
}); });
...@@ -1286,6 +1286,9 @@ msgstr "" ...@@ -1286,6 +1286,9 @@ msgstr ""
msgid "Added at" msgid "Added at"
msgstr "" msgstr ""
msgid "Added for this merge request"
msgstr ""
msgid "Added in this version" msgid "Added in this version"
msgstr "" msgstr ""
...@@ -14162,6 +14165,9 @@ msgstr "" ...@@ -14162,6 +14165,9 @@ msgstr ""
msgid "OutdatedBrowser|You can provide feedback %{feedback_link_start}on this issue%{feedback_link_end} or via your usual support channels." msgid "OutdatedBrowser|You can provide feedback %{feedback_link_start}on this issue%{feedback_link_end} or via your usual support channels."
msgstr "" msgstr ""
msgid "Overridden"
msgstr ""
msgid "Overview" msgid "Overview"
msgstr "" msgstr ""
......
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