Commit 9a6a760c authored by Florie Guibert's avatar Florie Guibert

Add epic board scope to newly created epic

Changelog: fixed
EE: true
parent 24875d7d
...@@ -91,6 +91,14 @@ export function formatEpicListsPageInfo(lists) { ...@@ -91,6 +91,14 @@ export function formatEpicListsPageInfo(lists) {
return listData; return listData;
} }
export function formatEpicInput(epicInput, boardConfig) {
const { labelIds = [], ...restEpicInput } = epicInput;
return {
...restEpicInput,
addLabelIds: [...labelIds, ...boardConfig.labelIds],
};
}
export function transformBoardConfig(boardConfig) { export function transformBoardConfig(boardConfig) {
const updatedBoardConfig = {}; const updatedBoardConfig = {};
const passedFilterParams = queryToObject(window.location.search, { gatherArrays: true }); const passedFilterParams = queryToObject(window.location.search, { gatherArrays: true });
......
...@@ -3,8 +3,7 @@ import { mapActions, mapGetters, mapState } from 'vuex'; ...@@ -3,8 +3,7 @@ import { mapActions, mapGetters, mapState } from 'vuex';
import BoardNewItem from '~/boards/components/board_new_item.vue'; import BoardNewItem from '~/boards/components/board_new_item.vue';
import { toggleFormEventPrefix } from '~/boards/constants'; import { toggleFormEventPrefix } from '~/boards/constants';
import eventHub from '~/boards/eventhub'; import eventHub from '~/boards/eventhub';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { fullEpicBoardId } from '../boards_util';
import GroupSelect from './group_select.vue'; import GroupSelect from './group_select.vue';
...@@ -36,11 +35,12 @@ export default { ...@@ -36,11 +35,12 @@ export default {
methods: { methods: {
...mapActions(['addListNewEpic']), ...mapActions(['addListNewEpic']),
submit({ title }) { submit({ title }) {
const labels = this.list.label ? [this.list.label] : [];
return this.addListNewEpic({ return this.addListNewEpic({
epicInput: { epicInput: {
title, title,
boardId: fullEpicBoardId(this.boardId), labelIds: labels?.map((l) => getIdFromGraphQLId(l.id)),
listId: this.list.id,
groupPath: this.groupPath, groupPath: this.groupPath,
}, },
list: this.list, list: this.list,
......
#import "ee/graphql_shared/fragments/epic.fragment.graphql" #import "ee/graphql_shared/fragments/epic.fragment.graphql"
#import "~/graphql_shared/fragments/label.fragment.graphql" #import "~/graphql_shared/fragments/label.fragment.graphql"
mutation CreateEpic($input: BoardEpicCreateInput!) { mutation CreateEpic($input: CreateEpicInput!) {
boardEpicCreate(input: $input) { createEpic(input: $input) {
epic { epic {
...EpicNode ...EpicNode
labels { labels {
......
...@@ -21,6 +21,7 @@ import { ...@@ -21,6 +21,7 @@ import {
formatEpic, formatEpic,
formatListEpics, formatListEpics,
formatEpicListsPageInfo, formatEpicListsPageInfo,
formatEpicInput,
FiltersInfo, FiltersInfo,
} from '../boards_util'; } from '../boards_util';
...@@ -536,7 +537,7 @@ export default { ...@@ -536,7 +537,7 @@ export default {
}, },
addListNewEpic: ( addListNewEpic: (
{ dispatch, commit }, { state: { boardConfig }, dispatch, commit },
{ epicInput, list, placeholderId = `tmp-${new Date().getTime()}` }, { epicInput, list, placeholderId = `tmp-${new Date().getTime()}` },
) => { ) => {
const placeholderEpic = { const placeholderEpic = {
...@@ -552,14 +553,14 @@ export default { ...@@ -552,14 +553,14 @@ export default {
gqlClient gqlClient
.mutate({ .mutate({
mutation: epicCreateMutation, mutation: epicCreateMutation,
variables: { input: epicInput }, variables: { input: formatEpicInput(epicInput, boardConfig) },
}) })
.then(({ data }) => { .then(({ data }) => {
if (data.boardEpicCreate.errors?.length) { if (data.createEpic.errors?.length) {
throw new Error(data.boardEpicCreate.errors[0]); throw new Error(data.createEpic.errors[0]);
} }
const rawEpic = data.boardEpicCreate?.epic; const rawEpic = data.createEpic?.epic;
const formattedEpic = formatEpic({ ...rawEpic, id: getIdFromGraphQLId(rawEpic.id) }); const formattedEpic = formatEpic({ ...rawEpic, id: getIdFromGraphQLId(rawEpic.id) });
dispatch('removeListItem', { listId: list.id, itemId: placeholderId }); dispatch('removeListItem', { listId: list.id, itemId: placeholderId });
dispatch('addListItem', { list, item: formattedEpic, position: 0 }); dispatch('addListItem', { list, item: formattedEpic, position: 0 });
......
...@@ -80,8 +80,7 @@ describe('Epic boards new epic form', () => { ...@@ -80,8 +80,7 @@ describe('Epic boards new epic form', () => {
list: expect.any(Object), list: expect.any(Object),
epicInput: { epicInput: {
title: 'Foo', title: 'Foo',
boardId: 'gid://gitlab/Boards::EpicBoard/1', labelIds: [],
listId: 'gid://gitlab/List/1',
}, },
}); });
}); });
......
...@@ -934,7 +934,7 @@ describe('addListNewEpic', () => { ...@@ -934,7 +934,7 @@ describe('addListNewEpic', () => {
boardType: 'group', boardType: 'group',
fullPath: 'gitlab-org/gitlab', fullPath: 'gitlab-org/gitlab',
boardConfig: { boardConfig: {
labelIds: [], labelIds: ['gid://gitlab/GroupLabel/23'],
assigneeId: null, assigneeId: null,
milestoneId: -1, milestoneId: -1,
}, },
...@@ -945,7 +945,7 @@ describe('addListNewEpic', () => { ...@@ -945,7 +945,7 @@ describe('addListNewEpic', () => {
it('should add board scope to the epic being created', async () => { it('should add board scope to the epic being created', async () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: { data: {
boardEpicCreate: { createEpic: {
epic: mockEpic, epic: mockEpic,
errors: [], errors: [],
}, },
...@@ -964,7 +964,7 @@ describe('addListNewEpic', () => { ...@@ -964,7 +964,7 @@ describe('addListNewEpic', () => {
...mockEpic, ...mockEpic,
groupPath: state.fullPath, groupPath: state.fullPath,
id: 'gid://gitlab/Epic/41', id: 'gid://gitlab/Epic/41',
labels: [], addLabelIds: ['gid://gitlab/GroupLabel/23'],
}, },
}, },
}); });
...@@ -978,7 +978,7 @@ describe('addListNewEpic', () => { ...@@ -978,7 +978,7 @@ describe('addListNewEpic', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: { data: {
boardEpicCreate: { createEpic: {
epic, epic,
errors: [], errors: [],
}, },
...@@ -986,8 +986,8 @@ describe('addListNewEpic', () => { ...@@ -986,8 +986,8 @@ describe('addListNewEpic', () => {
}); });
const payload = { const payload = {
...epic, ...mockEpic,
labelIds: [...epic.labelIds, 'gid://gitlab/GroupLabel/5'], addLabelIds: [...epic.labelIds, 'gid://gitlab/GroupLabel/23'],
}; };
await actions.addListNewEpic( await actions.addListNewEpic(
...@@ -999,19 +999,22 @@ describe('addListNewEpic', () => { ...@@ -999,19 +999,22 @@ describe('addListNewEpic', () => {
mutation: epicCreateMutation, mutation: epicCreateMutation,
variables: { variables: {
input: { input: {
...epic, ...payload,
groupPath: state.fullPath, groupPath: state.fullPath,
}, },
}, },
}); });
expect(payload.labelIds).toEqual(['gid://gitlab/GroupLabel/4', 'gid://gitlab/GroupLabel/5']); expect(payload.addLabelIds).toEqual([
'gid://gitlab/GroupLabel/4',
'gid://gitlab/GroupLabel/23',
]);
}); });
describe('when issue creation mutation request succeeds', () => { describe('when issue creation mutation request succeeds', () => {
it('dispatches a correct set of mutations', () => { it('dispatches a correct set of mutations', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: { data: {
boardEpicCreate: { createEpic: {
epic: mockEpic, epic: mockEpic,
errors: [], errors: [],
}, },
...@@ -1054,7 +1057,7 @@ describe('addListNewEpic', () => { ...@@ -1054,7 +1057,7 @@ describe('addListNewEpic', () => {
it('dispatches a correct set of mutations', () => { it('dispatches a correct set of mutations', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({ jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: { data: {
boardEpicCreate: { createEpic: {
epic: mockEpic, epic: mockEpic,
errors: [{ foo: 'bar' }], errors: [{ foo: 'bar' }],
}, },
......
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