Commit 9e7d2ed9 authored by Mark Florian's avatar Mark Florian Committed by Phil Hughes

Normalize Vuex actions/mutations

This normalizes the Vuex action and mutation names according to our
established [request/receive/fetch pattern][0].

Part of [Remove parsed_license_report flag from front end code][1].

The batch case-preserving renaming was achieved using [repren][2]:

    repren --word-breaks --preserve-case -p patterns ee

where the `patterns` file contains:

    requestLoadManagedLicenses	requestManagedLicenses
    receiveLoadManagedLicenses	receiveManagedLicensesSuccess
    receiveLoadManagedLicensesError	receiveManagedLicensesError
    loadManagedLicenses	fetchManagedLicenses
    #
    requestLoadParsedLicenseReport	requestParsedLicenseReport
    receiveLoadParsedLicenseReport	receiveParsedLicenseReportSuccess
    receiveLoadParsedLicenseReportError	receiveParsedLicenseReportError
    receiveLoadLicenseReportError	receiveParsedLicenseReportError
    loadParsedLicenseReport	fetchParsedLicenseReport

Note that the `receiveLoadLicenseReportError` identifier is also being
renamed to `receiveParsedLicenseReportError`, since it is functionally
the same as the `receiveLoadParsedLicenseReportError` action/mutation.
The resulting duplicates will be removed by the next commit.

