Commit c8b1b3b0 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'mw-productivity-analytics-filter-dropdown-fixes' into 'master'

Productivity Analytics: Project filter dropdown fixes

See merge request gitlab-org/gitlab!16814
parents f57052ac 8d10487a
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import GroupsDropdownFilter from '../../shared/components/groups_dropdown_filter.vue'; import GroupsDropdownFilter from '../../shared/components/groups_dropdown_filter.vue';
import ProjectsDropdownFilter from '../../shared/components/projects_dropdown_filter.vue'; import ProjectsDropdownFilter from '../../shared/components/projects_dropdown_filter.vue';
import { accessLevelReporter } from '../constants'; import { accessLevelReporter, projectsPerPage } from '../constants';
export default { export default {
components: { components: {
...@@ -15,6 +15,10 @@ export default { ...@@ -15,6 +15,10 @@ export default {
groupsQueryParams: { groupsQueryParams: {
min_access_level: accessLevelReporter, min_access_level: accessLevelReporter,
}, },
projectsQueryParams: {
per_page: projectsPerPage,
with_shared: false, // exclude forks
},
}; };
}, },
computed: { computed: {
...@@ -28,16 +32,23 @@ export default { ...@@ -28,16 +32,23 @@ export default {
onGroupSelected({ id, full_path }) { onGroupSelected({ id, full_path }) {
this.groupId = id; this.groupId = id;
this.setGroupNamespace(full_path); this.setGroupNamespace(full_path);
this.$emit('groupSelected', full_path); this.$emit('groupSelected', { groupId: id, groupNamespace: full_path });
}, },
onProjectsSelected(selectedProjects) { onProjectsSelected(selectedProjects) {
const pathWithNamespace = selectedProjects.length let projectNamespace = null;
? selectedProjects[0].path_with_namespace let projectId = null;
: null;
this.setProjectPath(pathWithNamespace); if (selectedProjects.length) {
projectNamespace = selectedProjects[0].path_with_namespace;
projectId = selectedProjects[0].id;
}
this.setProjectPath(projectNamespace);
this.$emit('projectSelected', { this.$emit('projectSelected', {
namespacePath: this.groupNamespace, groupNamespace: this.groupNamespace,
project: pathWithNamespace, groupId: this.groupId,
projectNamespace,
projectId,
}); });
}, },
}, },
...@@ -55,6 +66,7 @@ export default { ...@@ -55,6 +66,7 @@ export default {
v-if="showProjectsDropdownFilter" v-if="showProjectsDropdownFilter"
:key="groupId" :key="groupId"
class="project-select" class="project-select"
:query-params="projectsQueryParams"
:group-id="groupId" :group-id="groupId"
@selected="onProjectsSelected" @selected="onProjectsSelected"
/> />
......
...@@ -95,3 +95,5 @@ export const dataZoomOptions = [ ...@@ -95,3 +95,5 @@ export const dataZoomOptions = [
export const columnHighlightStyle = { color: '#418cd8', opacity: 0.8 }; export const columnHighlightStyle = { color: '#418cd8', opacity: 0.8 };
export const accessLevelReporter = 20; export const accessLevelReporter = 20;
export const projectsPerPage = 50;
...@@ -25,13 +25,13 @@ export default () => { ...@@ -25,13 +25,13 @@ export default () => {
el: groupProjectSelectContainer, el: groupProjectSelectContainer,
store, store,
methods: { methods: {
onGroupSelected(namespacePath) { onGroupSelected({ groupNamespace, groupId }) {
this.initFilteredSearch(namespacePath); this.initFilteredSearch({ groupNamespace, groupId });
}, },
onProjectSelected({ namespacePath, project }) { onProjectSelected({ groupNamespace, groupId, projectNamespace, projectId }) {
this.initFilteredSearch(namespacePath, project); this.initFilteredSearch({ groupNamespace, groupId, projectNamespace, projectId });
}, },
initFilteredSearch(namespacePath, project = '') { initFilteredSearch({ groupNamespace, groupId, projectNamespace = '', projectId = null }) {
// let's unbind attached event handlers first and reset the template // let's unbind attached event handlers first and reset the template
if (filterManager) { if (filterManager) {
filterManager.cleanup(); filterManager.cleanup();
...@@ -41,13 +41,13 @@ export default () => { ...@@ -41,13 +41,13 @@ export default () => {
searchBarContainer.classList.remove('hide'); searchBarContainer.classList.remove('hide');
const filteredSearchInput = searchBarContainer.querySelector('.filtered-search'); const filteredSearchInput = searchBarContainer.querySelector('.filtered-search');
const labelsEndpoint = this.getLabelsEndpoint(namespacePath, project); const labelsEndpoint = this.getLabelsEndpoint(groupNamespace, projectNamespace);
const milestonesEndpoint = this.getMilestonesEndpoint(namespacePath, project); const milestonesEndpoint = this.getMilestonesEndpoint(groupNamespace, projectNamespace);
filteredSearchInput.setAttribute('data-group-id', namespacePath); filteredSearchInput.setAttribute('data-group-id', groupId);
if (project) { if (projectId) {
filteredSearchInput.setAttribute('data-project-id', project); filteredSearchInput.setAttribute('data-project-id', projectId);
} }
filteredSearchInput.setAttribute('data-labels-endpoint', labelsEndpoint); filteredSearchInput.setAttribute('data-labels-endpoint', labelsEndpoint);
......
...@@ -30,6 +30,11 @@ export default { ...@@ -30,6 +30,11 @@ export default {
required: false, required: false,
default: s__('CycleAnalytics|project dropdown filter'), default: s__('CycleAnalytics|project dropdown filter'),
}, },
queryParams: {
type: Object,
required: false,
default: () => ({}),
},
}, },
data() { data() {
return { return {
...@@ -95,7 +100,7 @@ export default { ...@@ -95,7 +100,7 @@ export default {
}, },
fetchData(term, callback) { fetchData(term, callback) {
this.loading = true; this.loading = true;
return Api.groupProjects(this.groupId, term, {}, projects => { return Api.groupProjects(this.groupId, term, this.queryParams, projects => {
this.loading = false; this.loading = false;
callback(projects); callback(projects);
}); });
......
...@@ -17,8 +17,10 @@ describe('FilterDropdowns component', () => { ...@@ -17,8 +17,10 @@ describe('FilterDropdowns component', () => {
setProjectPath: jest.fn(), setProjectPath: jest.fn(),
}; };
const groupId = 1;
const groupNamespace = 'gitlab-org'; const groupNamespace = 'gitlab-org';
const projectPath = 'gitlab-org/gitlab-test'; const projectPath = 'gitlab-org/gitlab-test';
const projectId = 10;
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(localVue.extend(FilterDropdowns), { wrapper = shallowMount(localVue.extend(FilterDropdowns), {
...@@ -54,7 +56,7 @@ describe('FilterDropdowns component', () => { ...@@ -54,7 +56,7 @@ describe('FilterDropdowns component', () => {
describe('with a group selected', () => { describe('with a group selected', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.groupId = 1; wrapper.vm.groupId = groupId;
}); });
it('renders the projects dropdown', () => { it('renders the projects dropdown', () => {
...@@ -66,7 +68,7 @@ describe('FilterDropdowns component', () => { ...@@ -66,7 +68,7 @@ describe('FilterDropdowns component', () => {
describe('methods', () => { describe('methods', () => {
describe('onGroupSelected', () => { describe('onGroupSelected', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.onGroupSelected({ id: 1, full_path: groupNamespace }); wrapper.vm.onGroupSelected({ id: groupId, full_path: groupNamespace });
}); });
it('updates the groupId and invokes setGroupNamespace action', () => { it('updates the groupId and invokes setGroupNamespace action', () => {
...@@ -75,15 +77,22 @@ describe('FilterDropdowns component', () => { ...@@ -75,15 +77,22 @@ describe('FilterDropdowns component', () => {
}); });
it('emits the "groupSelected" event', () => { it('emits the "groupSelected" event', () => {
expect(wrapper.emitted().groupSelected[0][0]).toBe(groupNamespace); expect(wrapper.emitted().groupSelected[0][0]).toEqual({
groupNamespace,
groupId,
});
}); });
}); });
describe('onProjectsSelected', () => { describe('onProjectsSelected', () => {
beforeEach(() => {
wrapper.vm.groupId = groupId;
});
describe('when the list of selected projects is not empty', () => { describe('when the list of selected projects is not empty', () => {
beforeEach(() => { beforeEach(() => {
store.state.filters.groupNamespace = groupNamespace; store.state.filters.groupNamespace = groupNamespace;
wrapper.vm.onProjectsSelected([{ id: 1, path_with_namespace: `${projectPath}` }]); wrapper.vm.onProjectsSelected([{ id: projectId, path_with_namespace: `${projectPath}` }]);
}); });
it('invokes setProjectPath action', () => { it('invokes setProjectPath action', () => {
...@@ -92,8 +101,10 @@ describe('FilterDropdowns component', () => { ...@@ -92,8 +101,10 @@ describe('FilterDropdowns component', () => {
it('emits the "projectSelected" event', () => { it('emits the "projectSelected" event', () => {
expect(wrapper.emitted().projectSelected[0][0]).toEqual({ expect(wrapper.emitted().projectSelected[0][0]).toEqual({
namespacePath: groupNamespace, groupNamespace,
project: projectPath, groupId,
projectNamespace: projectPath,
projectId,
}); });
}); });
}); });
...@@ -110,8 +121,10 @@ describe('FilterDropdowns component', () => { ...@@ -110,8 +121,10 @@ describe('FilterDropdowns component', () => {
it('emits the "projectSelected" event', () => { it('emits the "projectSelected" event', () => {
expect(wrapper.emitted().projectSelected[0][0]).toEqual({ expect(wrapper.emitted().projectSelected[0][0]).toEqual({
namespacePath: groupNamespace, groupNamespace,
project: null, groupId,
projectNamespace: null,
projectId: null,
}); });
}); });
}); });
......
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