Commit 4cf73323 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '287713-swimlanes-creating-an-issue-should-add-board-scope-to-it' into 'master'

Swimlanes - Creating an issue should add board scope to it

See merge request gitlab-org/gitlab!51675
parents f3855f2d 2759adcb
......@@ -88,13 +88,33 @@ export function fullIterationId(id) {
return `gid://gitlab/Iteration/${id}`;
}
export function fullUserId(id) {
return `gid://gitlab/User/${id}`;
}
export function fullMilestoneId(id) {
return `gid://gitlab/Milestone/${id}`;
}
export function fullLabelId(label) {
if (label.project_id !== null) {
if (label.project_id && label.project_id !== null) {
return `gid://gitlab/ProjectLabel/${label.id}`;
}
return `gid://gitlab/GroupLabel/${label.id}`;
}
export function formatIssueInput(issueInput, boardConfig) {
const { labelIds = [], assigneeIds = [] } = issueInput;
const { labels, assigneeId, milestoneId } = boardConfig;
return {
milestoneId: milestoneId ? fullMilestoneId(milestoneId) : null,
...issueInput,
labelIds: [...labelIds, ...(labels?.map((l) => fullLabelId(l)) || [])],
assigneeIds: [...assigneeIds, ...(assigneeId ? [fullUserId(assigneeId)] : [])],
};
}
export function moveIssueListHelper(issue, fromList, toList) {
const updatedIssue = issue;
if (
......
......@@ -129,8 +129,10 @@ export default () => {
milestoneTitle: $boardApp.dataset.boardMilestoneTitle || '',
iterationId: parseInt($boardApp.dataset.boardIterationId, 10),
iterationTitle: $boardApp.dataset.boardIterationTitle || '',
assigneeId: $boardApp.dataset.boardAssigneeId,
assigneeUsername: $boardApp.dataset.boardAssigneeUsername,
labels: $boardApp.dataset.labels ? JSON.parse($boardApp.dataset.labels || []) : [],
labels: $boardApp.dataset.labels ? JSON.parse($boardApp.dataset.labels) : [],
labelIds: $boardApp.dataset.labelIds ? JSON.parse($boardApp.dataset.labelIds) : [],
weight: $boardApp.dataset.boardWeight
? parseInt($boardApp.dataset.boardWeight, 10)
: null,
......
......@@ -12,6 +12,7 @@ import {
fullBoardId,
formatListsPageInfo,
formatIssue,
formatIssueInput,
updateListPosition,
} from '../boards_util';
import createFlash from '~/flash';
......@@ -362,7 +363,10 @@ export default {
},
createNewIssue: ({ commit, state }, issueInput) => {
const input = issueInput;
const { boardConfig } = state;
const input = formatIssueInput(issueInput, boardConfig);
const { boardType, fullPath } = state;
if (boardType === BoardType.project) {
input.projectPath = fullPath;
......
......@@ -21,6 +21,7 @@ module EE
board_iteration_title: board.iteration&.title,
board_iteration_id: board.iteration_id,
board_assignee_username: board.assignee&.username,
board_assignee_id: board.assignee&.id,
label_ids: board.label_ids,
labels: board.labels.to_json(only: [:id, :title, :color, :text_color] ),
board_weight: board.weight,
......
---
title: Swimlanes - Creating an issue adds board scope to it
merge_request: 51675
author:
type: fixed
......@@ -16,8 +16,14 @@ import * as types from '~/boards/stores/mutation_types';
import { inactiveId } from '~/boards/constants';
import issueMoveListMutation from '~/boards/graphql/issue_move_list.mutation.graphql';
import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql';
import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql';
import updateAssignees from '~/vue_shared/components/sidebar/queries/updateAssignees.mutation.graphql';
import { fullBoardId, formatListIssues, formatBoardLists } from '~/boards/boards_util';
import {
fullBoardId,
formatListIssues,
formatBoardLists,
formatIssueInput,
} from '~/boards/boards_util';
import createFlash from '~/flash';
jest.mock('~/flash');
......@@ -728,6 +734,27 @@ describe('createNewIssue', () => {
const state = {
boardType: 'group',
fullPath: 'gitlab-org/gitlab',
boardConfig: {
labelIds: [],
assigneeId: null,
milestoneId: -1,
},
};
const stateWithBoardConfig = {
boardConfig: {
labels: [
{
id: 5,
title: 'Test',
color: '#ff0000',
description: 'testing;',
textColor: 'white',
},
],
assigneeId: 2,
milestoneId: 3,
},
};
it('should return issue from API on success', async () => {
......@@ -744,11 +771,59 @@ describe('createNewIssue', () => {
expect(result).toEqual(mockIssue);
});
it('should add board scope to the issue being created', async () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
createIssue: {
issue: mockIssue,
errors: [],
},
},
});
await actions.createNewIssue({ state: stateWithBoardConfig }, mockIssue);
expect(gqlClient.mutate).toHaveBeenCalledWith({
mutation: issueCreateMutation,
variables: {
input: formatIssueInput(mockIssue, stateWithBoardConfig.boardConfig),
},
});
});
it('should add board scope by merging attributes to the issue being created', async () => {
const issue = {
...mockIssue,
assigneeIds: ['gid://gitlab/User/1'],
labelIds: ['gid://gitlab/GroupLabel/4'],
};
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
createIssue: {
issue,
errors: [],
},
},
});
const payload = formatIssueInput(issue, stateWithBoardConfig.boardConfig);
await actions.createNewIssue({ state: stateWithBoardConfig }, issue);
expect(gqlClient.mutate).toHaveBeenCalledWith({
mutation: issueCreateMutation,
variables: {
input: formatIssueInput(issue, stateWithBoardConfig.boardConfig),
},
});
expect(payload.labelIds).toEqual(['gid://gitlab/GroupLabel/4', 'gid://gitlab/GroupLabel/5']);
expect(payload.assigneeIds).toEqual(['gid://gitlab/User/1', 'gid://gitlab/User/2']);
});
it('should commit CREATE_ISSUE_FAILURE mutation when API returns an error', (done) => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
createIssue: {
issue: {},
issue: mockIssue,
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