Project

General

Profile

Actions

Patch #44157

open

Add parent issue as a groupable column in issue query

Added by Yasu Saku about 11 hours ago. Updated about 11 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Issues filter
Target version:
-

Description

Problem

The parent issue column (:parent) in IssueQuery is not available as a grouping option. Users who manage issues with parent-child relationships cannot group issue lists by parent issue, which would be useful for tracking work broken down from epics or stories.

Solution

This patch adds grouping support for the parent issue column by introducing a QueryParentIssueColumn subclass, following the same pattern used by TimestampQueryColumn.

Changes

app/models/query.rb

Add a new QueryParentIssueColumn class:

class QueryParentIssueColumn < QueryColumn
  def groupable?
    true
  end

  def group_by_statement
    "#{Issue.table_name}.parent_id" 
  end

  def group_value(object)
    object.parent
  end
end

Extend group_by_sort_order to handle QueryParentIssueColumn, so that grouping sorts by parent_id while leaving the original sortable (used for column header sorting) unchanged:

      column_sortable = column.sortable
      if column.is_a?(TimestampQueryColumn)
        column_sortable = Redmine::Database.timestamp_to_date(column.sortable, User.current.time_zone)
      elsif column.is_a?(QueryParentIssueColumn)
        column_sortable = "#{Issue.table_name}.parent_id" 
      end

app/models/issue_query.rb

Replace QueryColumn.new(:parent, ...) with QueryParentIssueColumn.new(:parent, ...):

    QueryParentIssueColumn.new(:parent,
                    :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"],
                    :default_order => 'desc', :caption => :field_parent_issue),

Notes

  • Grouping is based on the direct parent only. Multi-level ancestor grouping is not supported.
  • Issues without a parent are grouped under (blank), consistent with other groupable columns.
  • Tested on PostgreSQL with latest trunk ( r24718 ).

Preview


Files

Actions #1

Updated by Yasu Saku about 11 hours ago

I found a bug in the previous patch: the group count badge was not displayed correctly for non-blank groups.

Root cause

result_count_by_group returns a hash keyed by parent_id (Integer), while the view resolves group membership via group_value which returns an Issue object. Since Integer != Issue, only the nil key (blank group) matched correctly.

Additional fix

In grouped_query, convert the Integer keys to Issue objects after counting, following the same pattern used for QueryCustomFieldColumn:

      elsif c.is_a?(QueryParentIssueColumn)
        ids = r.keys.compact
        issues_by_id = Issue.where(id: ids).index_by(&:id)
        r = r.keys.to_h { |k| [k ? issues_by_id[k] : nil, r[k]] }
      end

Preview

Please use the updated patch attached to this comment instead of the previous one.

Actions

Also available in: Atom PDF