Skip to content

Expose max_depth limit reached in Hierarchy widget

What does this MR do and why?

Currently if user creates a child work item beyond a permitted depth limit (9 levels for OKRs and 7 levels for Epics), the mutation fails with an appropriate error. We're looking to improve the UX by disabling the ability to create child items in such cases as a part of #474312 (closed), this means frontend should be able to figure out the current depth level as well as the maximum depth supported for a given work item parent type.

The WorkItemWidgetHierarchy can be updated to include depthLimitReached based on the work item type such that frontend can use it to disable the ability to add items on UI.

Issue: #474910 (comment 2086816930)

How to set up and validate locally

  1. Enable work item epics and the work item epics list using these feature flags: work_item_epics_rollout, work_item_epics, namespace_level_work_items, work_item_epics_list.
  2. Visit the page and create sub epic.
  3. Use the following GraphQl query to fetch all available child types and if they have reached max depth limit.
GraphQl Query
query namespaceWorkItem($fullPath: ID!, $iid: String!) {
  workspace: namespace(fullPath: $fullPath) {
    id
    workItem(iid: $iid) {
      ...WorkItem
      __typename
    }
    __typename
  }
}

fragment WorkItem on WorkItem {
  id
  iid
  
  title
  
  namespace {
    id
    fullPath
    name
    __typename
  }
  workItemType {
    id
    name
    iconName
    __typename
  }

  widgets {
    ...WorkItemWidgets
    __typename
  }
  __typename
}

fragment WorkItemWidgets on WorkItemWidget {
  type
  ... on WorkItemWidgetHierarchy {
    hasChildren
    hasParent
    depthLimitReachedByType {
      workItemType {
        name
      }
      depthLimitReached
    }
    __typename
  }
  __typename
}
Response
{
  "data": {
    "workspace": {
      "id": "gid://gitlab/Group/33",
      "workItem": {
        "id": "gid://gitlab/WorkItem/670",
        "iid": "7",
        "title": "testttttttt",
        "namespace": {
          "id": "gid://gitlab/Group/33",
          "fullPath": "flightjs",
          "name": "Flightjs",
          "__typename": "Namespace"
        },
        "workItemType": {
          "id": "gid://gitlab/WorkItems::Type/8",
          "name": "Epic",
          "iconName": "issue-type-epic",
          "__typename": "WorkItemType"
        },
        "widgets": [
          {
            "type": "ASSIGNEES",
            "__typename": "WorkItemWidgetAssignees"
          },
          {
            "type": "DESCRIPTION",
            "__typename": "WorkItemWidgetDescription"
          },
          {
            "type": "HIERARCHY",
            "hasChildren": true,
            "hasParent": true,
            "depthLimitReachedByType": [
              {
                "workItemType": {
                  "name": "Epic"
                },
                "depthLimitReached": true
              },
              {
                "workItemType": {
                  "name": "Issue"
                },
                "depthLimitReached": false
              },
              {
                "workItemType": {
                  "name": "Task"
                },
                "depthLimitReached": false
              }
            ],
            "__typename": "WorkItemWidgetHierarchy"
          },
          {
            "type": "LABELS",
            "__typename": "WorkItemWidgetLabels"
          },
          {
            "type": "NOTES",
            "__typename": "WorkItemWidgetNotes"
          },
          {
            "type": "START_AND_DUE_DATE",
            "__typename": "WorkItemWidgetStartAndDueDate"
          },
          {
            "type": "HEALTH_STATUS",
            "__typename": "WorkItemWidgetHealthStatus"
          },
          {
            "type": "STATUS",
            "__typename": "WorkItemWidgetStatus"
          },
          {
            "type": "NOTIFICATIONS",
            "__typename": "WorkItemWidgetNotifications"
          },
          {
            "type": "CURRENT_USER_TODOS",
            "__typename": "WorkItemWidgetCurrentUserTodos"
          },
          {
            "type": "AWARD_EMOJI",
            "__typename": "WorkItemWidgetAwardEmoji"
          },
          {
            "type": "LINKED_ITEMS",
            "__typename": "WorkItemWidgetLinkedItems"
          },
          {
            "type": "COLOR",
            "__typename": "WorkItemWidgetColor"
          },
          {
            "type": "ROLLEDUP_DATES",
            "__typename": "WorkItemWidgetRolledupDates"
          },
          {
            "type": "PARTICIPANTS",
            "__typename": "WorkItemWidgetParticipants"
          },
          {
            "type": "WEIGHT",
            "__typename": "WorkItemWidgetWeight"
          },
          {
            "type": "TIME_TRACKING",
            "__typename": "WorkItemWidgetTimeTracking"
          }
        ],
        "__typename": "WorkItem"
      },
      "__typename": "Namespace"
    }
  }
}
  1. Change epic - epic restriction to 2 from console using the following
Console commands
t = WorkItems::Type.where(name: 'Epic').first
r = WorkItems::HierarchyRestriction.where(parent_type_id: t.id, child_type_id: t.id).first
r.update(maximum_depth: 2)
  1. The parent should return depthLimitReached as false and for sub-epic should return true.
Edited by Abhilash Kotte

Merge request reports

Loading