actions.js 21.1 KB
Newer Older
1
import { pick } from 'lodash';
2 3 4 5 6
import {
  formatBoardLists,
  formatListIssues,
  formatListsPageInfo,
  fullBoardId,
7
  transformNotFilters,
8
} from '~/boards/boards_util';
9
import { BoardType } from '~/boards/constants';
10
import eventHub from '~/boards/eventhub';
11
import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql';
12 13 14 15 16 17 18 19 20 21 22 23
import actionsCE from '~/boards/stores/actions';
import boardsStore from '~/boards/stores/boards_store';
import * as typesCE from '~/boards/stores/mutation_types';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import createGqClient, { fetchPolicies } from '~/lib/graphql';
import axios from '~/lib/utils/axios_utils';
import {
  historyPushState,
  convertObjectPropsToCamelCase,
  urlParamsToObject,
} from '~/lib/utils/common_utils';
import { mergeUrlParams, removeParams } from '~/lib/utils/url_utility';
24 25 26 27 28 29
import {
  fullEpicId,
  fullEpicBoardId,
  formatListEpics,
  formatEpicListsPageInfo,
} from '../boards_util';
30

31
import { EpicFilterType, IterationFilterType, GroupByParamType } from '../constants';
32
import epicQuery from '../graphql/epic.query.graphql';
33
import createEpicBoardListMutation from '../graphql/epic_board_list_create.mutation.graphql';
34
import epicBoardListsQuery from '../graphql/epic_board_lists.query.graphql';
35
import epicMoveListMutation from '../graphql/epic_move_list.mutation.graphql';
36
import epicsSwimlanesQuery from '../graphql/epics_swimlanes.query.graphql';
37
import groupBoardAssigneesQuery from '../graphql/group_board_assignees.query.graphql';
38
import groupBoardIterationsQuery from '../graphql/group_board_iterations.query.graphql';
39
import groupBoardMilestonesQuery from '../graphql/group_board_milestones.query.graphql';
40
import issueMoveListMutation from '../graphql/issue_move_list.mutation.graphql';
41 42 43
import issueSetEpicMutation from '../graphql/issue_set_epic.mutation.graphql';
import issueSetWeightMutation from '../graphql/issue_set_weight.mutation.graphql';
import listUpdateLimitMetricsMutation from '../graphql/list_update_limit_metrics.mutation.graphql';
44
import listsEpicsQuery from '../graphql/lists_epics.query.graphql';
45
import projectBoardAssigneesQuery from '../graphql/project_board_assignees.query.graphql';
46
import projectBoardIterationsQuery from '../graphql/project_board_iterations.query.graphql';
47
import projectBoardMilestonesQuery from '../graphql/project_board_milestones.query.graphql';
48
import updateBoardEpicUserPreferencesMutation from '../graphql/update_board_epic_user_preferences.mutation.graphql';
49

50
import boardsStoreEE from './boards_store_ee';
51
import * as types from './mutation_types';
52

53
const notImplemented = () => {
54
  /* eslint-disable-next-line @gitlab/require-i18n-strings */
55 56 57
  throw new Error('Not implemented!');
};

58 59 60 61 62 63
export const gqlClient = createGqClient(
  {},
  {
    fetchPolicy: fetchPolicies.NO_CACHE,
  },
);
64 65

const fetchAndFormatListIssues = (state, extraVariables) => {
66
  const { fullPath, boardId, boardType, filterParams } = state;
67 68 69 70 71 72 73

  const variables = {
    fullPath,
    boardId: fullBoardId(boardId),
    filters: { ...filterParams },
    isGroup: boardType === BoardType.group,
    isProject: boardType === BoardType.project,
74
    ...extraVariables,
75 76 77 78 79 80 81 82 83 84 85 86
  };

  return gqlClient
    .query({
      query: listsIssuesQuery,
      context: {
        isSingleRequest: true,
      },
      variables,
    })
    .then(({ data }) => {
      const { lists } = data[boardType]?.board;
87
      return { listItems: formatListIssues(lists), listPageInfo: formatListsPageInfo(lists) };
88 89
    });
};
90

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
const fetchAndFormatListEpics = (state, extraVariables) => {
  const { fullPath, boardId, filterParams } = state;

  const variables = {
    fullPath,
    boardId: fullEpicBoardId(boardId),
    filters: { ...filterParams },
    ...extraVariables,
  };

  return gqlClient
    .query({
      query: listsEpicsQuery,
      context: {
        isSingleRequest: true,
      },
      variables,
    })
    .then(({ data }) => {
      const { lists } = data.group?.epicBoard;
111
      return { listItems: formatListEpics(lists), listPageInfo: formatEpicListsPageInfo(lists) };
112 113 114
    });
};