[0]: https://docs.gitlab.com/ce/development/fe_guide/vuex.html#actions-pattern-request-and-receive-namespaces
[1]: https://gitlab.com/gitlab-org/gitlab/issues/37271
[2]: https://github.com/jlevy/repren
parent a5c0130e
...@@ -37,10 +37,10 @@ export default { ...@@ -37,10 +37,10 @@ export default {
this.setAPISettings({ this.setAPISettings({
apiUrlManageLicenses: this.apiUrl, apiUrlManageLicenses: this.apiUrl,
}); });
this.loadManagedLicenses(); this.fetchManagedLicenses();
}, },
methods: { methods: {
...mapActions(['loadManagedLicenses', 'setAPISettings', 'setLicenseApproval']), ...mapActions(['fetchManagedLicenses', 'setAPISettings', 'setLicenseApproval']),
openAddLicenseForm() { openAddLicenseForm() {
this.formIsOpen = true; this.formIsOpen = true;
}, },
......
...@@ -95,10 +95,10 @@ export default { ...@@ -95,10 +95,10 @@ export default {
licensesApiPath, licensesApiPath,
}); });
this.loadParsedLicenseReport(); this.fetchParsedLicenseReport();
}, },
methods: { methods: {
...mapActions(['setAPISettings', 'loadParsedLicenseReport']), ...mapActions(['setAPISettings', 'fetchParsedLicenseReport']),
}, },
}; };
</script> </script>
......
...@@ -20,7 +20,7 @@ export const requestDeleteLicense = ({ commit }) => { ...@@ -20,7 +20,7 @@ export const requestDeleteLicense = ({ commit }) => {
}; };
export const receiveDeleteLicense = ({ commit, dispatch }) => { export const receiveDeleteLicense = ({ commit, dispatch }) => {
commit(types.RECEIVE_DELETE_LICENSE); commit(types.RECEIVE_DELETE_LICENSE);
dispatch('loadManagedLicenses'); dispatch('fetchManagedLicenses');
}; };
export const receiveDeleteLicenseError = ({ commit }, error) => { export const receiveDeleteLicenseError = ({ commit }, error) => {
commit(types.RECEIVE_DELETE_LICENSE_ERROR, error); commit(types.RECEIVE_DELETE_LICENSE_ERROR, error);
...@@ -39,57 +39,53 @@ export const deleteLicense = ({ dispatch, state }) => { ...@@ -39,57 +39,53 @@ export const deleteLicense = ({ dispatch, state }) => {
}); });
}; };
export const requestLoadManagedLicenses = ({ commit }) => { export const requestManagedLicenses = ({ commit }) => {
commit(types.REQUEST_LOAD_MANAGED_LICENSES); commit(types.REQUEST_MANAGED_LICENSES);
}; };
export const receiveLoadManagedLicenses = ({ commit }, licenses) => { export const receiveManagedLicensesSuccess = ({ commit }, licenses) => {
commit(types.RECEIVE_LOAD_MANAGED_LICENSES, licenses); commit(types.RECEIVE_MANAGED_LICENSES_SUCCESS, licenses);
}; };
export const receiveLoadManagedLicensesError = ({ commit }, error) => { export const receiveManagedLicensesError = ({ commit }, error) => {
commit(types.RECEIVE_LOAD_MANAGED_LICENSES_ERROR, error); commit(types.RECEIVE_MANAGED_LICENSES_ERROR, error);
}; };
export const loadManagedLicenses = ({ dispatch, state }) => { export const fetchManagedLicenses = ({ dispatch, state }) => {
dispatch('requestLoadManagedLicenses'); dispatch('requestManagedLicenses');
const { apiUrlManageLicenses } = state; const { apiUrlManageLicenses } = state;
return axios return axios
.get(apiUrlManageLicenses, { params: { per_page: 100 } }) .get(apiUrlManageLicenses, { params: { per_page: 100 } })
.then(({ data }) => { .then(({ data }) => {
dispatch('receiveLoadManagedLicenses', data); dispatch('receiveManagedLicensesSuccess', data);
}) })
.catch(error => { .catch(error => {
dispatch('receiveLoadManagedLicensesError', error); dispatch('receiveManagedLicensesError', error);
}); });
}; };
export const requestLoadParsedLicenseReport = ({ commit }) => { export const requestParsedLicenseReport = ({ commit }) => {
commit(types.REQUEST_LOAD_PARSED_LICENSE_REPORT); commit(types.REQUEST_PARSED_LICENSE_REPORT);
}; };
export const receiveLoadParsedLicenseReport = ({ commit }, reports) => { export const receiveParsedLicenseReportSuccess = ({ commit }, reports) => {
commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT, reports); commit(types.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS, reports);
}; };
export const receiveLoadParsedLicenseReportError = ({ commit }, error) => { export const receiveParsedLicenseReportError = ({ commit }, error) => {
commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR, error); commit(types.RECEIVE_PARSED_LICENSE_REPORT_ERROR, error);
}; };
export const loadParsedLicenseReport = ({ dispatch, state }) => { export const fetchParsedLicenseReport = ({ dispatch, state }) => {
dispatch('requestLoadParsedLicenseReport'); dispatch('requestParsedLicenseReport');
pollUntilComplete(state.licensesApiPath) pollUntilComplete(state.licensesApiPath)
.then(({ data }) => { .then(({ data }) => {
const newLicenses = (data.new_licenses || data).map(convertToOldReportFormat); const newLicenses = (data.new_licenses || data).map(convertToOldReportFormat);
const existingLicenses = (data.existing_licenses || []).map(convertToOldReportFormat); const existingLicenses = (data.existing_licenses || []).map(convertToOldReportFormat);
dispatch('receiveLoadParsedLicenseReport', { newLicenses, existingLicenses }); dispatch('receiveParsedLicenseReportSuccess', { newLicenses, existingLicenses });
}) })
.catch(error => { .catch(error => {
dispatch('receiveLoadLicenseReportError', error); dispatch('receiveParsedLicenseReportError', error);
}); });
}; };
export const receiveLoadLicenseReportError = ({ commit }, error) => {
commit(types.RECEIVE_LOAD_LICENSE_REPORT_ERROR, error);
};
export const requestSetLicenseApproval = ({ commit }) => { export const requestSetLicenseApproval = ({ commit }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL); commit(types.REQUEST_SET_LICENSE_APPROVAL);
}; };
...@@ -101,9 +97,9 @@ export const receiveSetLicenseApproval = ({ commit, dispatch, state }) => { ...@@ -101,9 +97,9 @@ export const receiveSetLicenseApproval = ({ commit, dispatch, state }) => {
// the project settings page. // the project settings page.
// https://gitlab.com/gitlab-org/gitlab/issues/201867 // https://gitlab.com/gitlab-org/gitlab/issues/201867
if (state.licensesApiPath) { if (state.licensesApiPath) {
dispatch('loadParsedLicenseReport'); dispatch('fetchParsedLicenseReport');
} else { } else {
dispatch('loadManagedLicenses'); dispatch('fetchManagedLicenses');
} }
}; };
export const receiveSetLicenseApprovalError = ({ commit }, error) => { export const receiveSetLicenseApprovalError = ({ commit }, error) => {
......
export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE'; export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE';
export const RECEIVE_DELETE_LICENSE_ERROR = 'RECEIVE_DELETE_LICENSE_ERROR'; export const RECEIVE_DELETE_LICENSE_ERROR = 'RECEIVE_DELETE_LICENSE_ERROR';
export const RECEIVE_LOAD_LICENSE_REPORT_ERROR = 'RECEIVE_LOAD_LICENSE_REPORT_ERROR'; export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCESS';
export const RECEIVE_LOAD_MANAGED_LICENSES = 'RECEIVE_LOAD_MANAGED_LICENSES'; export const RECEIVE_MANAGED_LICENSES_ERROR = 'RECEIVE_MANAGED_LICENSES_ERROR';
export const RECEIVE_LOAD_MANAGED_LICENSES_ERROR = 'RECEIVE_LOAD_MANAGED_LICENSES_ERROR'; export const RECEIVE_PARSED_LICENSE_REPORT_SUCCESS = 'RECEIVE_PARSED_LICENSE_REPORT_SUCCESS';
export const RECEIVE_LOAD_PARSED_LICENSE_REPORT = 'RECEIVE_LOAD_PARSED_LICENSE_REPORT'; export const RECEIVE_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_PARSED_LICENSE_REPORT_ERROR';
export const RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR';
export const RECEIVE_SET_LICENSE_APPROVAL = 'RECEIVE_SET_LICENSE_APPROVAL'; export const RECEIVE_SET_LICENSE_APPROVAL = 'RECEIVE_SET_LICENSE_APPROVAL';
export const RECEIVE_SET_LICENSE_APPROVAL_ERROR = 'RECEIVE_SET_LICENSE_APPROVAL_ERROR'; export const RECEIVE_SET_LICENSE_APPROVAL_ERROR = 'RECEIVE_SET_LICENSE_APPROVAL_ERROR';
export const REQUEST_DELETE_LICENSE = 'REQUEST_DELETE_LICENSE'; export const REQUEST_DELETE_LICENSE = 'REQUEST_DELETE_LICENSE';
export const REQUEST_LOAD_MANAGED_LICENSES = 'REQUEST_LOAD_MANAGED_LICENSES'; export const REQUEST_MANAGED_LICENSES = 'REQUEST_MANAGED_LICENSES';
export const REQUEST_LOAD_PARSED_LICENSE_REPORT = 'REQUEST_LOAD_PARSED_LICENSE_REPORT'; export const REQUEST_PARSED_LICENSE_REPORT = 'REQUEST_PARSED_LICENSE_REPORT';
export const REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL'; export const REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL';
export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL'; export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL';
export const SET_API_SETTINGS = 'SET_API_SETTINGS'; export const SET_API_SETTINGS = 'SET_API_SETTINGS';
......
...@@ -16,7 +16,7 @@ export default { ...@@ -16,7 +16,7 @@ export default {
Object.assign(state, data); Object.assign(state, data);
}, },
[types.RECEIVE_LOAD_MANAGED_LICENSES](state, licenses = []) { [types.RECEIVE_MANAGED_LICENSES_SUCCESS](state, licenses = []) {
const managedLicenses = licenses.map(normalizeLicense).reverse(); const managedLicenses = licenses.map(normalizeLicense).reverse();
Object.assign(state, { Object.assign(state, {
...@@ -25,20 +25,20 @@ export default { ...@@ -25,20 +25,20 @@ export default {
loadManagedLicensesError: false, loadManagedLicensesError: false,
}); });
}, },
[types.RECEIVE_LOAD_MANAGED_LICENSES_ERROR](state, error) { [types.RECEIVE_MANAGED_LICENSES_ERROR](state, error) {
Object.assign(state, { Object.assign(state, {
managedLicenses: [], managedLicenses: [],
isLoadingManagedLicenses: false, isLoadingManagedLicenses: false,
loadManagedLicensesError: error, loadManagedLicensesError: error,
}); });
}, },
[types.REQUEST_LOAD_MANAGED_LICENSES](state) { [types.REQUEST_MANAGED_LICENSES](state) {
Object.assign(state, { Object.assign(state, {
isLoadingManagedLicenses: true, isLoadingManagedLicenses: true,
}); });
}, },
[types.RECEIVE_LOAD_PARSED_LICENSE_REPORT](state, { newLicenses, existingLicenses }) { [types.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS](state, { newLicenses, existingLicenses }) {
Object.assign(state, { Object.assign(state, {
newLicenses, newLicenses,
existingLicenses, existingLicenses,
...@@ -46,26 +46,18 @@ export default { ...@@ -46,26 +46,18 @@ export default {
loadLicenseReportError: false, loadLicenseReportError: false,
}); });
}, },
[types.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR](state, error) { [types.RECEIVE_PARSED_LICENSE_REPORT_ERROR](state, error) {
Object.assign(state, { Object.assign(state, {
isLoadingLicenseReport: false, isLoadingLicenseReport: false,
loadLicenseReportError: error, loadLicenseReportError: error,
}); });
}, },
[types.REQUEST_LOAD_PARSED_LICENSE_REPORT](state) { [types.REQUEST_PARSED_LICENSE_REPORT](state) {
Object.assign(state, { Object.assign(state, {
isLoadingLicenseReport: true, isLoadingLicenseReport: true,
}); });
}, },
[types.RECEIVE_LOAD_LICENSE_REPORT_ERROR](state, error) {
Object.assign(state, {
managedLicenses: [],
isLoadingLicenseReport: false,
loadLicenseReportError: error,
});
},
[types.RECEIVE_DELETE_LICENSE](state) { [types.RECEIVE_DELETE_LICENSE](state) {
Object.assign(state, { Object.assign(state, {
isDeleting: false, isDeleting: false,
......
...@@ -37,7 +37,7 @@ describe('LicenseManagement', () => { ...@@ -37,7 +37,7 @@ describe('LicenseManagement', () => {
...state, ...state,
}, },
actions: { actions: {
loadManagedLicenses: noop, fetchManagedLicenses: noop,
setAPISettings: noop, setAPISettings: noop,
setLicenseApproval: noop, setLicenseApproval: noop,
...actionMocks, ...actionMocks,
...@@ -111,13 +111,13 @@ describe('LicenseManagement', () => { ...@@ -111,13 +111,13 @@ describe('LicenseManagement', () => {
it('should set api settings after mount and init API calls', () => { it('should set api settings after mount and init API calls', () => {
const setAPISettingsMock = jest.fn(); const setAPISettingsMock = jest.fn();
const loadManagedLicensesMock = jest.fn(); const fetchManagedLicensesMock = jest.fn();
createComponent({ createComponent({
state: { isLoadingManagedLicenses: false }, state: { isLoadingManagedLicenses: false },
actionMocks: { actionMocks: {
setAPISettings: setAPISettingsMock, setAPISettings: setAPISettingsMock,
loadManagedLicenses: loadManagedLicensesMock, fetchManagedLicenses: fetchManagedLicensesMock,
}, },
}); });
...@@ -129,6 +129,6 @@ describe('LicenseManagement', () => { ...@@ -129,6 +129,6 @@ describe('LicenseManagement', () => {
undefined, undefined,
); );
expect(loadManagedLicensesMock).toHaveBeenCalledWith(expect.any(Object), undefined, undefined); expect(fetchManagedLicensesMock).toHaveBeenCalledWith(expect.any(Object), undefined, undefined);
}); });
}); });
...@@ -51,8 +51,8 @@ describe('License Report MR Widget', () => { ...@@ -51,8 +51,8 @@ describe('License Report MR Widget', () => {
const defaultActions = { const defaultActions = {
setAPISettings: () => {}, setAPISettings: () => {},
loadManagedLicenses: () => {}, fetchManagedLicenses: () => {},
loadParsedLicenseReport: () => {}, fetchParsedLicenseReport: () => {},
}; };
const mountComponent = ({ const mountComponent = ({
...@@ -219,7 +219,9 @@ describe('License Report MR Widget', () => { ...@@ -219,7 +219,9 @@ describe('License Report MR Widget', () => {
it('should init store after mount', () => { it('should init store after mount', () => {
const actions = { const actions = {
setAPISettings: jasmine.createSpy('setAPISettings').and.callFake(() => {}), setAPISettings: jasmine.createSpy('setAPISettings').and.callFake(() => {}),
loadParsedLicenseReport: jasmine.createSpy('loadParsedLicenseReport').and.callFake(() => {}), fetchParsedLicenseReport: jasmine
.createSpy('fetchParsedLicenseReport')
.and.callFake(() => {}),
}; };
vm = mountComponent({ actions }); vm = mountComponent({ actions });
...@@ -233,7 +235,7 @@ describe('License Report MR Widget', () => { ...@@ -233,7 +235,7 @@ describe('License Report MR Widget', () => {
undefined, undefined,
); );
expect(actions.loadParsedLicenseReport).toHaveBeenCalledWith( expect(actions.fetchParsedLicenseReport).toHaveBeenCalledWith(
jasmine.any(Object), jasmine.any(Object),
undefined, undefined,
undefined, undefined,
......
...@@ -125,7 +125,7 @@ describe('License store mutations', () => { ...@@ -125,7 +125,7 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_LOAD_MANAGED_LICENSES', () => { describe('RECEIVE_MANAGED_LICENSES_SUCCESS', () => {
it('sets isLoadingManagedLicenses and loadManagedLicensesError to false and saves managed licenses', () => { it('sets isLoadingManagedLicenses and loadManagedLicensesError to false and saves managed licenses', () => {
store.replaceState({ store.replaceState({
...store.state, ...store.state,
...@@ -134,7 +134,7 @@ describe('License store mutations', () => { ...@@ -134,7 +134,7 @@ describe('License store mutations', () => {
loadManagedLicensesError: true, loadManagedLicensesError: true,
}); });
store.commit(types.RECEIVE_LOAD_MANAGED_LICENSES, [ store.commit(types.RECEIVE_MANAGED_LICENSES_SUCCESS, [
{ name: 'Foo', approval_status: LICENSE_APPROVAL_STATUS.approved }, { name: 'Foo', approval_status: LICENSE_APPROVAL_STATUS.approved },
]); ]);
...@@ -147,7 +147,7 @@ describe('License store mutations', () => { ...@@ -147,7 +147,7 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_LOAD_MANAGED_LICENSES_ERROR', () => { describe('RECEIVE_MANAGED_LICENSES_ERROR', () => {
it('sets isLoadingManagedLicenses to true and saves the error', () => { it('sets isLoadingManagedLicenses to true and saves the error', () => {
const error = new Error('test'); const error = new Error('test');
store.replaceState({ store.replaceState({
...@@ -156,50 +156,34 @@ describe('License store mutations', () => { ...@@ -156,50 +156,34 @@ describe('License store mutations', () => {
loadManagedLicensesError: false, loadManagedLicensesError: false,
}); });
store.commit(types.RECEIVE_LOAD_MANAGED_LICENSES_ERROR, error); store.commit(types.RECEIVE_MANAGED_LICENSES_ERROR, error);
expect(store.state.isLoadingManagedLicenses).toBe(false); expect(store.state.isLoadingManagedLicenses).toBe(false);
expect(store.state.loadManagedLicensesError).toBe(error); expect(store.state.loadManagedLicensesError).toBe(error);
}); });
}); });
describe('REQUEST_LOAD_MANAGED_LICENSES', () => { describe('REQUEST_MANAGED_LICENSES', () => {
it('sets isLoadingManagedLicenses to true', () => { it('sets isLoadingManagedLicenses to true', () => {
store.replaceState({ store.replaceState({
...store.state, ...store.state,
isLoadingManagedLicenses: true, isLoadingManagedLicenses: true,
}); });
store.commit(types.REQUEST_LOAD_MANAGED_LICENSES); store.commit(types.REQUEST_MANAGED_LICENSES);
expect(store.state.isLoadingManagedLicenses).toBe(true); expect(store.state.isLoadingManagedLicenses).toBe(true);
}); });
}); });
describe('RECEIVE_LOAD_LICENSE_REPORT_ERROR', () => { describe('RECEIVE_PARSED_LICENSE_REPORT_SUCCESS', () => {
it('sets isLoadingLicenseReport to true and saves the error', () => {
const error = new Error('test');
store.replaceState({
...store.state,
isLoadingLicenseReport: true,
loadLicenseReportError: false,
});
store.commit(types.RECEIVE_LOAD_LICENSE_REPORT_ERROR, error);
expect(store.state.isLoadingLicenseReport).toBe(false);
expect(store.state.loadLicenseReportError).toBe(error);
});
});
describe('RECEIVE_LOAD_PARSED_LICENSE_REPORT', () => {
const newLicenses = []; const newLicenses = [];
const existingLicenses = []; const existingLicenses = [];
beforeEach(() => { beforeEach(() => {
store.state.isLoadingLicenseReport = true; store.state.isLoadingLicenseReport = true;
store.state.loadLicenseReportError = new Error('test'); store.state.loadLicenseReportError = new Error('test');
store.commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT, { newLicenses, existingLicenses }); store.commit(types.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS, { newLicenses, existingLicenses });
}); });
it('should set the new and existing reports', () => { it('should set the new and existing reports', () => {
...@@ -213,12 +197,12 @@ describe('License store mutations', () => { ...@@ -213,12 +197,12 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR', () => { describe('RECEIVE_PARSED_LICENSE_REPORT_ERROR', () => {
const error = new Error('test'); const error = new Error('test');
beforeEach(() => { beforeEach(() => {
store.state.isLoadingLicenseReport = true; store.state.isLoadingLicenseReport = true;
store.state.loadLicenseReportError = false; store.state.loadLicenseReportError = false;
store.commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR, error); store.commit(types.RECEIVE_PARSED_LICENSE_REPORT_ERROR, error);
}); });
it('should set the error on the state', () => { it('should set the error on the state', () => {
...@@ -230,10 +214,10 @@ describe('License store mutations', () => { ...@@ -230,10 +214,10 @@ describe('License store mutations', () => {
}); });
}); });
describe('REQUEST_LOAD_PARSED_LICENSE_REPORT', () => { describe('REQUEST_PARSED_LICENSE_REPORT', () => {
beforeEach(() => { beforeEach(() => {
store.state.isLoadingLicenseReport = false; store.state.isLoadingLicenseReport = false;
store.commit(types.REQUEST_LOAD_PARSED_LICENSE_REPORT); store.commit(types.REQUEST_PARSED_LICENSE_REPORT);
}); });
it('should initiate loading', () => { it('should initiate loading', () => {
......
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