Commit 88589d27 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'mw-cr-add-filter-module' into 'master'

Code Review Analytics: Add filters module

See merge request gitlab-org/gitlab!30054
parents 48171f4f e03e7ad3
......@@ -21,6 +21,6 @@ export default class FilteredSearchCodeReviewAnalytics extends FilteredSearchMan
*/
updateObject = path => {
const filters = urlParamsToObject(path);
store.dispatch('mergeRequests/setFilters', filters);
store.dispatch('filters/setFilters', filters);
};
}
import Vue from 'vue';
import Vuex from 'vuex';
import filters from './modules/filters/index';
import mergeRequests from './modules/merge_requests/index';
Vue.use(Vuex);
......@@ -7,6 +8,7 @@ Vue.use(Vuex);
const createStore = () =>
new Vuex.Store({
modules: {
filters,
mergeRequests,
},
});
......
import * as types from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const setFilters = ({ commit, dispatch }, { label_name, milestone_title }) => {
commit(types.SET_FILTERS, { labelName: label_name, milestoneTitle: milestone_title });
dispatch('mergeRequests/setPage', 1, { root: true });
dispatch('mergeRequests/fetchMergeRequests', null, { root: true });
};
import state from './state';
import * as actions from './actions';
import mutations from './mutations';
export default {
namespaced: true,
actions,
mutations,
state: state(),
};
// eslint-disable-next-line import/prefer-default-export
export const SET_FILTERS = 'SET_FILTERS';
import * as types from './mutation_types';
export default {
[types.SET_FILTERS](state, { labelName, milestoneTitle }) {
state.labelName = labelName;
state.milestoneTitle = milestoneTitle;
},
};
export default () => ({
labelName: [],
milestoneTitle: null,
});
......@@ -6,23 +6,16 @@ import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId);
export const setFilters = ({ commit, dispatch }, { label_name, milestone_title }) => {
commit(types.SET_FILTERS, { labelName: label_name, milestoneTitle: milestone_title });
export const fetchMergeRequests = ({ dispatch, state, rootState }) => {
dispatch('requestMergeRequests');
dispatch('fetchMergeRequests');
};
const { projectId, pageInfo } = state;
export const fetchMergeRequests = ({ dispatch, state }) => {
dispatch('requestMergeRequests');
const { milestoneTitle, labelName } = rootState.filters;
const {
projectId,
filters: { milestoneTitle, labelName },
pageInfo,
} = state;
const params = {
project_id: projectId,
milestone_title: milestoneTitle,
milestone_title: Array.isArray(milestoneTitle) ? milestoneTitle.join('') : milestoneTitle,
label_name: labelName,
page: pageInfo.page,
};
......
export const SET_PROJECT_ID = 'SET_PROJECT_ID';
export const SET_FILTERS = 'SET_FILTERS';
export const REQUEST_MERGE_REQUESTS = 'REQUEST_MERGE_REQUESTS';
export const RECEIVE_MERGE_REQUESTS_SUCCESS = 'RECEIVE_MERGE_REQUESTS_SUCCESS';
......
......@@ -4,11 +4,6 @@ export default {
[types.SET_PROJECT_ID](state, projectId) {
state.projectId = projectId;
},
[types.SET_FILTERS](state, { labelName, milestoneTitle }) {
state.filters.labelName = labelName;
state.filters.milestoneTitle = milestoneTitle;
state.pageInfo.page = 1;
},
[types.REQUEST_MERGE_REQUESTS](state) {
state.isLoading = true;
},
......
......@@ -4,8 +4,4 @@ export default () => ({
errorCode: null,
mergeRequests: [],
pageInfo: {},
filters: {
labelName: [],
milestoneTitle: null,
},
});
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import * as actions from 'ee/analytics/code_review_analytics/store/modules/filters/actions';
import * as types from 'ee/analytics/code_review_analytics/store/modules/filters/mutation_types';
import getInitialState from 'ee/analytics/code_review_analytics/store/modules/filters/state';
describe('Code review analytics filters actions', () => {
let state;
let mock;
beforeEach(() => {
state = getInitialState();
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
describe('setFilters', () => {
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
it('commits the SET_FILTERS mutation', () => {
testAction(
actions.setFilters,
{ milestone_title: milestoneTitle, label_name: labelName },
state,
[
{
type: types.SET_FILTERS,
payload: { milestoneTitle, labelName },
},
],
[
{ type: 'mergeRequests/setPage', payload: 1 },
{ type: 'mergeRequests/fetchMergeRequests', payload: null },
],
);
});
});
});
import * as types from 'ee/analytics/code_review_analytics/store/modules/filters/mutation_types';
import mutations from 'ee/analytics/code_review_analytics/store/modules/filters/mutations';
import getInitialState from 'ee/analytics/code_review_analytics/store/modules/filters/state';
describe('Code review analytics filters mutations', () => {
let state;
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
beforeEach(() => {
state = getInitialState();
});
describe(types.SET_FILTERS, () => {
it('updates milestoneTitle and labelName', () => {
mutations[types.SET_FILTERS](state, { milestoneTitle, labelName });
expect(state.milestoneTitle).toBe(milestoneTitle);
expect(state.labelName).toBe(labelName);
});
});
});
......@@ -9,7 +9,7 @@ import mockMergeRequests from '../../../mock_data';
jest.mock('~/flash', () => jest.fn());
describe('Code review analytics actions', () => {
describe('Code review analytics mergeRequests actions', () => {
let state;
let mock;
......@@ -32,7 +32,13 @@ describe('Code review analytics actions', () => {
};
beforeEach(() => {
state = getInitialState();
state = {
filters: {
milestoneTitle: null,
labelName: [],
},
...getInitialState(),
};
mock = new MockAdapter(axios);
});
......@@ -142,26 +148,6 @@ describe('Code review analytics actions', () => {
}));
});
describe('setFilters', () => {
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
it('commits the SET_FILTERS mutation', () => {
testAction(
actions.setFilters,
{ milestone_title: milestoneTitle, label_name: labelName },
state,
[
{
type: types.SET_FILTERS,
payload: { milestoneTitle, labelName },
},
],
[{ type: 'fetchMergeRequests' }],
);
});
});
describe('setPage', () => {
it('commits SET_PAGE mutation', () => {
testAction(actions.setPage, 2, state, [{ type: types.SET_PAGE, payload: 2 }], []);
......
......@@ -3,12 +3,9 @@ import mutations from 'ee/analytics/code_review_analytics/store/modules/merge_re
import getInitialState from 'ee/analytics/code_review_analytics/store/modules/merge_requests/state';
import mockMergeRequests from '../../../mock_data';
describe('Code review analytics mutations', () => {
describe('Code review analytics mergeRequests mutations', () => {
let state;
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
const pageInfo = {
page: 1,
nextPage: 2,
......@@ -30,16 +27,6 @@ describe('Code review analytics mutations', () => {
});
});
describe(types.SET_FILTERS, () => {
it('updates milestoneTitle and labelName', () => {
mutations[types.SET_FILTERS](state, { milestoneTitle, labelName });
expect(state.filters.milestoneTitle).toBe(milestoneTitle);
expect(state.filters.labelName).toBe(labelName);
expect(state.pageInfo.page).toBe(1);
});
});
describe(types.REQUEST_MERGE_REQUESTS, () => {
it('sets isLoading to true', () => {
mutations[types.REQUEST_MERGE_REQUESTS](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