Skip to content

Adds sort order by relative_position to Work Item Hierarchy Widget

What does this MR do and why?

When fetching work item's children with Work Item Hierarchy Widget, ensures they are ordered by relative_position. When relative_position is not set, orders by created_at.

This is a part of ongoing effort to enable manual reordering of Work Item children.

Related to BE: Work Items - Ability to reorder work items ... (#370401 - closed)

Related to TASK: Add sorting by relative_position to children field in Work Items Hierarchy Widget

Screenshots or screen recordings

Screenshot_2023-01-25_at_15.05.34

DB query details

SELECT
    "issues".*
FROM
    "issues"
    INNER JOIN "work_item_parent_links" ON "issues"."id" = "work_item_parent_links"."work_item_id"
WHERE
    "work_item_parent_links"."work_item_parent_id" = 121880239
ORDER BY
    "work_item_parent_links"."relative_position" ASC NULLS LAST,
    "issues"."created_at" ASC
LIMIT 101

Query plan (internal): https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/14833/commands/51767

How to set up and validate locally

1. Local Test scenario background setup.

  • Create a new Issue:
    • Add five tasks to the issue named Position Task #1, Position Task #2 ... Position Task #5.
      • Verify new tasks are added to the end of the list, which is consistent behaviour.
      • Reload the page in the browser, and verify Position Task #1 appears at the top of the list.
  • In the local GDK rails console, executed the snippet
middle_item = WorkItem.where(title: "Position Task #3").last
middle_item.created_at = 10.minutes.ago
middle_item.save

positioned_item_parent_link = WorkItem.where(title: "Position Task #4").last.parent_link
positioned_item_parent_link.relative_position = 1
positioned_item_parent_link.save

2. Local Test scenario verification.

  • Reloaded issue page in the browser and verified:
    • All five tasks are present on the page.
    • Position Task #4 appears at the top of the list.
    • Position Task #3 appears on the second position.
    • All other than Position Task #4 and Position Task #3 work items are present on the page and the order is consistent.

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 Petro Koriakin

Merge request reports