Commit 2f4945d0 authored by wortschi's avatar wortschi

Clear modal form fields

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