Commit f7c2e86d authored by Robert Hunt's avatar Robert Hunt Committed by Andrew Fontaine

Updated the approvers rule removal modal to use new danger variant

- Updated the modal to use the new primary and cancel action objects
- Updated to use danger rather than remove
- Updated specs with new prop values
- Removed eslint disabled rule and replaced v-html with GlSprintF
parent 8cfe7d61
<script> <script>
/* eslint-disable vue/no-v-html */ import { GlSprintf } from '@gitlab/ui';
import { escape } from 'lodash';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { sprintf, n__, s__ } from '~/locale'; import { n__, s__, __ } from '~/locale';
import GlModalVuex from '~/vue_shared/components/gl_modal_vuex.vue'; import GlModalVuex from '~/vue_shared/components/gl_modal_vuex.vue';
const i18n = {
cancelButtonText: __('Cancel'),
primaryButtonText: __('Remove approvers'),
modalTitle: __('Remove approvers?'),
removeWarningText: s__(
'ApprovalRuleRemove|You are about to remove the %{name} approver group which has %{nMembers}.',
),
};
export default { export default {
components: { components: {
GlModalVuex, GlModalVuex,
GlSprintf,
}, },
props: { props: {
modalId: { modalId: {
...@@ -19,33 +28,22 @@ export default { ...@@ -19,33 +28,22 @@ export default {
...mapState('deleteModal', { ...mapState('deleteModal', {
rule: 'data', rule: 'data',
}), }),
message() { membersText() {
if (!this.rule) { return n__(
return '';
}
const nMembers = n__(
'ApprovalRuleRemove|%d member', 'ApprovalRuleRemove|%d member',
'ApprovalRuleRemove|%d members', 'ApprovalRuleRemove|%d members',
this.rule.approvers.length, this.rule.approvers.length,
); );
const removeWarning = sprintf( },
s__( revokeWarningText() {
'ApprovalRuleRemove|You are about to remove the %{name} approver group which has %{nMembers}.', return n__(
),
{
name: `<strong>${escape(this.rule.name)}</strong>`,
nMembers: `<strong>${nMembers}</strong>`,
},
false,
);
const revokeWarning = n__(
'ApprovalRuleRemove|Approvals from this member are not revoked.', 'ApprovalRuleRemove|Approvals from this member are not revoked.',
'ApprovalRuleRemove|Approvals from these members are not revoked.', 'ApprovalRuleRemove|Approvals from these members are not revoked.',
this.rule.approvers.length, this.rule.approvers.length,
); );
},
return `${removeWarning} ${revokeWarning}`; modalText() {
return `${i18n.removeWarningText} ${this.revokeWarningText}`;
}, },
}, },
methods: { methods: {
...@@ -54,6 +52,16 @@ export default { ...@@ -54,6 +52,16 @@ export default {
this.deleteRule(this.rule.id); this.deleteRule(this.rule.id);
}, },
}, },
buttonActions: {
primary: {
text: i18n.primaryButtonText,
attributes: [{ variant: 'danger' }],
},
cancel: {
text: i18n.cancelButtonText,
},
},
i18n,
}; };
</script> </script>
...@@ -61,12 +69,23 @@ export default { ...@@ -61,12 +69,23 @@ export default {
<gl-modal-vuex <gl-modal-vuex
modal-module="deleteModal" modal-module="deleteModal"
:modal-id="modalId" :modal-id="modalId"
:title="__('Remove approvers?')" :title="$options.i18n.modalTitle"
:ok-title="__('Remove approvers')" :action-primary="$options.buttonActions.primary"
ok-variant="remove" :action-cancel="$options.buttonActions.cancel"
:cancel-title="__('Cancel')"
@ok.prevent="submit" @ok.prevent="submit"
> >
<p v-html="message"></p> <p v-if="rule">
<gl-sprintf :message="modalText">
<template #name>
<strong>{{ rule.name }}</strong>
</template>
<template #nMembers>
<strong>{{ membersText }}</strong>
</template>
<template #revokeWarning>
{{ revokeWarningText }}
</template>
</gl-sprintf>
</p>
</gl-modal-vuex> </gl-modal-vuex>
</template> </template>
---
title: Update the approvers rule removal modal button to use new danger variant
merge_request: 56230
author:
type: changed
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Approvals ModalRuleRemove shows message 1`] = `
<div
title="Remove approvers?"
>
<p>
You are about to remove the
<strong>
Lorem
</strong>
approver group which has
<strong>
5 members
</strong>
. Approvals from these members are not revoked.
</p>
</div>
`;
exports[`Approvals ModalRuleRemove shows singular message 1`] = `
<div
title="Remove approvers?"
>
<p>
You are about to remove the
<strong>
Lorem
</strong>
approver group which has
<strong>
1 member
</strong>
. Approvals from this member are not revoked.
</p>
</div>
`;
import { GlSprintf } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import ModalRuleRemove from 'ee/approvals/components/modal_rule_remove.vue'; import ModalRuleRemove from 'ee/approvals/components/modal_rule_remove.vue';
import { stubComponent } from 'helpers/stub_component';
import GlModalVuex from '~/vue_shared/components/gl_modal_vuex.vue'; import GlModalVuex from '~/vue_shared/components/gl_modal_vuex.vue';
const MODAL_MODULE = 'deleteModal'; const MODAL_MODULE = 'deleteModal';
...@@ -21,6 +23,8 @@ describe('Approvals ModalRuleRemove', () => { ...@@ -21,6 +23,8 @@ describe('Approvals ModalRuleRemove', () => {
let actions; let actions;
let deleteModalState; let deleteModalState;
const findModal = () => wrapper.findComponent(GlModalVuex);
const factory = (options = {}) => { const factory = (options = {}) => {
const store = new Vuex.Store({ const store = new Vuex.Store({
actions, actions,
...@@ -42,6 +46,12 @@ describe('Approvals ModalRuleRemove', () => { ...@@ -42,6 +46,12 @@ describe('Approvals ModalRuleRemove', () => {
localVue, localVue,
store, store,
propsData, propsData,
stubs: {
GlModalVuex: stubComponent(GlModalVuex, {
props: ['modalModule', 'modalId', 'actionPrimary', 'actionCancel'],
}),
GlSprintf,
},
}); });
}; };
...@@ -57,13 +67,18 @@ describe('Approvals ModalRuleRemove', () => { ...@@ -57,13 +67,18 @@ describe('Approvals ModalRuleRemove', () => {
it('renders modal', () => { it('renders modal', () => {
factory(); factory();
const modal = wrapper.find(GlModalVuex); const modal = findModal();
expect(modal.exists()).toBe(true); expect(modal.exists()).toBe(true);
expect(modal.props()).toEqual( expect(modal.props()).toEqual(
expect.objectContaining({ expect.objectContaining({
modalModule: MODAL_MODULE, modalModule: MODAL_MODULE,
modalId: TEST_MODAL_ID, modalId: TEST_MODAL_ID,
actionPrimary: {
text: 'Remove approvers',
attributes: [{ variant: 'danger' }],
},
actionCancel: { text: 'Cancel' },
}), }),
); );
}); });
...@@ -71,10 +86,7 @@ describe('Approvals ModalRuleRemove', () => { ...@@ -71,10 +86,7 @@ describe('Approvals ModalRuleRemove', () => {
it('shows message', () => { it('shows message', () => {
factory(); factory();
const modal = wrapper.find(GlModalVuex); expect(findModal().element).toMatchSnapshot();
expect(modal.text()).toContain(TEST_RULE.name);
expect(modal.text()).toContain(`${TEST_RULE.approvers.length} members`);
}); });
it('shows singular message', () => { it('shows singular message', () => {
...@@ -84,9 +96,7 @@ describe('Approvals ModalRuleRemove', () => { ...@@ -84,9 +96,7 @@ describe('Approvals ModalRuleRemove', () => {
}; };
factory(); factory();
const modal = wrapper.find(GlModalVuex); expect(findModal().element).toMatchSnapshot();
expect(modal.text()).toContain('1 member');
}); });
it('deletes rule when modal is submitted', () => { it('deletes rule when modal is submitted', () => {
...@@ -94,7 +104,7 @@ describe('Approvals ModalRuleRemove', () => { ...@@ -94,7 +104,7 @@ describe('Approvals ModalRuleRemove', () => {
expect(actions.deleteRule).not.toHaveBeenCalled(); expect(actions.deleteRule).not.toHaveBeenCalled();
const modal = wrapper.find(GlModalVuex); const modal = findModal();
modal.vm.$emit('ok', new Event('submit')); modal.vm.$emit('ok', new Event('submit'));
expect(actions.deleteRule).toHaveBeenCalledWith(expect.anything(), TEST_RULE.id); expect(actions.deleteRule).toHaveBeenCalledWith(expect.anything(), TEST_RULE.id);
......
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