Project

General

Profile

Actions

Defect #40157

closed

Problem with Version types project CFs group titles in filters drop-down boxes

Added by Stoyan Zhekov 4 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Custom fields
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Duplicate
Affected version:

Description

Problem

Redmine-5.1.x does not handle properly group titles in filters drop-down boxes for association type custom fields ( custom field names, containing dot , like Version type - example cf_1.status ). It is trying to implement localization ( l() method) on CF name, which lead to Translation missing error. It should display directly the name , not trying to localize it.
See the attached screenshots for RM-5.0.3 and RM-5.1.0 filters drop-down box in Projects screen.

How to reproduce the problem

1.) Create Version-type project custom field and enable it to be used as a filter - see attached screenshot.
2.) Go to Projects screen and open Filters drop-down box
3.) There will be Translation missing group title

Possible fix for the problem

I think the problem originates in changing the orders of matchers in app/helpers/queries_helper.rb file, filters_options_for_select(query) method.

Up to RM-5.0 the /^cf_\d+\./.match?(field) matcher was taking place before field =~ /^(.+)\./ one. In RM-5.1 this matcher is on the top, so it is the first executed on CF names, containing dot (for example cf_1.status - version-type CF).

As a result group name cf_1 becomes :field_cf_1, which later, in localized_grouped = grouped.map {|k, v| [k.is_a?(Symbol) ? l(k) : k.to_s, v]} line is never resolved (because it is unknown symbol, should be just the CF name ), leading to translation missing error for the group name.

The debug flow for filters_options_for_select(query) execution in RM-5.0.x vs RM-5.1.x for version-type CF follows:

RM-5.0.3 - proper group name handling

field: "cf_6" 
field opts: name=Sprint type=list_optional
group: nil
grouped: {}
ungrouped: [["プロジェクト", "id"], ["プロジェクトのステータス", "status"], ["Sprint", "cf_6"]]

field: "cf_6.due_date" 
field opts: name=Sprintの 期日 type=date
cf_: Sprint   <-  ---[ !!!  matcher: /^cf_\d+\./.match?(field) , ここで cf_1 から名前に立ってる ]---
group: "Sprint" 
grouped: {"Sprint"=>[["Sprintの 期日", "cf_6.due_date"]]}
ungrouped: [["プロジェクト", "id"], ["プロジェクトのステータス", "status"], ["Sprint", "cf_6"]]

field: "cf_6.status" 
field opts: name=Sprintの ステータス type=list
cf_: Sprint
group: "Sprint" 
grouped: {"Sprint"=>[["Sprintの 期日", "cf_6.due_date"], ["Sprintのステータス", "cf_6.status"]]}
ungrouped: [["プロジェクト", "id"], ["プロジェクトのステータス", "status"], ["Sprint", "cf_6"]]

localized: [["Sprint", [["Sprintの 期日", "cf_6.due_date"], ["Sprintのステータス", "cf_6.status"]]]]

RM-5.1.0 - translation missing error for group name

field: "cf_3" 
field opts: name=Sprint type=list_optional
group: nil
grouped: {:label_string=>[], :label_date=>[], :label_time_tracking=>[], :label_attachment=>[]}
ungrouped: [["プロジェクト", "id"], ["プロジェクトのステータス", "status"], ["Sprint", "cf_3"]]

field: "cf_3.due_date" 
field opts: name=Sprintの 期日 type=date
association: cf_3  <- ---[ !!! matcher: field =~ /^(.+)\./ , ここで cf_3からfield_cf_3になる ]---
group: :field_cf_3
grouped: {:label_string=>[], :label_date=>[], :label_time_tracking=>[], :label_attachment=>[], :field_cf_3=>[["Sprintの 期日", "cf_3.due_date"]]}
ungrouped: [["プロジェクト", "id"], ["プロジェクトのステータス", "status"], ["Sprint", "cf_3"]]

field: "cf_3.status" 
field opts: name=Sprintの ステータス type=list
association: cf_3
group: :field_cf_3
grouped: {:label_string=>[], :label_date=>[], :label_time_tracking=>[], :label_attachment=>[], :field_cf_3=>[["Sprintの 期日", "cf_3.due_date"], ["Sprintの ステータス", "cf_3.status"]]}
ungrouped: [["プロジェクト", "id"], ["プロジェクトのステータス", "status"], ["Sprint", "cf_3"]]

localized: [["Translation missing: ja.field_cf_3", [["Sprintの 期日", "cf_3.due_date"], ["Sprintの ステータス", "cf_3.status"]]]]

To fix the problem, I think, a simple restore of the old matchers order ( /^cf_\d+\./ matcher before /^(.+)\./ one) will be enough:

--- app/helpers/queries_helper.rb.orig    2024-01-31 12:37:14.000000000 +0900
+++ app/helpers/queries_helper.rb    2024-01-31 12:37:47.000000000 +0900
@@ -26,15 +26,15 @@
     ungrouped = []
     grouped = {label_string: [], label_date: [], label_time_tracking: [], label_attachment: []}
     query.available_filters.map do |field, field_options|
-      if field =~ /^(.+)\./
-        # association filters
-        group = "field_#{$1}".to_sym
-      elsif field_options[:type] == :relation
+      if field_options[:type] == :relation
         group = :label_relations
       elsif field_options[:type] == :tree
         group = query.is_a?(IssueQuery) ? :label_relations : nil
       elsif /^cf_\d+\./.match?(field)
         group = (field_options[:through] || field_options[:field]).try(:name)
+      elsif field =~ /^(.+)\./
+        # association filters
+        group = "field_#{$1}".to_sym
       elsif %w(member_of_group assigned_to_role).include?(field)
         group = :field_assigned_to
       elsif field_options[:type] == :date_past || field_options[:type] == :date

Files

filters-5.0.png (25.4 KB) filters-5.0.png Filters drop-down box in RM-5.0.x Stoyan Zhekov, 2024-01-31 04:07
filters-5.1.png (26.7 KB) filters-5.1.png Filters drop-down box in RM-5.1.x Stoyan Zhekov, 2024-01-31 04:07
version_cf.png (17 KB) version_cf.png Version-type project CF Stoyan Zhekov, 2024-01-31 04:07
clipboard-202401311454-vlpi5.png (137 KB) clipboard-202401311454-vlpi5.png Go MAEDA, 2024-01-31 06:54

Related issues

Related to Redmine - Defect #39714: Query grouping filter not working for custom field relationsClosedMarius BĂLTEANU

Actions
Actions #1

Updated by Marius BĂLTEANU 4 months ago

  • Related to Defect #39714: Query grouping filter not working for custom field relations added
Actions #2

Updated by Marius BĂLTEANU 4 months ago

We did some changes in #39714.

Actions #3

Updated by Go MAEDA 4 months ago

I cannot reproduce the issue with the current trunk r22665. I think the issue was fixed in Redmine 5.1.1 (#39714).
Please check if the issue is still reproducible with Redmine 5.1.1.

Actions #4

Updated by Go MAEDA 4 months ago

  • Affected version changed from 5.1.1 to 5.1.0
Actions

Also available in: Atom PDF