Skip to content

Add block counts to linked items widget

Eugenia Grieff requested to merge 416768-query-linked-work-items-2 into master

Related to #416768 (closed)

What does this MR do and why?

This is the following iteration for !126980 (merged) where we added a GraphQL query to expose the items linked to a work item.

Similarly to IssueType, we also want to expose the field blocked, blockedByCount and blockingCount for a work item so these can now be included in the WorkItemWidgetLinkedItems widget added in !126980 (merged).

Summary of changes

  • Extend LinkedItemsType to add the EE scoped fields blocked, blocking_count and blocked_by_count
  • Add a new LazyLinksAggregate file for work item links. This aggregator is used for blocked and blocked_by_count fields
  • Move EE::IssueLink logic to LinkableItem concern so it can be shared with WorkItems::RelatedWorkItemLink. This functionality will refresh the blocking count for a work item when a link is created or destroyed (used by blocking_count field).

I have also included notes inline to explain more specific changes

This feature remains behind the feature flag :linked_work_items

Screenshots or screen recordings

This MR doesn't introduce any UI changes

example query

Screenshot_2023-08-08_at_15.26.09

How to set up and validate locally

  1. Using rails console enable the feature flag
Feature.enable(:linked_work_items)
  1. Create the work items and links
author, project = User.first, Project.first
wi_type = WorkItems::Type.find_by(base_type: 'task')
task = WorkItem.create!(title: "Source Task", project: project, author: author, work_item_type: wi_type)

blocked_task = WorkItem.create!(title: "Blocked Task", project: project, author: author, work_item_type: wi_type)
blocking_task1 = WorkItem.create!(title: "Blocking Task 1", project: project, author: author, work_item_type: wi_type)
blocking_task2 = WorkItem.create!(title: "Blocking Task 2", project: project, author: author, work_item_type: wi_type)

WorkItems::RelatedWorkItemLink.create!(source: task, target: blocked_task, link_type: 'blocks')
WorkItems::RelatedWorkItemLink.create!(source: blocking_task1, target: task, link_type: 'blocks')
WorkItems::RelatedWorkItemLink.create!(source: blocking_task2, target: task, link_type: 'blocks')
  1. Visit https://gdk.test:3000/-/graphql-explorer and verify that the following query returns the expected values
query
query getLinkedITems {
  workItem(id: "gid://gitlab/WorkItem/NOTE_ID") {
    widgets {
      ...on WorkItemWidgetLinkedItems {
        blocked
        blockingCount
        blockedByCount
        linkedItems {
          edges {
            node {
              linkType
              workItem {
                title
              }
            }
          }
        }
      }
    }
  }
}
response
{
  "data": {
    "workItem": {
      "widgets": [
        {
          "blocked": true,
          "blockingCount": 1,
          "blockedByCount": 2,
          "linkedItems": {
            "edges": [
              {
                "node": {
                  "linkType": "blocks",
                  "workItem": {
                    "title": "Blocked Task"
                  }
                }
              },
              {
                "node": {
                  "linkType": "is_blocked_by",
                  "workItem": {
                    "title": "Blocking Task 1"
                  }
                }
              },
              {
                "node": {
                  "linkType": "is_blocked_by",
                  "workItem": {
                    "title": "Blocking Task 2"
                  }
                }
              }
            ]
          }
        },
        {}
      ]
    }
  }
}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugenia Grieff

Merge request reports

Loading