Commit 2f4945d0 authored by wortschi's avatar wortschi

Clear modal form fields

parent 9b3bc6b3
...@@ -53,8 +53,11 @@ export default { ...@@ -53,8 +53,11 @@ export default {
}, },
cancelOptions() { cancelOptions() {
return { return {
text: this.$options.i18n.cancel, button: {
attributes: [{ disabled: this.loading }], text: this.$options.i18n.cancel,
attributes: [{ disabled: this.loading }],
},
callback: this.resetForm,
}; };
}, },
primaryOptions() { primaryOptions() {
...@@ -115,6 +118,7 @@ export default { ...@@ -115,6 +118,7 @@ export default {
if (errors.length) { if (errors.length) {
this.errors = errors; this.errors = errors;
} else { } else {
this.resetForm();
this.closeModal(); this.closeModal();
} }
} catch (error) { } catch (error) {
...@@ -161,6 +165,11 @@ export default { ...@@ -161,6 +165,11 @@ export default {
checkboxValuesFromSegment() { checkboxValuesFromSegment() {
return this.segment.groups.map(({ id }) => getIdFromGraphQLId(id)); return this.segment.groups.map(({ id }) => getIdFromGraphQLId(id));
}, },
resetForm() {
this.name = this.segment?.name || '';
this.checkboxValues = this.segment ? this.checkboxValuesFromSegment() : [];
this.filter = '';
},
}, },
devopsSegmentModalId: DEVOPS_ADOPTION_SEGMENT_MODAL_ID, devopsSegmentModalId: DEVOPS_ADOPTION_SEGMENT_MODAL_ID,
}; };
...@@ -173,8 +182,10 @@ export default { ...@@ -173,8 +182,10 @@ export default {
size="sm" size="sm"
scrollable scrollable
:action-primary="primaryOptions.button" :action-primary="primaryOptions.button"
:action-cancel="cancelOptions" :action-cancel="cancelOptions.button"
@primary.prevent="primaryOptions.callback" @primary.prevent="primaryOptions.callback"
@canceled="cancelOptions.callback"
@hide="resetForm"
> >
<gl-alert v-if="errors.length" variant="danger" class="gl-mb-3" @dismiss="clearErrors"> <gl-alert v-if="errors.length" variant="danger" class="gl-mb-3" @dismiss="clearErrors">
{{ displayError }} {{ displayError }}
......
---
title: 'DevOps Adoption: Clear form when creating a new segment'
merge_request: 50766
author:
type: fixed
...@@ -298,6 +298,15 @@ describe('DevopsAdoptionSegmentModal', () => { ...@@ -298,6 +298,15 @@ describe('DevopsAdoptionSegmentModal', () => {
it('closes the modal after a successful mutation', async () => { it('closes the modal after a successful mutation', async () => {
expect(wrapper.vm.$refs.modal.hide).toHaveBeenCalled(); expect(wrapper.vm.$refs.modal.hide).toHaveBeenCalled();
}); });
it('resets the form fields', async () => {
const name = segment ? 'Segment 1' : '';
const checkboxValues = segment ? [1] : [];
expect(wrapper.vm.name).toBe(name);
expect(wrapper.vm.checkboxValues).toEqual(checkboxValues);
expect(wrapper.vm.filter).toBe('');
});
}); });
describe('error handling', () => { describe('error handling', () => {
......
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