Commit ad8c8059 authored by Jiaan Louw's avatar Jiaan Louw Committed by Denys Mishunov

Update approval settings to toast on success

Updates the group and project-level approval settings to display
a toast on success rather than rendering a in-page alert.

Changelog: changed
EE: true
parent 5f617d55
...@@ -45,7 +45,6 @@ export default { ...@@ -45,7 +45,6 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
isLoading: (state) => state.approvalSettings.isLoading, isLoading: (state) => state.approvalSettings.isLoading,
isUpdated: (state) => state.approvalSettings.isUpdated,
settings: (state) => state.approvalSettings.settings, settings: (state) => state.approvalSettings.settings,
errorMessage: (state) => state.approvalSettings.errorMessage, errorMessage: (state) => state.approvalSettings.errorMessage,
preventAuthorApproval: (state) => state.approvalSettings.settings.preventAuthorApproval, preventAuthorApproval: (state) => state.approvalSettings.settings.preventAuthorApproval,
...@@ -73,7 +72,6 @@ export default { ...@@ -73,7 +72,6 @@ export default {
'fetchSettings', 'fetchSettings',
'updateSettings', 'updateSettings',
'dismissErrorMessage', 'dismissErrorMessage',
'dismissSuccessMessage',
'setPreventAuthorApproval', 'setPreventAuthorApproval',
'setPreventCommittersApproval', 'setPreventCommittersApproval',
'setPreventMrApprovalRuleEdit', 'setPreventMrApprovalRuleEdit',
...@@ -82,6 +80,7 @@ export default { ...@@ -82,6 +80,7 @@ export default {
]), ]),
async onSubmit() { async onSubmit() {
await this.updateSettings(this.approvalSettingsPath); await this.updateSettings(this.approvalSettingsPath);
this.$toast.show(APPROVAL_SETTINGS_I18N.savingSuccessMessage);
}, },
lockedText({ locked, inheritedFrom }) { lockedText({ locked, inheritedFrom }) {
if (!locked) { if (!locked) {
...@@ -115,17 +114,6 @@ export default { ...@@ -115,17 +114,6 @@ export default {
> >
{{ errorMessage }} {{ errorMessage }}
</gl-alert> </gl-alert>
<gl-alert
v-if="isUpdated"
variant="success"
:dismissible="true"
:contained="true"
class="gl-mb-6"
data-testid="success-alert"
@dismiss="dismissSuccessMessage"
>
{{ $options.i18n.savingSuccessMessage }}
</gl-alert>
<gl-form v-if="hasSettings" @submit.prevent="onSubmit"> <gl-form v-if="hasSettings" @submit.prevent="onSubmit">
<label class="label-bold"> {{ $options.i18n.approvalSettingsHeader }} </label> <label class="label-bold"> {{ $options.i18n.approvalSettingsHeader }} </label>
<p> <p>
......
import Vue from 'vue'; import Vue from 'vue';
import { GlToast } from '@gitlab/ui';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import GroupSettingsApp from './components/group_settings/app.vue'; import GroupSettingsApp from './components/group_settings/app.vue';
import { mergeRequestApprovalSettingsMappers } from './mappers'; import { mergeRequestApprovalSettingsMappers } from './mappers';
...@@ -15,6 +16,8 @@ const mountGroupApprovalSettings = (el) => { ...@@ -15,6 +16,8 @@ const mountGroupApprovalSettings = (el) => {
approvalSettings: approvalSettingsModule(mergeRequestApprovalSettingsMappers), approvalSettings: approvalSettingsModule(mergeRequestApprovalSettingsMappers),
}); });
Vue.use(GlToast);
return new Vue({ return new Vue({
el, el,
store, store,
......
import Vue from 'vue'; import Vue from 'vue';
import { GlToast } from '@gitlab/ui';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import ProjectSettingsApp from './components/project_settings/app.vue'; import ProjectSettingsApp from './components/project_settings/app.vue';
import { projectApprovalsMappers, mergeRequestApprovalSettingsMappers } from './mappers'; import { projectApprovalsMappers, mergeRequestApprovalSettingsMappers } from './mappers';
...@@ -39,6 +40,8 @@ export default function mountProjectSettingsApprovals(el) { ...@@ -39,6 +40,8 @@ export default function mountProjectSettingsApprovals(el) {
canModifyCommiterSettings: parseBoolean(el.dataset.canModifyCommiterSettings), canModifyCommiterSettings: parseBoolean(el.dataset.canModifyCommiterSettings),
}); });
Vue.use(GlToast);
return new Vue({ return new Vue({
el, el,
store, store,
......
...@@ -38,10 +38,6 @@ export default (mapStateToPayload, updateMethod = 'put') => ({ ...@@ -38,10 +38,6 @@ export default (mapStateToPayload, updateMethod = 'put') => ({
}); });
}, },
dismissSuccessMessage({ commit }) {
commit(types.DISMISS_SUCCESS_MESSAGE);
},
dismissErrorMessage({ commit }) { dismissErrorMessage({ commit }) {
commit(types.DISMISS_ERROR_MESSAGE); commit(types.DISMISS_ERROR_MESSAGE);
}, },
......
...@@ -18,22 +18,17 @@ export default (mapDataToState) => ({ ...@@ -18,22 +18,17 @@ export default (mapDataToState) => ({
}, },
[types.REQUEST_UPDATE_SETTINGS](state) { [types.REQUEST_UPDATE_SETTINGS](state) {
state.isLoading = true; state.isLoading = true;
state.isUpdated = false;
state.errorMessage = ''; state.errorMessage = '';
}, },
[types.UPDATE_SETTINGS_SUCCESS](state, data) { [types.UPDATE_SETTINGS_SUCCESS](state, data) {
state.settings = mapDataToState(data); state.settings = mapDataToState(data);
state.initialSettings = cloneDeep(state.settings); state.initialSettings = cloneDeep(state.settings);
state.isLoading = false; state.isLoading = false;
state.isUpdated = true;
}, },
[types.UPDATE_SETTINGS_ERROR](state) { [types.UPDATE_SETTINGS_ERROR](state) {
state.isLoading = false; state.isLoading = false;
state.errorMessage = APPROVAL_SETTINGS_I18N.savingErrorMessage; state.errorMessage = APPROVAL_SETTINGS_I18N.savingErrorMessage;
}, },
[types.DISMISS_SUCCESS_MESSAGE](state) {
state.isUpdated = false;
},
[types.DISMISS_ERROR_MESSAGE](state) { [types.DISMISS_ERROR_MESSAGE](state) {
state.errorMessage = ''; state.errorMessage = '';
}, },
......
...@@ -2,6 +2,5 @@ export default () => ({ ...@@ -2,6 +2,5 @@ export default () => ({
settings: {}, settings: {},
initialSettings: {}, initialSettings: {},
isLoading: false, isLoading: false,
isUpdated: false,
errorMessage: '', errorMessage: '',
}); });
...@@ -36,11 +36,17 @@ describe('ApprovalSettings', () => { ...@@ -36,11 +36,17 @@ describe('ApprovalSettings', () => {
jest.spyOn(actions, 'fetchSettings').mockImplementation(); jest.spyOn(actions, 'fetchSettings').mockImplementation();
jest.spyOn(actions, 'updateSettings').mockImplementation(); jest.spyOn(actions, 'updateSettings').mockImplementation();
jest.spyOn(actions, 'dismissErrorMessage').mockImplementation(); jest.spyOn(actions, 'dismissErrorMessage').mockImplementation();
jest.spyOn(actions, 'dismissSuccessMessage').mockImplementation();
store = createStore({ approvalSettings: module, approvals: projectSettingsModule() }); store = createStore({ approvalSettings: module, approvals: projectSettingsModule() });
}; };
const showToast = jest.fn();
const mocks = {
$toast: {
show: showToast,
},
};
const createWrapper = (props = {}) => { const createWrapper = (props = {}) => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
shallowMount(ApprovalSettings, { shallowMount(ApprovalSettings, {
...@@ -51,6 +57,7 @@ describe('ApprovalSettings', () => { ...@@ -51,6 +57,7 @@ describe('ApprovalSettings', () => {
...props, ...props,
}, },
stubs: { GlButton }, stubs: { GlButton },
mocks,
}), }),
); );
}; };
...@@ -254,6 +261,10 @@ describe('ApprovalSettings', () => { ...@@ -254,6 +261,10 @@ describe('ApprovalSettings', () => {
expect(actions.dismissErrorMessage).toHaveBeenCalled(); expect(actions.dismissErrorMessage).toHaveBeenCalled();
}); });
it('does not show a toast message', () => {
expect(showToast).not.toHaveBeenCalled();
});
}); });
describe('if the form updates', () => { describe('if the form updates', () => {
...@@ -272,15 +283,8 @@ describe('ApprovalSettings', () => { ...@@ -272,15 +283,8 @@ describe('ApprovalSettings', () => {
); );
}); });
it('renders the alert', () => { it('shows the success toast', () => {
expect(findErrorAlert().exists()).toBe(false); expect(showToast).toHaveBeenCalledWith(APPROVAL_SETTINGS_I18N.savingSuccessMessage);
expect(findSuccessAlert().text()).toBe(APPROVAL_SETTINGS_I18N.savingSuccessMessage);
});
it('dismisses the alert', async () => {
await findSuccessAlert().vm.$emit('dismiss');
expect(actions.dismissSuccessMessage).toHaveBeenCalled();
}); });
}); });
}); });
......
...@@ -117,18 +117,6 @@ describe('EE approvals group settings module actions', () => { ...@@ -117,18 +117,6 @@ describe('EE approvals group settings module actions', () => {
}); });
}); });
describe('dismissSuccessMessage', () => {
it('commits DISMISS_SUCCESS_MESSAGE', () => {
return testAction(
actions.dismissSuccessMessage,
{},
state,
[{ type: types.DISMISS_SUCCESS_MESSAGE }],
[],
);
});
});
describe('dismissErrorMessage', () => { describe('dismissErrorMessage', () => {
it('commits DISMISS_ERROR_MESSAGE', () => { it('commits DISMISS_ERROR_MESSAGE', () => {
return testAction( return testAction(
......
...@@ -52,7 +52,6 @@ describe('Group settings store mutations', () => { ...@@ -52,7 +52,6 @@ describe('Group settings store mutations', () => {
mutations.REQUEST_UPDATE_SETTINGS(state); mutations.REQUEST_UPDATE_SETTINGS(state);
expect(state.isLoading).toBe(true); expect(state.isLoading).toBe(true);
expect(state.isUpdated).toBe(false);
expect(state.errorMessage).toBe(''); expect(state.errorMessage).toBe('');
}); });
}); });
...@@ -64,7 +63,6 @@ describe('Group settings store mutations', () => { ...@@ -64,7 +63,6 @@ describe('Group settings store mutations', () => {
expect(mapperFn).toHaveBeenCalledWith(settings); expect(mapperFn).toHaveBeenCalledWith(settings);
expect(state.settings).toStrictEqual(settings); expect(state.settings).toStrictEqual(settings);
expect(state.isLoading).toBe(false); expect(state.isLoading).toBe(false);
expect(state.isUpdated).toBe(true);
}); });
}); });
...@@ -77,14 +75,6 @@ describe('Group settings store mutations', () => { ...@@ -77,14 +75,6 @@ describe('Group settings store mutations', () => {
}); });
}); });
describe('DISMISS_SUCCESS_MESSAGE', () => {
it('resets isUpdated', () => {
mutations.DISMISS_SUCCESS_MESSAGE(state);
expect(state.isUpdated).toBe(false);
});
});
describe('DISMISS_ERROR_MESSAGE', () => { describe('DISMISS_ERROR_MESSAGE', () => {
it('resets errorMessage', () => { it('resets errorMessage', () => {
mutations.DISMISS_ERROR_MESSAGE(state); mutations.DISMISS_ERROR_MESSAGE(state);
......
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