Skip to content

Add labels and assignees widgets to work items create mutation

What does this MR do and why?

Related to #456119 (closed)

Add support for setting labels and when creating a work item. These arguments are needed for !144705 (closed) (see !144705 (comment 1861625817) for more context).

Summary of changes:

  • Assignees widget: The callback before_create was added to WorkItems::Callbacks::Assignees to set assignees during the work item creation.
  • Labels widget: Add a new input file LabelsCreateInputType because the existing LabelsUpdateInputType uses different arguments than the one needed for the WI creation. This widget hasn't been refactored to use a callback class yet but we do have the WorkItems::Widgets::LabelsService::CreateService which works for setting the param.

MR acceptance checklist

Screenshots or screen recordings

mutation result
Screenshot_2024-04-23_at_15.25.29 Screenshot_2024-04-23_at_15.27.09

How to set up and validate locally

  1. Enable feature flag namespace_level_work_items
  2. Visit a group and create two labels in it
  3. Visit https://gdk.test:3000/-/graphql-explorer and test the following query using the corresponding IDs
query
query getWorkItemTypeId{
  workspace: group(fullPath: "group-a") {
    workItemTypes(name: EPIC) {
      edges {
        node {
          id #=> E.g. "gid://gitlab/WorkItems::Type/8" but can be different in your local environment 
        }
      }
    }
  }
}

mutation createWIEpic {
  workItemCreate(input: {
    namespacePath: "group-a", title: "Epic WI with assignees, labels, color and health status",
    workItemTypeId: "gid://gitlab/WorkItems::Type/8",
    assigneesWidget: {assigneeIds: ["gid://gitlab/User/1", "gid://gitlab/User/2"]},
    labelsWidget: {labelIds: ["gid://gitlab/GroupLabel/<label_1_id>", "gid://gitlab/GroupLabel/<label_2_id>"]},
  }) {
    errors
    workItem {
      id
      webUrl
      widgets {
        ... on WorkItemWidgetAssignees {
          assignees {
            edges {
              node {
                username
              }
            }
          }
        }
        ... on WorkItemWidgetLabels {
          labels {
            edges {
              node {
                title
              }
            }
          }
        }
      }
    }
  }
}
response
{
  "data": {
    "workItemCreate": {
      "errors": [],
      "workItem": {
        "id": "gid://gitlab/WorkItem/602",
        "webUrl": "http://127.0.0.1:3000/groups/group-a/-/work_items/138",
        "widgets": [
          {},
          {
            "assignees": {
              "edges": [
                {
                  "node": {
                    "username": "root"
                  }
                },
                {
                  "node": {
                    "username": "stephany_grant"
                  }
                }
              ]
            }
          },
          {
            "labels": {
              "edges": [
                {
                  "node": {
                    "title": "Green"
                  }
                },
                {
                  "node": {
                    "title": "Pink"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
}
  1. Visit the work item list using http://gdk.test:3000/groups/GROUP_PATH/-/work_items and verify that the the work item was created with the set arguments

Related to #456119 (closed)

Edited by Eugenia Grieff

Merge request reports