Commit 527a3ebd authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch '207443-remove-unused-state-properties' into 'master'

Remove deprecated state properties from license management's store

See merge request gitlab-org/gitlab!72284
parents e0390691 551a4c8b
......@@ -10,7 +10,6 @@ import { licenseManagementModule } from 'ee/vue_shared/license_compliance/store/
import modalModule from '~/vuex_shared/modules/modal';
import { LICENSE_LIST } from './constants';
import listModule from './modules/list';
import mediator from './plugins/mediator';
import createState from './state';
Vue.use(Vuex);
......@@ -24,5 +23,4 @@ export default (settings = {}) =>
[APPROVALS]: approvalsModule(),
[APPROVALS_MODAL]: modalModule(),
},
plugins: [mediator],
});
import { LICENSE_MANAGEMENT } from 'ee/vue_shared/license_compliance/store/constants';
import * as licenseMangementMutationTypes from 'ee/vue_shared/license_compliance/store/mutation_types';
import { LICENSE_LIST } from '../constants';
export default (store) => {
store.subscribe(({ type }) => {
switch (type) {
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_SET_LICENSE_APPROVAL}`:
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`:
store.dispatch(`${LICENSE_LIST}/fetchLicenses`);
break;
default:
}
});
};
import { LICENSE_CHECK_NAME } from 'ee/approvals/constants';
import axios from '~/lib/utils/axios_utils';
import pollUntilComplete from '~/lib/utils/poll_until_complete';
import { LICENSE_LIST } from 'ee/license_compliance/store/constants';
import { LICENSE_APPROVAL_STATUS } from '../constants';
import * as types from './mutation_types';
import { convertToOldReportFormat } from './utils';
......@@ -25,21 +26,18 @@ export const resetLicenseInModal = ({ commit }) => {
commit(types.RESET_LICENSE_IN_MODAL);
};
export const requestDeleteLicense = ({ commit }) => {
commit(types.REQUEST_DELETE_LICENSE);
};
export const receiveDeleteLicense = ({ commit, dispatch }, id) => {
commit(types.RECEIVE_DELETE_LICENSE);
commit(types.RESET_LICENSE_IN_MODAL);
dispatch(`${LICENSE_LIST}/fetchLicenses`, null, { root: true });
return dispatch('fetchManagedLicenses').then(() => {
dispatch('removePendingLicense', id);
});
};
export const receiveDeleteLicenseError = ({ commit }, error) => {
commit(types.RECEIVE_DELETE_LICENSE_ERROR, error);
export const receiveDeleteLicenseError = ({ commit }) => {
commit(types.RESET_LICENSE_IN_MODAL);
};
export const deleteLicense = ({ dispatch, state }) => {
const licenseId = state.currentLicenseInModal.id;
dispatch('requestDeleteLicense');
dispatch('addPendingLicense', licenseId);
const endpoint = `${state.apiUrlManageLicenses}/${licenseId}`;
return axios
......@@ -47,8 +45,8 @@ export const deleteLicense = ({ dispatch, state }) => {
.then(() => {
dispatch('receiveDeleteLicense', licenseId);
})
.catch((error) => {
dispatch('receiveDeleteLicenseError', error);
.catch(() => {
dispatch('receiveDeleteLicenseError');
dispatch('removePendingLicense', licenseId);
});
};
......@@ -59,8 +57,8 @@ export const requestManagedLicenses = ({ commit }) => {
export const receiveManagedLicensesSuccess = ({ commit }, licenses) => {
commit(types.RECEIVE_MANAGED_LICENSES_SUCCESS, licenses);
};
export const receiveManagedLicensesError = ({ commit }, error) => {
commit(types.RECEIVE_MANAGED_LICENSES_ERROR, error);
export const receiveManagedLicensesError = ({ commit }) => {
commit(types.RECEIVE_MANAGED_LICENSES_ERROR);
};
export const fetchManagedLicenses = ({ dispatch, state }) => {
dispatch('requestManagedLicenses');
......@@ -72,8 +70,8 @@ export const fetchManagedLicenses = ({ dispatch, state }) => {
.then(({ data }) => {
dispatch('receiveManagedLicensesSuccess', data);
})
.catch((error) => {
dispatch('receiveManagedLicensesError', error);
.catch(() => {
dispatch('receiveManagedLicensesError');
});
};
......@@ -100,11 +98,9 @@ export const fetchParsedLicenseReport = ({ dispatch, state }) => {
});
};
export const requestSetLicenseApproval = ({ commit }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL);
};
export const receiveSetLicenseApproval = ({ commit, dispatch, state }, id) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL);
commit(types.RESET_LICENSE_IN_MODAL);
dispatch(`${LICENSE_LIST}/fetchLicenses`, null, { root: true });
// If we have the licenses API endpoint, fetch from there. This corresponds
// to the cases that we're viewing the merge request or pipeline pages.
// Otherwise, fetch from the managed licenses endpoint, which corresponds to
......@@ -117,8 +113,8 @@ export const receiveSetLicenseApproval = ({ commit, dispatch, state }, id) => {
dispatch('removePendingLicense', id);
});
};
export const receiveSetLicenseApprovalError = ({ commit }, error) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error);
export const receiveSetLicenseApprovalError = ({ commit }) => {
commit(types.RESET_LICENSE_IN_MODAL);
};
export const fetchLicenseCheckApprovalRule = ({ dispatch, state }) => {
......@@ -177,7 +173,6 @@ export const setLicenseApproval = ({ dispatch, state }, payload) => {
const { license, newStatus } = payload;
const { id, name } = license;
dispatch('requestSetLicenseApproval');
dispatch('addPendingLicense', id);
let request;
......@@ -196,8 +191,8 @@ export const setLicenseApproval = ({ dispatch, state }, payload) => {
.then(() => {
dispatch('receiveSetLicenseApproval', id);
})
.catch((error) => {
dispatch('receiveSetLicenseApprovalError', error);
.catch(() => {
dispatch('receiveSetLicenseApprovalError');
dispatch('removePendingLicense', id);
});
};
......
export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE';
export const RECEIVE_DELETE_LICENSE_ERROR = 'RECEIVE_DELETE_LICENSE_ERROR';
export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCESS';
export const RECEIVE_MANAGED_LICENSES_ERROR = 'RECEIVE_MANAGED_LICENSES_ERROR';
export const RECEIVE_PARSED_LICENSE_REPORT_SUCCESS = 'RECEIVE_PARSED_LICENSE_REPORT_SUCCESS';
export const RECEIVE_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_PARSED_LICENSE_REPORT_ERROR';
export const RECEIVE_SET_LICENSE_APPROVAL = 'RECEIVE_SET_LICENSE_APPROVAL';
export const RECEIVE_SET_LICENSE_APPROVAL_ERROR = 'RECEIVE_SET_LICENSE_APPROVAL_ERROR';
export const REQUEST_DELETE_LICENSE = 'REQUEST_DELETE_LICENSE';
export const REQUEST_MANAGED_LICENSES = 'REQUEST_MANAGED_LICENSES';
export const REQUEST_PARSED_LICENSE_REPORT = 'REQUEST_PARSED_LICENSE_REPORT';
export const REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL';
export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL';
export const SET_API_SETTINGS = 'SET_API_SETTINGS';
export const SET_LICENSE_IN_MODAL = 'SET_LICENSE_IN_MODAL';
......
......@@ -31,14 +31,12 @@ export default {
Object.assign(state, {
managedLicenses,
isLoadingManagedLicenses: false,
loadManagedLicensesError: false,
});
},
[types.RECEIVE_MANAGED_LICENSES_ERROR](state, error) {
[types.RECEIVE_MANAGED_LICENSES_ERROR](state) {
Object.assign(state, {
managedLicenses: [],
isLoadingManagedLicenses: false,
loadManagedLicensesError: error,
});
},
[types.REQUEST_MANAGED_LICENSES](state) {
......@@ -66,41 +64,6 @@ export default {
isLoadingLicenseReport: true,
});
},
[types.RECEIVE_DELETE_LICENSE](state) {
Object.assign(state, {
isDeleting: false,
currentLicenseInModal: null,
});
},
[types.RECEIVE_DELETE_LICENSE_ERROR](state) {
Object.assign(state, {
isDeleting: false,
currentLicenseInModal: null,
});
},
[types.REQUEST_DELETE_LICENSE](state) {
Object.assign(state, {
isDeleting: true,
});
},
[types.REQUEST_SET_LICENSE_APPROVAL](state) {
Object.assign(state, {
isSaving: true,
});
},
[types.RECEIVE_SET_LICENSE_APPROVAL](state) {
Object.assign(state, {
isSaving: false,
currentLicenseInModal: null,
});
},
[types.RECEIVE_SET_LICENSE_APPROVAL_ERROR](state) {
Object.assign(state, {
isSaving: false,
currentLicenseInModal: null,
});
},
[types.REQUEST_LICENSE_CHECK_APPROVAL_RULE](state) {
Object.assign(state, {
isLoadingLicenseCheckApprovalRule: true,
......
......@@ -5,13 +5,10 @@ export default () => ({
canManageLicenses: false,
currentLicenseInModal: null,
isAdmin: false,
isDeleting: false,
isLoadingLicenseReport: false,
isLoadingManagedLicenses: false,
pendingLicenses: [],
isSaving: false,
loadLicenseReportError: false,
loadManagedLicensesError: false,
managedLicenses: [],
newLicenses: [],
existingLicenses: [],
......
import { LICENSE_LIST } from 'ee/license_compliance/store/constants';
import createStore from 'ee/license_compliance/store/index';
import { LICENSE_MANAGEMENT } from 'ee/vue_shared/license_compliance/store/constants';
import * as licenseMangementMutationTypes from 'ee/vue_shared/license_compliance/store/mutation_types';
describe('mediator', () => {
let store;
beforeEach(() => {
store = createStore();
jest.spyOn(store, 'dispatch').mockImplementation();
});
it('triggers fetching of detected licenses after a license policy is added or edited', () => {
store.commit(
`${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_SET_LICENSE_APPROVAL}`,
);
expect(store.dispatch).toHaveBeenCalledWith(`${LICENSE_LIST}/fetchLicenses`);
});
it('triggers fetching of detected licenses after a license policy is deleted', () => {
store.commit(`${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`);
expect(store.dispatch).toHaveBeenCalledWith(`${LICENSE_LIST}/fetchLicenses`);
});
});
......@@ -68,100 +68,6 @@ describe('License store mutations', () => {
});
});
describe('RECEIVE_DELETE_LICENSE', () => {
it('sets isDeleting to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isDeleting: true,
},
});
store.commit(`licenseManagement/${types.RECEIVE_DELETE_LICENSE}`);
expect(store.state.licenseManagement.isDeleting).toBe(false);
});
});
describe('RECEIVE_DELETE_LICENSE_ERROR', () => {
it('sets isDeleting to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isDeleting: true,
currentLicenseInModal: approvedLicense,
},
});
store.commit(`licenseManagement/${types.RECEIVE_DELETE_LICENSE_ERROR}`);
expect(store.state.licenseManagement.isDeleting).toBe(false);
expect(store.state.licenseManagement.currentLicenseInModal).toBeNull();
});
});
describe('REQUEST_DELETE_LICENSE', () => {
it('sets isDeleting to true', () => {
store.replaceState({
...store.state,
licenseManagement: {
isDeleting: false,
},
});
store.commit(`licenseManagement/${types.REQUEST_DELETE_LICENSE}`);
expect(store.state.licenseManagement.isDeleting).toBe(true);
});
});
describe('RECEIVE_SET_LICENSE_APPROVAL', () => {
it('sets isSaving to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isSaving: true,
},
});
store.commit(`licenseManagement/${types.RECEIVE_SET_LICENSE_APPROVAL}`);
expect(store.state.licenseManagement.isSaving).toBe(false);
});
});
describe('RECEIVE_SET_LICENSE_APPROVAL_ERROR', () => {
it('sets isSaving to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isSaving: true,
currentLicenseInModal: approvedLicense,
},
});
store.commit(`licenseManagement/${types.RECEIVE_SET_LICENSE_APPROVAL_ERROR}`);
expect(store.state.licenseManagement.isSaving).toBe(false);
expect(store.state.licenseManagement.currentLicenseInModal).toBeNull();
});
});
describe('REQUEST_SET_LICENSE_APPROVAL', () => {
it('sets isSaving to true', () => {
store.replaceState({
...store.state,
licenseManagement: {
isSaving: false,
},
});
store.commit(`licenseManagement/${types.REQUEST_SET_LICENSE_APPROVAL}`);
expect(store.state.licenseManagement.isSaving).toBe(true);
});
});
describe('REQUEST_LICENSE_CHECK_APPROVAL_RULE', () => {
it('sets isLoadingLicenseCheckApprovalRule to true', () => {
store.replaceState({
......@@ -211,13 +117,12 @@ describe('License store mutations', () => {
});
describe('RECEIVE_MANAGED_LICENSES_SUCCESS', () => {
it('sets isLoadingManagedLicenses and loadManagedLicensesError to false and saves managed licenses', () => {
it('sets isLoadingManagedLicenses to false and saves managed licenses', () => {
store.replaceState({
...store.state,
licenseManagement: {
managedLicenses: false,
isLoadingManagedLicenses: true,
loadManagedLicensesError: true,
},
});
......@@ -230,7 +135,6 @@ describe('License store mutations', () => {
]);
expect(store.state.licenseManagement.isLoadingManagedLicenses).toBe(false);
expect(store.state.licenseManagement.loadManagedLicensesError).toBe(false);
});
});
......@@ -241,14 +145,12 @@ describe('License store mutations', () => {
...store.state,
licenseManagement: {
isLoadingManagedLicenses: true,
loadManagedLicensesError: false,
},
});
store.commit(`licenseManagement/${types.RECEIVE_MANAGED_LICENSES_ERROR}`, error);
expect(store.state.licenseManagement.isLoadingManagedLicenses).toBe(false);
expect(store.state.licenseManagement.loadManagedLicensesError).toBe(error);
});
});
......
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