115 116 117
export default {
  ...actionsCE,

118
  setFilters: ({ commit, dispatch, getters }, filters) => {
119 120 121 122 123 124
    const filterParams = pick(filters, [
      'assigneeUsername',
      'authorUsername',
      'epicId',
      'labelName',
      'milestoneTitle',
125
      'iterationTitle',
126 127 128 129 130
      'releaseTag',
      'search',
      'weight',
    ]);

131 132 133 134
    // Temporarily disabled until negated filters are supported for epic boards
    if (!getters.isEpicBoard) {
      filterParams.not = transformNotFilters(filters);
    }
135

136 137 138 139
    if (filters.groupBy === GroupByParamType.epic) {
      dispatch('setEpicSwimlanes');
    }

140 141 142 143 144 145
    if (filterParams.epicId === EpicFilterType.any || filterParams.epicId === EpicFilterType.none) {
      filterParams.epicWildcardId = filterParams.epicId.toUpperCase();
      filterParams.epicId = undefined;
    } else if (filterParams.epicId) {
      filterParams.epicId = fullEpicId(filterParams.epicId);
    }
146
    if (!getters.isEpicBoard && filterParams.not.epicId) {
147 148
      filterParams.not.epicId = fullEpicId(filterParams.not.epicId);
    }
149 150 151

    if (
      filters.iterationId === IterationFilterType.any ||
152 153
      filters.iterationId === IterationFilterType.none ||
      filters.iterationId === IterationFilterType.current
154 155 156 157
    ) {
      filterParams.iterationWildcardId = filters.iterationId.toUpperCase();
    }

158 159 160
    commit(types.SET_FILTERS, filterParams);
  },

161
  performSearch({ dispatch, getters }) {
162 163 164 165 166 167 168 169
    dispatch(
      'setFilters',
      convertObjectPropsToCamelCase(urlParamsToObject(window.location.search)),
    );

    if (getters.isSwimlanesOn) {
      dispatch('resetEpics');
      dispatch('resetIssues');
170 171
      dispatch('fetchEpicsSwimlanes');
      dispatch('fetchIssueLists');
172
    } else if (gon.features.graphqlBoardLists || getters.isEpicBoard) {
173 174 175 176 177
      dispatch('fetchLists');
      dispatch('resetIssues');
    }
  },

178
  fetchEpicsSwimlanes({ state, commit, dispatch }, { endCursor = null } = {}) {
179
    const { fullPath, boardId, boardType, filterParams } = state;
Florie Guibert's avatar
Florie Guibert committed
180 181 182 183 184 185 186

    const variables = {
      fullPath,
      boardId: `gid://gitlab/Board/${boardId}`,
      issueFilters: filterParams,
      isGroup: boardType === BoardType.group,
      isProject: boardType === BoardType.project,
187
      after: endCursor,
Florie Guibert's avatar
Florie Guibert committed
188 189 190 191
    };

    return gqlClient
      .query({
192
        query: epicsSwimlanesQuery,
Florie Guibert's avatar
Florie Guibert committed
193 194 195
        variables,
      })
      .then(({ data }) => {
196
        const { epics } = data[boardType]?.board;
197
        const epicsFormatted = epics.edges.map((e) => ({
198
          ...e.node,
Florie Guibert's avatar
Florie Guibert committed
199 200
        }));

201 202 203 204 205
        if (epicsFormatted) {
          commit(types.RECEIVE_EPICS_SUCCESS, {
            epics: epicsFormatted,
            canAdminEpic: epics.edges[0]?.node?.userPermissions?.adminEpic,
          });
206
          commit(types.UPDATE_CACHED_EPICS, epicsFormatted);
Florie Guibert's avatar
Florie Guibert committed
207 208
        }

209 210 211 212 213 214 215
        if (epics.pageInfo?.hasNextPage) {
          dispatch('fetchEpicsSwimlanes', {
            endCursor: epics.pageInfo.endCursor,
          });
        }
      })
      .catch(() => commit(types.RECEIVE_SWIMLANES_FAILURE));
Florie Guibert's avatar
Florie Guibert committed
216 217
  },

Rajat Jain's avatar
Rajat Jain committed
218
  updateBoardEpicUserPreferences({ commit, state }, { epicId, collapsed }) {
219
    const { boardId } = state;
Rajat Jain's avatar
Rajat Jain committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249

    const variables = {
      boardId: fullBoardId(boardId),
      epicId,
      collapsed,
    };

    return gqlClient
      .mutate({
        mutation: updateBoardEpicUserPreferencesMutation,
        variables,
      })
      .then(({ data }) => {
        if (data?.updateBoardEpicUserPreferences?.errors.length) {
          throw new Error();
        }

        const { epicUserPreferences: userPreferences } = data?.updateBoardEpicUserPreferences;
        commit(types.SET_BOARD_EPIC_USER_PREFERENCES, { epicId, userPreferences });
      })
      .catch(() => {
        commit(types.SET_BOARD_EPIC_USER_PREFERENCES, {
          epicId,
          userPreferences: {
            collapsed: !collapsed,
          },
        });
      });
  },

250 251
  setShowLabels({ commit }, val) {
    commit(types.SET_SHOW_LABELS, val);
252 253
  },

254 255 256 257
  updateListWipLimit({ commit, getters }, { maxIssueCount, listId }) {
    if (getters.shouldUseGraphQL) {
      return gqlClient
        .mutate({
258
          mutation: listUpdateLimitMetricsMutation,
259 260 261 262 263 264 265 266 267 268 269 270 271 272
          variables: {
            input: {
              listId,
              maxIssueCount,
            },
          },
        })
        .then(({ data }) => {
          if (data?.boardListUpdateLimitMetrics?.errors.length) {
            commit(types.UPDATE_LIST_FAILURE);
          } else {
            const list = data.boardListUpdateLimitMetrics?.list;
            commit(types.UPDATE_LIST_SUCCESS, {
              listId,
273
              list,
274 275 276 277 278
            });
          }
        })
        .catch(() => commit(types.UPDATE_LIST_FAILURE));
    }
279

280
    return axios.put(`${boardsStoreEE.store.state.endpoints.listsEndpoint}/${listId}`, {
281 282 283 284 285
      list: {
        max_issue_count: maxIssueCount,
      },
    });
  },
286

287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
  fetchAllBoards: () => {
    notImplemented();
  },

  fetchRecentBoards: () => {
    notImplemented();
  },

  deleteBoard: () => {
    notImplemented();
  },

  updateIssueWeight: () => {
    notImplemented();
  },

303 304 305 306
  fetchItemsForList: (
    { state, commit, getters },
    { listId, fetchNext = false, noEpicIssues = false },
  ) => {
307
    commit(types.REQUEST_ITEMS_FOR_LIST, { listId, fetchNext });
308

309 310 311 312
    const { epicId, ...filterParams } = state.filterParams;
    if (noEpicIssues && epicId !== undefined) {
      return null;
    }
313 314 315 316

    const variables = {
      id: listId,
      filters: noEpicIssues
317
        ? { ...filterParams, epicWildcardId: EpicFilterType.none.toUpperCase() }
318
        : { ...filterParams, epicId },
319 320
      after: fetchNext ? state.pageInfoByListId[listId].endCursor : undefined,
      first: 20,
321 322
    };

323
    if (getters.isEpicBoard) {
324
      return fetchAndFormatListEpics(state, variables)
325
        .then(({ listItems, listPageInfo }) => {
326
          commit(types.RECEIVE_ITEMS_FOR_LIST_SUCCESS, {
327
            listItems,
328 329 330 331 332 333 334 335
            listPageInfo,
            listId,
            noEpicIssues,
          });
        })
        .catch(() => commit(types.RECEIVE_ITEMS_FOR_LIST_FAILURE, listId));
    }

336
    return fetchAndFormatListIssues(state, variables)
337
      .then(({ listItems, listPageInfo }) => {
338
        commit(types.RECEIVE_ITEMS_FOR_LIST_SUCCESS, {
339
          listItems,
340 341 342 343
          listPageInfo,
          listId,
          noEpicIssues,
        });
344
      })
345
      .catch(() => commit(types.RECEIVE_ITEMS_FOR_LIST_FAILURE, listId));
346 347 348 349 350 351 352 353 354 355 356 357
  },

  fetchIssuesForEpic: ({ state, commit }, epicId) => {
    commit(types.REQUEST_ISSUES_FOR_EPIC, epicId);

    const { filterParams } = state;

    const variables = {
      filters: { ...filterParams, epicId },
    };

    return fetchAndFormatListIssues(state, variables)
358 359
      .then(({ listItems }) => {
        commit(types.RECEIVE_ISSUES_FOR_EPIC_SUCCESS, { ...listItems, epicId });
360 361 362 363
      })
      .catch(() => commit(types.RECEIVE_ISSUES_FOR_EPIC_FAILURE, epicId));
  },

Florie Guibert's avatar
Florie Guibert committed
364
  toggleEpicSwimlanes: ({ state, commit, dispatch }) => {
365
    commit(types.TOGGLE_EPICS_SWIMLANES);
366 367

    if (state.isShowingEpicsSwimlanes) {
368 369 370 371 372
      historyPushState(
        mergeUrlParams({ group_by: GroupByParamType.epic }, window.location.href, {
          spreadArrays: true,
        }),
      );
373 374
      dispatch('fetchEpicsSwimlanes');
      dispatch('fetchIssueLists');
375
    } else if (!gon.features.graphqlBoardLists) {
376
      historyPushState(removeParams(['group_by']), window.location.href, true);
377 378
      boardsStore.create();
      eventHub.$emit('initialBoardLoad');
379
    } else {
380
      historyPushState(removeParams(['group_by']), window.location.href, true);
381 382
    }
  },
383

384
  setEpicSwimlanes: ({ commit }) => {
385 386 387
    commit(types.SET_EPICS_SWIMLANES);
  },

388 389 390
  resetEpics: ({ commit }) => {
    commit(types.RESET_EPICS);
  },
391

392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
  fetchEpicForActiveIssue: async ({ state, commit, getters }) => {
    if (!getters.activeIssue.epic) {
      return false;
    }

    const {
      epic: { id, iid },
    } = getters.activeIssue;

    if (state.epicsCacheById[id]) {
      return false;
    }

    commit(types.SET_EPIC_FETCH_IN_PROGRESS, true);

    try {
      const {
        data: {
          group: { epic },
        },
      } = await gqlClient.query({
        query: epicQuery,
        variables: {
          fullPath: getters.groupPathForActiveIssue,
          iid,
        },
      });

      commit(types.UPDATE_CACHED_EPICS, [epic]);
    } finally {
      commit(types.SET_EPIC_FETCH_IN_PROGRESS, false);
    }

    return true;
  },

  setActiveIssueEpic: async ({ state, commit, getters }, epicId) => {
    commit(types.SET_EPIC_FETCH_IN_PROGRESS, true);

431
    const { data } = await gqlClient.mutate({
432
      mutation: issueSetEpicMutation,
433 434
      variables: {
        input: {
435
          iid: String(getters.activeIssue.iid),
436 437
          epicId,
          projectPath: getters.projectPathForActiveIssue,
438 439 440 441 442 443 444 445
        },
      },
    });

    if (data.issueSetEpic.errors?.length > 0) {
      throw new Error(data.issueSetEpic.errors);
    }

446 447 448
    const { epic } = data.issueSetEpic.issue;

    if (epic !== null) {
449
      commit(types.RECEIVE_EPICS_SUCCESS, { epics: [epic, ...state.epics] });
450 451 452 453 454 455 456 457 458
      commit(types.UPDATE_CACHED_EPICS, [epic]);
    }

    commit(typesCE.UPDATE_ISSUE_BY_ID, {
      issueId: getters.activeIssue.id,
      prop: 'epic',
      value: epic ? { id: epic.id, iid: epic.iid } : null,
    });
    commit(types.SET_EPIC_FETCH_IN_PROGRESS, false);
459
  },
460

461 462
  setActiveIssueWeight: async ({ commit, getters }, input) => {
    const { data } = await gqlClient.mutate({
463
      mutation: issueSetWeightMutation,
464 465
      variables: {
        input: {
466
          iid: String(getters.activeIssue.iid),
467 468 469 470 471 472 473 474 475 476 477
          weight: input.weight,
          projectPath: input.projectPath,
        },
      },
    });

    if (!data.issueSetWeight || data.issueSetWeight?.errors?.length > 0) {
      throw new Error(data.issueSetWeight?.errors);
    }

    commit(typesCE.UPDATE_ISSUE_BY_ID, {
478
      issueId: getters.activeIssue.id,
479 480 481 482 483
      prop: 'weight',
      value: data.issueSetWeight.issue.weight,
    });
  },

484 485 486 487 488 489 490 491
  moveItem: ({ getters, dispatch }, params) => {
    if (!getters.isEpicBoard) {
      dispatch('moveIssue', params);
    } else {
      dispatch('moveEpic', params);
    }
  },

492 493
  moveIssue: (
    { state, commit },
494
    { itemId, itemIid, itemPath, fromListId, toListId, moveBeforeId, moveAfterId, epicId },
495
  ) => {
496
    const originalIssue = state.boardItems[itemId];
497
    const fromList = state.boardItemsByListId[fromListId];
498
    const originalIndex = fromList.indexOf(Number(itemId));
499 500 501 502 503 504 505 506 507
    commit(types.MOVE_ISSUE, {
      originalIssue,
      fromListId,
      toListId,
      moveBeforeId,
      moveAfterId,
      epicId,
    });

508
    const { boardId } = state;
509
    const [fullProjectPath] = itemPath.split(/[#]/);
510 511 512 513 514 515 516

    gqlClient
      .mutate({
        mutation: issueMoveListMutation,
        variables: {
          projectPath: fullProjectPath,
          boardId: fullBoardId(boardId),
517
          iid: itemIid,
518 519 520 521 522 523 524 525 526
          fromListId: getIdFromGraphQLId(fromListId),
          toListId: getIdFromGraphQLId(toListId),
          moveBeforeId,
          moveAfterId,
          epicId,
        },
      })
      .then(({ data }) => {
        if (data?.issueMoveList?.errors.length) {
527
          throw new Error();
528 529 530 531 532 533 534 535 536
        } else {
          const issue = data.issueMoveList?.issue;
          commit(types.MOVE_ISSUE_SUCCESS, { issue });
        }
      })
      .catch(() =>
        commit(types.MOVE_ISSUE_FAILURE, { originalIssue, fromListId, toListId, originalIndex }),
      );
  },
537

538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
  moveEpic: ({ state, commit }, { itemId, fromListId, toListId, moveBeforeId, moveAfterId }) => {
    const originalEpic = state.boardItems[itemId];
    const fromList = state.boardItemsByListId[fromListId];
    const originalIndex = fromList.indexOf(Number(itemId));
    commit(types.MOVE_EPIC, {
      originalEpic,
      fromListId,
      toListId,
      moveBeforeId,
      moveAfterId,
    });

    const { boardId } = state;

    gqlClient
      .mutate({
        mutation: epicMoveListMutation,
        variables: {
          epicId: fullEpicId(itemId),
          boardId: fullEpicBoardId(boardId),
          fromListId,
          toListId,
        },
      })
      .then(({ data }) => {
        if (data?.epicMoveList?.errors.length) {
564
          throw new Error();
565 566 567 568 569 570 571
        }
      })
      .catch(() =>
        commit(types.MOVE_EPIC_FAILURE, { originalEpic, fromListId, toListId, originalIndex }),
      );
  },

572 573
  fetchLists: ({ getters, dispatch }) => {
    if (!getters.isEpicBoard) {
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
      dispatch('fetchIssueLists');
    } else {
      dispatch('fetchEpicLists');
    }
  },

  fetchEpicLists: ({ commit, state }) => {
    const { filterParams, fullPath, boardId } = state;

    const variables = {
      fullPath,
      boardId: fullEpicBoardId(boardId),
      filters: filterParams,
    };

    return gqlClient
      .query({
        query: epicBoardListsQuery,
        variables,
      })
      .then(({ data }) => {
        const { lists } = data.group?.epicBoard;
        commit(types.RECEIVE_BOARD_LISTS_SUCCESS, formatBoardLists(lists));
      })
      .catch(() => commit(types.RECEIVE_BOARD_LISTS_FAILURE));
  },
600

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
  fetchMilestones({ state, commit }, searchTerm) {
    commit(types.RECEIVE_MILESTONES_REQUEST);

    const { fullPath, boardType } = state;

    const variables = {
      fullPath,
      searchTerm,
    };

    let query;
    if (boardType === BoardType.project) {
      query = projectBoardMilestonesQuery;
    }
    if (boardType === BoardType.group) {
      query = groupBoardMilestonesQuery;
    }

    if (!query) {
      // eslint-disable-next-line @gitlab/require-i18n-strings
      throw new Error('Unknown board type');
    }

    return gqlClient
      .query({
        query,
        variables,
      })
      .then(({ data }) => {
        const errors = data[boardType]?.errors;
        const milestones = data[boardType]?.milestones.nodes;

        if (errors?.[0]) {
          throw new Error(errors[0]);
        }

        commit(types.RECEIVE_MILESTONES_SUCCESS, milestones);
      })
      .catch((e) => {
        commit(types.RECEIVE_MILESTONES_FAILURE);
        throw e;
      });
  },

645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
  fetchIterations({ state, commit }, title) {
    commit(types.RECEIVE_ITERATIONS_REQUEST);

    const { fullPath, boardType } = state;

    const variables = {
      fullPath,
      title,
    };

    let query;
    if (boardType === BoardType.project) {
      query = projectBoardIterationsQuery;
    }
    if (boardType === BoardType.group) {
      query = groupBoardIterationsQuery;
    }

    if (!query) {
      // eslint-disable-next-line @gitlab/require-i18n-strings
      throw new Error('Unknown board type');
    }

    return gqlClient
      .query({
        query,
        variables,
      })
      .then(({ data }) => {
        const errors = data[boardType]?.errors;
        const iterations = data[boardType]?.iterations.nodes;

        if (errors?.[0]) {
          throw new Error(errors[0]);
        }

        commit(types.RECEIVE_ITERATIONS_SUCCESS, iterations);
      })
      .catch((e) => {
        commit(types.RECEIVE_ITERATIONS_FAILURE);
        throw e;
      });
  },

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
  fetchAssignees({ state, commit }, search) {
    commit(types.RECEIVE_ASSIGNEES_REQUEST);

    const { fullPath, boardType } = state;

    const variables = {
      fullPath,
      search,
    };

    let query;
    if (boardType === BoardType.project) {
      query = projectBoardAssigneesQuery;
    }
    if (boardType === BoardType.group) {
      query = groupBoardAssigneesQuery;
    }

    if (!query) {
      // eslint-disable-next-line @gitlab/require-i18n-strings
      throw new Error('Unknown board type');
    }

    return gqlClient
      .query({
        query,
        variables,
      })
      .then(({ data }) => {
        const [firstError] = data.workspace.errors || [];
        const assignees = data.workspace.assignees.nodes;

        if (firstError) {
          throw new Error(firstError);
        }
        commit(
          types.RECEIVE_ASSIGNEES_SUCCESS,
          assignees.map(({ user }) => user),
        );
      })
      .catch((e) => {
        commit(types.RECEIVE_ASSIGNEES_FAILURE);
        throw e;
      });
  },

735 736 737 738
  createList: (
    { getters, dispatch },
    { backlog, labelId, milestoneId, assigneeId, iterationId },
  ) => {
739
    if (!getters.isEpicBoard) {
740
      dispatch('createIssueList', { backlog, labelId, milestoneId, assigneeId, iterationId });
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
    } else {
      dispatch('createEpicList', { backlog, labelId });
    }
  },

  createEpicList: ({ state, commit, dispatch, getters }, { backlog, labelId }) => {
    const { boardId } = state;

    const existingList = getters.getListByLabelId(labelId);

    if (existingList) {
      dispatch('highlightList', existingList.id);
      return;
    }

    gqlClient
      .mutate({
        mutation: createEpicBoardListMutation,
        variables: {
          boardId: fullEpicBoardId(boardId),
          backlog,
          labelId,
        },
      })
      .then(({ data }) => {
        if (data?.epicBoardListCreate?.errors.length) {
767
          commit(types.CREATE_LIST_FAILURE, data.epicBoardListCreate.errors[0]);
768 769 770 771 772 773 774 775 776 777 778
        } else {
          const list = data.epicBoardListCreate?.list;
          dispatch('addList', list);
          dispatch('highlightList', list.id);
        }
      })
      .catch((e) => {
        commit(types.CREATE_LIST_FAILURE);
        throw e;
      });
  },
779
};