Commit 25bf1cbb authored by Frédéric Caplette's avatar Frédéric Caplette

Merge branch '331933-escalation-rule-improvements' into 'master'

Escalation rule improvements

See merge request gitlab-org/gitlab!62831
parents db42252b 07b8f924
...@@ -79,7 +79,6 @@ export default { ...@@ -79,7 +79,6 @@ export default {
methods: { methods: {
addRule() { addRule() {
this.rules.push({ ...cloneDeep(defaultEscalationRule), key: this.getUid() }); this.rules.push({ ...cloneDeep(defaultEscalationRule), key: this.getUid() });
this.emitUpdate();
}, },
updateEscalationRules(index, rule) { updateEscalationRules(index, rule) {
this.rules[index] = rule; this.rules[index] = rule;
......
...@@ -38,7 +38,7 @@ export default { ...@@ -38,7 +38,7 @@ export default {
rules: [], rules: [],
}, },
validationState: { validationState: {
name: true, name: null,
rules: [], rules: [],
}, },
error: null, error: null,
...@@ -103,7 +103,7 @@ export default { ...@@ -103,7 +103,7 @@ export default {
} }
this.$refs.addUpdateEscalationPolicyModal.hide(); this.$refs.addUpdateEscalationPolicyModal.hide();
this.$emit('policyCreated'); this.$emit('policyCreated');
this.clearForm(); this.resetForm();
}, },
) )
.catch((error) => { .catch((error) => {
...@@ -124,12 +124,17 @@ export default { ...@@ -124,12 +124,17 @@ export default {
hideErrorAlert() { hideErrorAlert() {
this.error = null; this.error = null;
}, },
clearForm() { resetForm() {
this.form = { this.form = {
name: '', name: '',
description: '', description: '',
rules: [], rules: [],
}; };
this.validationState = {
name: null,
rules: [],
};
this.hideErrorAlert();
}, },
}, },
}; };
...@@ -144,7 +149,8 @@ export default { ...@@ -144,7 +149,8 @@ export default {
:action-primary="actionsProps.primary" :action-primary="actionsProps.primary"
:action-cancel="actionsProps.cancel" :action-cancel="actionsProps.cancel"
@primary.prevent="createEscalationPolicy" @primary.prevent="createEscalationPolicy"
@cancel="clearForm" @canceled="resetForm"
@close="resetForm"
> >
<gl-alert v-if="error" variant="danger" class="gl-mt-n3 gl-mb-3" @dismiss="hideErrorAlert"> <gl-alert v-if="error" variant="danger" class="gl-mt-n3 gl-mb-3" @dismiss="hideErrorAlert">
{{ error }} {{ error }}
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlCard, GlCard,
GlButton,
GlIcon, GlIcon,
GlSprintf, GlSprintf,
GlTooltipDirective as GlTooltip, GlTooltipDirective as GlTooltip,
...@@ -24,6 +25,7 @@ export const i18n = { ...@@ -24,6 +25,7 @@ export const i18n = {
noSchedules: s__( noSchedules: s__(
'EscalationPolicies|A schedule is required for adding an escalation policy. Please create an on-call schedule first.', 'EscalationPolicies|A schedule is required for adding an escalation policy. Please create an on-call schedule first.',
), ),
removeRuleLabel: s__('EscalationPolicies|Remove escalation rule'),
}, },
}, },
}; };
...@@ -38,6 +40,7 @@ export default { ...@@ -38,6 +40,7 @@ export default {
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlCard, GlCard,
GlButton,
GlIcon, GlIcon,
GlSprintf, GlSprintf,
}, },
...@@ -111,9 +114,12 @@ export default { ...@@ -111,9 +114,12 @@ export default {
<template> <template>
<gl-card class="gl-border-gray-400 gl-bg-gray-10 gl-mb-3 gl-relative"> <gl-card class="gl-border-gray-400 gl-bg-gray-10 gl-mb-3 gl-relative">
<gl-icon <gl-button
v-if="index !== 0" v-if="index !== 0"
name="close" category="tertiary"
size="small"
icon="close"
:aria-label="$options.i18n.fields.rules.removeRuleLabel"
class="gl-absolute rule-close-icon" class="gl-absolute rule-close-icon"
@click="$emit('remove-escalation-rule', index)" @click="$emit('remove-escalation-rule', index)"
/> />
......
...@@ -82,18 +82,10 @@ describe('AddEscalationPolicyForm', () => { ...@@ -82,18 +82,10 @@ describe('AddEscalationPolicyForm', () => {
expect(rules.at(1).props('rule')).toMatchObject(defaultEscalationRule); expect(rules.at(1).props('rule')).toMatchObject(defaultEscalationRule);
}); });
it('should emit updates when rule is added', async () => { it('should NOT emit updates when rule is added', async () => {
findAddRuleLink().vm.$emit('click'); findAddRuleLink().vm.$emit('click');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.emitted('update-escalation-policy-form')[0]).toMatchObject([ expect(wrapper.emitted('update-escalation-policy-form')).toBeUndefined();
{
field: 'rules',
value: [
expect.objectContaining(defaultEscalationRule),
expect.objectContaining(defaultEscalationRule),
],
},
]);
}); });
it('on rule update emitted should update rules array and emit updates up', () => { it('on rule update emitted should update rules array and emit updates up', () => {
......
...@@ -90,14 +90,30 @@ describe('AddEscalationPolicyModal', () => { ...@@ -90,14 +90,30 @@ describe('AddEscalationPolicyModal', () => {
expect(alert.text()).toContain(error); expect(alert.text()).toContain(error);
}); });
it('clears the form on modal close', () => { it('clears the form on modal cancel', () => {
expect(wrapper.vm.form).toEqual(mockPolicy); expect(wrapper.vm.form).toEqual(mockPolicy);
findModal().vm.$emit('cancel', { preventDefault: jest.fn() }); findModal().vm.$emit('canceled', { preventDefault: jest.fn() });
expect(wrapper.vm.form).toEqual({ expect(wrapper.vm.form).toEqual({
name: '', name: '',
description: '', description: '',
rules: [], rules: [],
}); });
expect(wrapper.vm.validationState).toEqual({
name: null,
rules: [],
});
});
it('clears the validation state on modal cancel', () => {
expect(wrapper.vm.validationState.name).toBe(null);
findEscalationPolicyForm().vm.$emit('update-escalation-policy-form', {
field: 'name',
value: '',
});
expect(wrapper.vm.validationState.name).toBe(false);
findModal().vm.$emit('canceled', { preventDefault: jest.fn() });
expect(wrapper.vm.validationState.name).toBe(null);
}); });
}); });
......
...@@ -13108,6 +13108,9 @@ msgstr "" ...@@ -13108,6 +13108,9 @@ msgstr ""
msgid "EscalationPolicies|IF alert is not %{alertStatus} in %{minutes} minutes" msgid "EscalationPolicies|IF alert is not %{alertStatus} in %{minutes} minutes"
msgstr "" msgstr ""
msgid "EscalationPolicies|Remove escalation rule"
msgstr ""
msgid "EscalationPolicies|Select schedule" msgid "EscalationPolicies|Select schedule"
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