Commit 7ad267b2 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '335964-refactor-create-approvals-store' into 'master'

Update createStore to allow for multiple approval modules

See merge request gitlab-org/gitlab!66953
parents dc702856 8cf55a26
...@@ -23,10 +23,10 @@ export default { ...@@ -23,10 +23,10 @@ export default {
}, },
computed: { computed: {
...mapState({ ...mapState({
isLoading: (state) => state.approvals.isLoading, isLoading: (state) => state.approvalSettings.isLoading,
isUpdated: (state) => state.approvals.isUpdated, isUpdated: (state) => state.approvalSettings.isUpdated,
settings: (state) => state.approvals.settings, settings: (state) => state.approvalSettings.settings,
errorMessage: (state) => state.approvals.errorMessage, errorMessage: (state) => state.approvalSettings.errorMessage,
}), }),
...mapComputed( ...mapComputed(
[ [
...@@ -37,7 +37,7 @@ export default { ...@@ -37,7 +37,7 @@ export default {
{ key: 'requireUserPassword', updateFn: 'setRequireUserPassword' }, { key: 'requireUserPassword', updateFn: 'setRequireUserPassword' },
], ],
undefined, undefined,
(state) => state.approvals.settings, (state) => state.approvalSettings.settings,
), ),
hasSettings() { hasSettings() {
return !isEmpty(this.settings); return !isEmpty(this.settings);
......
...@@ -11,7 +11,9 @@ const mountGroupApprovalSettings = (el) => { ...@@ -11,7 +11,9 @@ const mountGroupApprovalSettings = (el) => {
} }
const { defaultExpanded, approvalSettingsPath } = el.dataset; const { defaultExpanded, approvalSettingsPath } = el.dataset;
const store = createStore(approvalSettingsModule(groupApprovalsMappers)); const store = createStore({
approvalSettings: approvalSettingsModule(groupApprovalsMappers),
});
return new Vue({ return new Vue({
el, el,
......
...@@ -13,15 +13,18 @@ export default function mountApprovalInput(el) { ...@@ -13,15 +13,18 @@ export default function mountApprovalInput(el) {
document.querySelector('#js-target-branch-title')?.textContent || document.querySelector('#js-target-branch-title')?.textContent ||
document.querySelector('#merge_request_target_branch')?.value; document.querySelector('#merge_request_target_branch')?.value;
const store = createStore(mrEditModule(), { const store = createStore(
...el.dataset, { approvals: mrEditModule() },
prefix: 'mr-edit', {
canEdit: parseBoolean(el.dataset.canEdit), ...el.dataset,
canUpdateApprovers: parseBoolean(el.dataset.canUpdateApprovers), prefix: 'mr-edit',
showCodeOwnerTip: parseBoolean(el.dataset.showCodeOwnerTip), canEdit: parseBoolean(el.dataset.canEdit),
allowMultiRule: parseBoolean(el.dataset.allowMultiRule), canUpdateApprovers: parseBoolean(el.dataset.canUpdateApprovers),
canOverride: parseBoolean(el.dataset.canOverride), showCodeOwnerTip: parseBoolean(el.dataset.showCodeOwnerTip),
}); allowMultiRule: parseBoolean(el.dataset.allowMultiRule),
canOverride: parseBoolean(el.dataset.canOverride),
},
);
store.dispatch('setTargetBranch', targetBranch); store.dispatch('setTargetBranch', targetBranch);
......
...@@ -15,12 +15,15 @@ export default function mountProjectSettingsApprovals(el) { ...@@ -15,12 +15,15 @@ export default function mountProjectSettingsApprovals(el) {
coverageCheckHelpPagePath, coverageCheckHelpPagePath,
} = el.dataset; } = el.dataset;
const store = createStore(projectSettingsModule(), { const store = createStore(
...el.dataset, { approvals: projectSettingsModule() },
prefix: 'project-settings', {
allowMultiRule: parseBoolean(el.dataset.allowMultiRule), ...el.dataset,
canEdit: parseBoolean(el.dataset.canEdit), prefix: 'project-settings',
}); allowMultiRule: parseBoolean(el.dataset.allowMultiRule),
canEdit: parseBoolean(el.dataset.canEdit),
},
);
return new Vue({ return new Vue({
el, el,
......
...@@ -3,10 +3,10 @@ import securityConfigurationModule from 'ee/security_configuration/modules/confi ...@@ -3,10 +3,10 @@ import securityConfigurationModule from 'ee/security_configuration/modules/confi
import modalModule from '~/vuex_shared/modules/modal'; import modalModule from '~/vuex_shared/modules/modal';
import state from './state'; import state from './state';
export const createStoreOptions = (approvalsModule, settings) => ({ export const createStoreOptions = (approvalsModules, settings) => ({
state: state(settings), state: state(settings),
modules: { modules: {
...(approvalsModule ? { approvals: approvalsModule } : {}), ...approvalsModules,
createModal: modalModule(), createModal: modalModule(),
deleteModal: modalModule(), deleteModal: modalModule(),
securityConfiguration: securityConfigurationModule({ securityConfiguration: securityConfigurationModule({
...@@ -15,5 +15,5 @@ export const createStoreOptions = (approvalsModule, settings) => ({ ...@@ -15,5 +15,5 @@ export const createStoreOptions = (approvalsModule, settings) => ({
}, },
}); });
export default (approvalsModule, settings = {}) => export default (approvalModules, settings = {}) =>
new Vuex.Store(createStoreOptions(approvalsModule, settings)); new Vuex.Store(createStoreOptions(approvalModules, settings));
...@@ -38,10 +38,13 @@ describe('EE Approvals App', () => { ...@@ -38,10 +38,13 @@ describe('EE Approvals App', () => {
rules: `<div class="${TEST_RULES_CLASS}">These are the rules!</div>`, rules: `<div class="${TEST_RULES_CLASS}">These are the rules!</div>`,
}; };
store = createStoreOptions(settingsModule(), { store = createStoreOptions(
canEdit: true, { approvals: settingsModule() },
prefix: APP_PREFIX, {
}); canEdit: true,
prefix: APP_PREFIX,
},
);
store.modules.approvals.actions = { store.modules.approvals.actions = {
fetchRules: jest.fn().mockResolvedValue(), fetchRules: jest.fn().mockResolvedValue(),
......
...@@ -30,7 +30,7 @@ describe('ApprovalSettings', () => { ...@@ -30,7 +30,7 @@ describe('ApprovalSettings', () => {
jest.spyOn(actions, 'dismissErrorMessage').mockImplementation(); jest.spyOn(actions, 'dismissErrorMessage').mockImplementation();
jest.spyOn(actions, 'dismissSuccessMessage').mockImplementation(); jest.spyOn(actions, 'dismissSuccessMessage').mockImplementation();
store = createStore(module); store = createStore({ approvalSettings: module });
}; };
const createWrapper = () => { const createWrapper = () => {
......
...@@ -43,7 +43,7 @@ describe('EE Approvals Group Settings App', () => { ...@@ -43,7 +43,7 @@ describe('EE Approvals Group Settings App', () => {
axiosMock = new MockAdapter(axios); axiosMock = new MockAdapter(axios);
axiosMock.onGet('*'); axiosMock.onGet('*');
store = createStoreOptions(approvalSettingsModule(groupApprovalsMappers)); store = createStoreOptions({ approvalSettings: approvalSettingsModule(groupApprovalsMappers) });
}); });
afterEach(() => { afterEach(() => {
......
...@@ -32,7 +32,7 @@ describe('EE Approvals MREditApp', () => { ...@@ -32,7 +32,7 @@ describe('EE Approvals MREditApp', () => {
axiosMock = new MockAdapter(axios); axiosMock = new MockAdapter(axios);
axiosMock.onGet('*'); axiosMock.onGet('*');
store = createStoreOptions(MREditModule()); store = createStoreOptions({ approvals: MREditModule() });
store.modules.approvals.state.hasLoaded = true; store.modules.approvals.state.hasLoaded = true;
}); });
......
...@@ -34,7 +34,7 @@ describe('EE Approvlas MRRulesHiddenInputs', () => { ...@@ -34,7 +34,7 @@ describe('EE Approvlas MRRulesHiddenInputs', () => {
}; };
beforeEach(() => { beforeEach(() => {
store = createStoreOptions(MREditModule()); store = createStoreOptions({ approvals: MREditModule() });
store.modules.approvals.state = { store.modules.approvals.state = {
rules: [], rules: [],
rulesToDelete: [], rulesToDelete: [],
......
...@@ -46,7 +46,7 @@ describe('EE Approvals MRRules', () => { ...@@ -46,7 +46,7 @@ describe('EE Approvals MRRules', () => {
.fn() .fn()
.mockImplementation((args) => new OriginalMutationObserver(args)); .mockImplementation((args) => new OriginalMutationObserver(args));
store = createStoreOptions(MREditModule()); store = createStoreOptions({ approvals: MREditModule() });
store.modules.approvals.state = { store.modules.approvals.state = {
hasLoaded: true, hasLoaded: true,
rules: [], rules: [],
......
...@@ -26,7 +26,7 @@ describe('Rule Input', () => { ...@@ -26,7 +26,7 @@ describe('Rule Input', () => {
}; };
beforeEach(() => { beforeEach(() => {
store = createStoreOptions(MREditModule()); store = createStoreOptions({ approvals: MREditModule() });
store.state.settings.canEdit = true; store.state.settings.canEdit = true;
store.modules.approvals.actions = { store.modules.approvals.actions = {
......
...@@ -41,7 +41,7 @@ describe('Approvals ProjectRules', () => { ...@@ -41,7 +41,7 @@ describe('Approvals ProjectRules', () => {
}; };
beforeEach(() => { beforeEach(() => {
store = createStoreOptions(projectSettingsModule()); store = createStoreOptions({ approvals: projectSettingsModule() });
store.modules.approvals.state.rules = TEST_RULES; store.modules.approvals.state.rules = TEST_RULES;
}); });
......
...@@ -33,7 +33,7 @@ describe('EE Approvals RuleControls', () => { ...@@ -33,7 +33,7 @@ describe('EE Approvals RuleControls', () => {
const findRemoveButton = () => findButton('Remove'); const findRemoveButton = () => findButton('Remove');
beforeEach(() => { beforeEach(() => {
store = createStoreOptions(MREditModule()); store = createStoreOptions({ approvals: MREditModule() });
({ actions } = store.modules.approvals); ({ actions } = store.modules.approvals);
['requestEditRule', 'requestDeleteRule'].forEach((actionName) => ['requestEditRule', 'requestDeleteRule'].forEach((actionName) =>
jest.spyOn(actions, actionName), jest.spyOn(actions, actionName),
......
...@@ -104,7 +104,10 @@ describe('EE Approvals RuleForm', () => { ...@@ -104,7 +104,10 @@ describe('EE Approvals RuleForm', () => {
]; ];
beforeEach(() => { beforeEach(() => {
store = createStoreOptions(projectSettingsModule(), { projectId: TEST_PROJECT_ID }); store = createStoreOptions(
{ approvals: projectSettingsModule() },
{ projectId: TEST_PROJECT_ID },
);
['postRule', 'putRule', 'deleteRule', 'putFallbackRule'].forEach((actionName) => { ['postRule', 'putRule', 'deleteRule', 'putFallbackRule'].forEach((actionName) => {
jest.spyOn(store.modules.approvals.actions, actionName).mockImplementation(() => {}); jest.spyOn(store.modules.approvals.actions, actionName).mockImplementation(() => {});
......
...@@ -31,7 +31,7 @@ describe('UnconfiguredSecurityRules component', () => { ...@@ -31,7 +31,7 @@ describe('UnconfiguredSecurityRules component', () => {
beforeEach(() => { beforeEach(() => {
store = new Vuex.Store( store = new Vuex.Store(
createStoreOptions(projectSettingsModule(), { projectId: TEST_PROJECT_ID }), createStoreOptions({ approvals: projectSettingsModule() }, { projectId: TEST_PROJECT_ID }),
); );
jest.spyOn(store, 'dispatch'); jest.spyOn(store, 'dispatch');
}); });
......
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