Commit 3f6c6e78 authored by Phil Hughes's avatar Phil Hughes

Merge branch '222763-use-project-iterations-query' into 'master'

Use project iterations query for project iterations list

See merge request gitlab-org/gitlab!38705
parents c6e88d58 2ca6da50
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
import { GlAlert, GlButton, GlLoadingIcon, GlPagination, GlTab, GlTabs } from '@gitlab/ui'; import { GlAlert, GlButton, GlLoadingIcon, GlPagination, GlTab, GlTabs } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import IterationsList from './iterations_list.vue'; import IterationsList from './iterations_list.vue';
import GroupIterationQuery from '../queries/group_iterations.query.graphql'; import IterationsQuery from '../queries/iterations.query.graphql';
import { Namespace } from '../constants';
const pageSize = 20; const pageSize = 20;
...@@ -26,6 +27,12 @@ export default { ...@@ -26,6 +27,12 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
namespaceType: {
type: String,
required: false,
default: Namespace.Group,
validator: value => Object.values(Namespace).includes(value),
},
newIterationPath: { newIterationPath: {
type: String, type: String,
required: false, required: false,
...@@ -34,14 +41,14 @@ export default { ...@@ -34,14 +41,14 @@ export default {
}, },
apollo: { apollo: {
namespace: { namespace: {
query: GroupIterationQuery, query: IterationsQuery,
variables() { variables() {
return this.queryVariables; return this.queryVariables;
}, },
update: data => { update(data) {
return { return {
iterations: data.group?.iterations?.nodes || [], iterations: data[this.namespaceType]?.iterations?.nodes || [],
pageInfo: data.group?.iterations?.pageInfo || {}, pageInfo: data[this.namespaceType]?.iterations?.pageInfo || {},
}; };
}, },
error() { error() {
...@@ -69,6 +76,8 @@ export default { ...@@ -69,6 +76,8 @@ export default {
queryVariables() { queryVariables() {
const vars = { const vars = {
fullPath: this.fullPath, fullPath: this.fullPath,
isGroup: this.namespaceType === Namespace.Group,
isProject: this.namespaceType === Namespace.Project,
state: this.state, state: this.state,
}; };
......
export const Namespace = {
Group: 'group',
Project: 'project',
};
export default {};
...@@ -12,7 +12,7 @@ const apolloProvider = new VueApollo({ ...@@ -12,7 +12,7 @@ const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(), defaultClient: createDefaultClient(),
}); });
export function initIterationsList() { export function initIterationsList(namespaceType) {
const el = document.querySelector('.js-iterations-list'); const el = document.querySelector('.js-iterations-list');
return new Vue({ return new Vue({
...@@ -23,6 +23,7 @@ export function initIterationsList() { ...@@ -23,6 +23,7 @@ export function initIterationsList() {
props: { props: {
fullPath: el.dataset.fullPath, fullPath: el.dataset.fullPath,
canAdmin: parseBoolean(el.dataset.canAdmin), canAdmin: parseBoolean(el.dataset.canAdmin),
namespaceType,
newIterationPath: el.dataset.newIterationPath, newIterationPath: el.dataset.newIterationPath,
}, },
}); });
......
fragment Iteration on Iteration {
dueDate
id
startDate
state
title
webPath
}
#import "~/graphql_shared/fragments/pageInfo.fragment.graphql" #import "~/graphql_shared/fragments/pageInfo.fragment.graphql"
#import "./iteration.fragment.graphql"
query GroupIterations( query Iterations(
$fullPath: ID! $fullPath: ID!
$isGroup: Boolean = false
$isProject: Boolean = false
$state: IterationState! $state: IterationState!
$beforeCursor: String = "" $beforeCursor: String = ""
$afterCursor: String = "" $afterCursor: String = ""
$firstPageSize: Int $firstPageSize: Int
$lastPageSize: Int $lastPageSize: Int
) { ) {
group(fullPath: $fullPath) { group(fullPath: $fullPath) @include(if: $isGroup) {
iterations( iterations(
state: $state state: $state
includeAncestors: false includeAncestors: false
...@@ -18,12 +21,23 @@ query GroupIterations( ...@@ -18,12 +21,23 @@ query GroupIterations(
last: $lastPageSize last: $lastPageSize
) { ) {
nodes { nodes {
title ...Iteration
state }
id pageInfo {
webPath ...PageInfo
startDate }
dueDate }
}
project(fullPath: $fullPath) @include(if: $isProject) {
iterations(
state: $state
before: $beforeCursor
after: $afterCursor
first: $firstPageSize
last: $lastPageSize
) {
nodes {
...Iteration
} }
pageInfo { pageInfo {
...PageInfo ...PageInfo
......
import { initIterationsList } from 'ee/iterations'; import { initIterationsList } from 'ee/iterations';
import { Namespace } from 'ee/iterations/constants';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => initIterationsList(Namespace.Group));
initIterationsList();
});
import { initIterationsList } from 'ee/iterations'; import { initIterationsList } from 'ee/iterations';
import { Namespace } from 'ee/iterations/constants';
document.addEventListener('DOMContentLoaded', initIterationsList); document.addEventListener('DOMContentLoaded', () => initIterationsList(Namespace.Project));
- return unless Feature.enabled?(:project_iterations, @project.group)
- page_title _("Iterations") - page_title _("Iterations")
- if Feature.enabled?(:project_iterations, @project.group) .js-iterations-list{ data: { full_path: @project.full_path } }
.js-iterations-list{ data: { full_path: @project.group.full_path } }
...@@ -2,6 +2,7 @@ import Iterations from 'ee/iterations/components/iterations.vue'; ...@@ -2,6 +2,7 @@ import Iterations from 'ee/iterations/components/iterations.vue';
import IterationsList from 'ee/iterations/components/iterations_list.vue'; import IterationsList from 'ee/iterations/components/iterations_list.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlAlert, GlLoadingIcon, GlPagination, GlTab, GlTabs } from '@gitlab/ui'; import { GlAlert, GlLoadingIcon, GlPagination, GlTab, GlTabs } from '@gitlab/ui';
import { Namespace } from 'ee/iterations/constants';
describe('Iterations tabs', () => { describe('Iterations tabs', () => {
let wrapper; let wrapper;
...@@ -101,6 +102,8 @@ describe('Iterations tabs', () => { ...@@ -101,6 +102,8 @@ describe('Iterations tabs', () => {
expect(wrapper.vm.queryVariables).toEqual({ expect(wrapper.vm.queryVariables).toEqual({
beforeCursor: 'first-item', beforeCursor: 'first-item',
isGroup: true,
isProject: false,
lastPageSize: 20, lastPageSize: 20,
fullPath: defaultProps.fullPath, fullPath: defaultProps.fullPath,
state: 'opened', state: 'opened',
...@@ -114,6 +117,8 @@ describe('Iterations tabs', () => { ...@@ -114,6 +117,8 @@ describe('Iterations tabs', () => {
afterCursor: 'last-item', afterCursor: 'last-item',
firstPageSize: 20, firstPageSize: 20,
fullPath: defaultProps.fullPath, fullPath: defaultProps.fullPath,
isGroup: true,
isProject: false,
state: 'opened', state: 'opened',
}); });
}); });
...@@ -136,6 +141,49 @@ describe('Iterations tabs', () => { ...@@ -136,6 +141,49 @@ describe('Iterations tabs', () => {
}); });
}); });
describe('iterations query variables', () => {
const expected = {
afterCursor: undefined,
firstPageSize: 20,
fullPath: defaultProps.fullPath,
state: 'opened',
};
describe('when group', () => {
it('has expected query variable values', () => {
mountComponent({
props: {
...defaultProps,
namespaceType: Namespace.Group,
},
});
expect(wrapper.vm.queryVariables).toEqual({
...expected,
isGroup: true,
isProject: false,
});
});
});
describe('when project', () => {
it('has expected query variable values', () => {
mountComponent({
props: {
...defaultProps,
namespaceType: Namespace.Project,
},
});
expect(wrapper.vm.queryVariables).toEqual({
...expected,
isGroup: false,
isProject: true,
});
});
});
});
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
mountComponent({ mountComponent({
......
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