Commit 03fe9386 authored by Florie Guibert's avatar Florie Guibert

Boards - Do no use groupId to check if board is for group

Create and use isGroupBoard and isProjectBoard getters
parent 79e19c5e
...@@ -27,7 +27,7 @@ export default { ...@@ -27,7 +27,7 @@ export default {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
}, },
mixins: [boardCardInner], mixins: [boardCardInner],
inject: ['groupId', 'rootPath', 'scopedLabelsAvailable'], inject: ['rootPath', 'scopedLabelsAvailable'],
props: { props: {
item: { item: {
type: Object, type: Object,
......
...@@ -107,7 +107,7 @@ export default { ...@@ -107,7 +107,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(['isEpicBoard']), ...mapGetters(['isEpicBoard', 'isGroupBoard', 'isProjectBoard']),
isNewForm() { isNewForm() {
return this.currentPage === formType.new; return this.currentPage === formType.new;
}, },
...@@ -178,8 +178,8 @@ export default { ...@@ -178,8 +178,8 @@ export default {
} }
: { : {
...variables, ...variables,
projectPath: this.projectId ? this.fullPath : undefined, projectPath: this.isProjectBoard ? this.fullPath : undefined,
groupPath: this.groupId ? this.fullPath : undefined, groupPath: this.isGroupBoard ? this.fullPath : undefined,
}; };
}, },
boardScopeMutationVariables() { boardScopeMutationVariables() {
......
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { getMilestone } from 'ee_else_ce/boards/boards_util'; import { getMilestone } from 'ee_else_ce/boards/boards_util';
import { __ } from '~/locale'; import { __ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
...@@ -32,8 +32,9 @@ export default { ...@@ -32,8 +32,9 @@ export default {
}, },
computed: { computed: {
...mapState(['selectedProject']), ...mapState(['selectedProject']),
...mapGetters(['isGroupBoard']),
disabled() { disabled() {
if (this.groupId) { if (this.isGroupBoard) {
return this.title === '' || !this.selectedProject.name; return this.title === '' || !this.selectedProject.name;
} }
return this.title === ''; return this.title === '';
...@@ -98,7 +99,7 @@ export default { ...@@ -98,7 +99,7 @@ export default {
name="issue_title" name="issue_title"
autocomplete="off" autocomplete="off"
/> />
<project-select v-if="groupId" :group-id="groupId" :list="list" /> <project-select v-if="isGroupBoard" :group-id="groupId" :list="list" />
<div class="clearfix gl-mt-3"> <div class="clearfix gl-mt-3">
<gl-button <gl-button
ref="submitButton" ref="submitButton"
......
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { mapGetters } from 'vuex';
import { getMilestone } from 'ee_else_ce/boards/boards_util'; import { getMilestone } from 'ee_else_ce/boards/boards_util';
import ListIssue from 'ee_else_ce/boards/models/issue'; import ListIssue from 'ee_else_ce/boards/models/issue';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
...@@ -31,8 +32,9 @@ export default { ...@@ -31,8 +32,9 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(['isGroupBoard']),
disabled() { disabled() {
if (this.groupId) { if (this.isGroupBoard) {
return this.title === '' || !this.selectedProject.name; return this.title === '' || !this.selectedProject.name;
} }
return this.title === ''; return this.title === '';
...@@ -110,7 +112,7 @@ export default { ...@@ -110,7 +112,7 @@ export default {
name="issue_title" name="issue_title"
autocomplete="off" autocomplete="off"
/> />
<project-select v-if="groupId" :group-id="groupId" :list="list" /> <project-select v-if="isGroupBoard" :group-id="groupId" :list="list" />
<div class="clearfix gl-mt-3"> <div class="clearfix gl-mt-3">
<gl-button <gl-button
ref="submitButton" ref="submitButton"
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
GlModalDirective, GlModalDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { throttle } from 'lodash'; import { throttle } from 'lodash';
import { mapGetters, mapState } from 'vuex';
import BoardForm from 'ee_else_ce/boards/components/board_form.vue'; import BoardForm from 'ee_else_ce/boards/components/board_form.vue';
...@@ -109,8 +110,10 @@ export default { ...@@ -109,8 +110,10 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(['boardType']),
...mapGetters(['isGroupBoard']),
parentType() { parentType() {
return this.groupId ? 'group' : 'project'; return this.boardType;
}, },
loading() { loading() {
return this.loadingRecentBoards || Boolean(this.loadingBoards); return this.loadingRecentBoards || Boolean(this.loadingBoards);
...@@ -171,7 +174,7 @@ export default { ...@@ -171,7 +174,7 @@ export default {
})); }));
}, },
boardQuery() { boardQuery() {
return this.groupId ? groupQuery : projectQuery; return this.isGroupBoard ? groupQuery : projectQuery;
}, },
loadBoards(toggleDropdown = true) { loadBoards(toggleDropdown = true) {
if (toggleDropdown && this.boards.length > 0) { if (toggleDropdown && this.boards.length > 0) {
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
GlModalDirective, GlModalDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { throttle } from 'lodash'; import { throttle } from 'lodash';
import { mapGetters, mapState } from 'vuex';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import httpStatusCodes from '~/lib/utils/http_status'; import httpStatusCodes from '~/lib/utils/http_status';
...@@ -108,8 +109,10 @@ export default { ...@@ -108,8 +109,10 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(['boardType']),
...mapGetters(['isGroupBoard']),
parentType() { parentType() {
return this.groupId ? 'group' : 'project'; return this.boardType;
}, },
loading() { loading() {
return this.loadingRecentBoards || Boolean(this.loadingBoards); return this.loadingRecentBoards || Boolean(this.loadingBoards);
...@@ -167,7 +170,7 @@ export default { ...@@ -167,7 +170,7 @@ export default {
return { fullPath: this.state.endpoints.fullPath }; return { fullPath: this.state.endpoints.fullPath };
}, },
query() { query() {
return this.groupId ? groupQuery : projectQuery; return this.isGroupBoard ? groupQuery : projectQuery;
}, },
loadingKey: 'loadingBoards', loadingKey: 'loadingBoards',
update(data) { update(data) {
......
import { find } from 'lodash'; import { find } from 'lodash';
import { inactiveId } from '../constants'; import { BoardType, inactiveId } from '../constants';
export default { export default {
isGroupBoard: (state) => state.boardType === BoardType.group,
isProjectBoard: (state) => state.boardType === BoardType.project,
isSidebarOpen: (state) => state.activeId !== inactiveId, isSidebarOpen: (state) => state.activeId !== inactiveId,
isSwimlanesOn: () => false, isSwimlanesOn: () => false,
getBoardItemById: (state) => (id) => { getBoardItemById: (state) => (id) => {
......
...@@ -56,6 +56,8 @@ describe('BoardForm', () => { ...@@ -56,6 +56,8 @@ describe('BoardForm', () => {
return new Vuex.Store({ return new Vuex.Store({
getters: { getters: {
isEpicBoard: () => true, isEpicBoard: () => true,
isGroupBoard: () => true,
isProjectBoard: () => false,
}, },
}); });
}; };
......
...@@ -42,7 +42,6 @@ describe('Board card component', () => { ...@@ -42,7 +42,6 @@ describe('Board card component', () => {
GlLabel: true, GlLabel: true,
}, },
provide: { provide: {
groupId: null,
rootPath: '/', rootPath: '/',
scopedLabelsAvailable: false, scopedLabelsAvailable: false,
}, },
......
...@@ -19,7 +19,11 @@ const createStore = (state = defaultState) => { ...@@ -19,7 +19,11 @@ const createStore = (state = defaultState) => {
return new Vuex.Store({ return new Vuex.Store({
state, state,
actions, actions,
getters: { isEpicBoard: () => false }, getters: {
isGroupBoard: () => false,
isProjectBoard: () => true,
isEpicBoard: () => false,
},
}); });
}; };
......
/* global List */ /* global List */
import { mount } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex';
import boardNewIssue from '~/boards/components/board_new_issue_deprecated.vue'; import boardNewIssue from '~/boards/components/board_new_issue_deprecated.vue';
import boardsStore from '~/boards/stores/boards_store'; import boardsStore from '~/boards/stores/boards_store';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -10,6 +11,10 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -10,6 +11,10 @@ import axios from '~/lib/utils/axios_utils';
import '~/boards/models/list'; import '~/boards/models/list';
import { listObj, boardsMockInterceptor } from './mock_data'; import { listObj, boardsMockInterceptor } from './mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Issue boards new issue form', () => { describe('Issue boards new issue form', () => {
let wrapper; let wrapper;
let vm; let vm;
...@@ -43,11 +48,17 @@ describe('Issue boards new issue form', () => { ...@@ -43,11 +48,17 @@ describe('Issue boards new issue form', () => {
newIssueMock = Promise.resolve(promiseReturn); newIssueMock = Promise.resolve(promiseReturn);
jest.spyOn(list, 'newIssue').mockImplementation(() => newIssueMock); jest.spyOn(list, 'newIssue').mockImplementation(() => newIssueMock);
const store = new Vuex.Store({
getters: { isGroupBoard: () => false },
});
wrapper = mount(BoardNewIssueComp, { wrapper = mount(BoardNewIssueComp, {
propsData: { propsData: {
disabled: false, disabled: false,
list, list,
}, },
store,
localVue,
provide: { provide: {
groupId: null, groupId: null,
}, },
......
...@@ -8,6 +8,7 @@ import { formType } from '~/boards/constants'; ...@@ -8,6 +8,7 @@ import { formType } from '~/boards/constants';
import createBoardMutation from '~/boards/graphql/board_create.mutation.graphql'; import createBoardMutation from '~/boards/graphql/board_create.mutation.graphql';
import destroyBoardMutation from '~/boards/graphql/board_destroy.mutation.graphql'; import destroyBoardMutation from '~/boards/graphql/board_destroy.mutation.graphql';
import updateBoardMutation from '~/boards/graphql/board_update.mutation.graphql'; import updateBoardMutation from '~/boards/graphql/board_update.mutation.graphql';
import { createStore } from '~/boards/stores';
import { deprecatedCreateFlash as createFlash } from '~/flash'; import { deprecatedCreateFlash as createFlash } from '~/flash';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
...@@ -48,6 +49,13 @@ describe('BoardForm', () => { ...@@ -48,6 +49,13 @@ describe('BoardForm', () => {
const findDeleteConfirmation = () => wrapper.find('[data-testid="delete-confirmation-message"]'); const findDeleteConfirmation = () => wrapper.find('[data-testid="delete-confirmation-message"]');
const findInput = () => wrapper.find('#board-new-name'); const findInput = () => wrapper.find('#board-new-name');
const store = createStore({
getters: {
isGroupBoard: () => true,
isProjectBoard: () => false,
},
});
const createComponent = (props, data) => { const createComponent = (props, data) => {
wrapper = shallowMount(BoardForm, { wrapper = shallowMount(BoardForm, {
propsData: { ...defaultProps, ...props }, propsData: { ...defaultProps, ...props },
...@@ -64,6 +72,7 @@ describe('BoardForm', () => { ...@@ -64,6 +72,7 @@ describe('BoardForm', () => {
mutate, mutate,
}, },
}, },
store,
attachTo: document.body, attachTo: document.body,
}); });
}; };
......
...@@ -2,7 +2,6 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'; ...@@ -2,7 +2,6 @@ import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import BoardNewIssue from '~/boards/components/board_new_issue.vue'; import BoardNewIssue from '~/boards/components/board_new_issue.vue';
import '~/boards/models/list';
import { mockList, mockGroupProjects } from '../mock_data'; import { mockList, mockGroupProjects } from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -31,7 +30,7 @@ describe('Issue boards new issue form', () => { ...@@ -31,7 +30,7 @@ describe('Issue boards new issue form', () => {
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { selectedProject: mockGroupProjects[0] }, state: { selectedProject: mockGroupProjects[0] },
actions: { addListNewIssue: addListNewIssuesSpy }, actions: { addListNewIssue: addListNewIssuesSpy },
getters: {}, getters: { isGroupBoard: () => false },
}); });
wrapper = shallowMount(BoardNewIssue, { wrapper = shallowMount(BoardNewIssue, {
......
...@@ -10,6 +10,42 @@ import { ...@@ -10,6 +10,42 @@ import {
} from '../mock_data'; } from '../mock_data';
describe('Boards - Getters', () => { describe('Boards - Getters', () => {
describe('isGroupBoard', () => {
it('returns true when boardType on state is group', () => {
const state = {
boardType: 'group',
};
expect(getters.isGroupBoard(state)).toBe(true);
});
it('returns false when boardType on state is not group', () => {
const state = {
boardType: 'project',
};
expect(getters.isGroupBoard(state)).toBe(false);
});
});
describe('isProjectBoard', () => {
it('returns true when boardType on state is project', () => {
const state = {
boardType: 'project',
};
expect(getters.isProjectBoard(state)).toBe(true);
});
it('returns false when boardType on state is not project', () => {
const state = {
boardType: 'group',
};
expect(getters.isProjectBoard(state)).toBe(false);
});
});
describe('isSidebarOpen', () => { describe('isSidebarOpen', () => {
it('returns true when activeId is not equal to 0', () => { it('returns true when activeId is not equal to 0', () => {
const state = { const 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