Skip to content

[FND-286] Categories - filtering grouping and sorting - #27149

Open
brunopagno wants to merge 5 commits into
devfrom
blp/impl/fnd-286-categories-filters-grouping-sorting
Open

brunopagno wants to merge 5 commits into
devfrom
blp/impl/fnd-286-categories-filters-grouping-sorting

Conversation

@brunopagno

@brunopagno brunopagno commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Ticket

https://community.openproject.org/projects/TC/work_packages/FND-286/activity

What are you trying to accomplish?

Adjust filtering grouping and sorting for categories as multi values

AI involvement

Collaborative – AI generated a substantial part of the code; I reviewed and understand every line

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@brunopagno brunopagno self-assigned this Nov 20, 2026
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/boards/spec/features/board_management_spec.rb[1:1:3]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #27149, linked for reference only):

- `rspec ./modules/boards/spec/features/board_management_spec.rb[1:1:3]`

Treat this as a standalone task, unrelated to PR #27149. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #27149 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @brunopagno to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @brunopagno, and request a review from @brunopagno.
On every commit, set @brunopagno as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@github-actions github-actions Bot added the ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line. label Nov 20, 2026
@brunopagno
brunopagno force-pushed the blp/impl/fnd-286-categories-filters-grouping-sorting branch from 39ba872 to 6794db6 Compare November 24, 2026 08:20
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/boards/spec/features/board_management_spec.rb[1:1:3]
  • rspec ./spec/features/work_packages/sorting/manual_sorting_spec.rb[1:6:2]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #27149, linked for reference only):

- `rspec ./modules/boards/spec/features/board_management_spec.rb[1:1:3]`
- `rspec ./spec/features/work_packages/sorting/manual_sorting_spec.rb[1:6:2]`

Treat this as a standalone task, unrelated to PR #27149. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #27149 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @brunopagno to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @brunopagno, and request a review from @brunopagno.
On every commit, set @brunopagno as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@brunopagno
brunopagno marked this pull request as ready for review November 24, 2026 08:50
@brunopagno
brunopagno requested a review from a team November 24, 2026 08:50
@brunopagno
brunopagno added this pull request to stack #27230 November 24, 2026 14:02
@brunopagno
brunopagno force-pushed the blp/impl/fnd-286-categories-filters-grouping-sorting branch from 6794db6 to 772caeb Compare November 24, 2026 14:08
@brunopagno
brunopagno removed this pull request from stack #27230 November 24, 2026 14:09
@brunopagno
brunopagno added this pull request to stack #27243 November 24, 2026 15:25
@brunopagno
brunopagno force-pushed the blp/impl/fnd-286-categories-filters-grouping-sorting branch from 3f380a1 to 60489b5 Compare November 26, 2026 13:55
Comment on lines +228 to +248
# Only the single category_id is journaled, so the join table read by
# `Queries::WorkPackages::Filter::CategoryFilter` is swapped for a stand-in built from it:
#
# before: SELECT 1 FROM "work_package_categories" WHERE (work_package_categories.work_package_id = ...
# after: SELECT 1 FROM (SELECT work_packages.id AS work_package_id, work_packages.category_id
# WHERE work_packages.category_id IS NOT NULL) "work_package_categories" WHERE ...
def substitute_work_package_categories_join_in_predicate(predicate)
return unless predicate.is_a? String

join_table_source = "FROM \"#{WorkPackageCategory.table_name}\""
journaled_category_source = "FROM (#{journaled_work_package_categories_sql}) \"#{WorkPackageCategory.table_name}\""

predicate.gsub!(join_table_source, journaled_category_source)
end

def journaled_work_package_categories_sql
<<~SQL.squish
SELECT #{model.table_name}.id AS work_package_id, #{model.table_name}.category_id
WHERE #{model.table_name}.category_id IS NOT NULL
SQL
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍊 The stand-in only knows the one mirrored category_id, so at a baseline a work package that had A and B looks like it only had A: = B misses it and ! B includes it.

#27253 adds work_package_category_journals, same shape as the version journals. Shall we land that one first and swap here the way versions do? The stand-in and its comment can then go:

def substitute_work_package_categories_join_in_predicate(predicate)
  return unless predicate.is_a? String

  category_journals = Journal::WorkPackageCategoryJournal.table_name
  work_package_categories = WorkPackageCategory.table_name
  models = model.table_name

  predicate.gsub! "#{work_package_categories}.work_package_id = #{models}.id",
                  "#{category_journals}.journal_id = #{models}.journal_id"
  predicate.gsub! "\"#{work_package_categories}\"",
                  "\"#{category_journals}\""
end

A baseline example with a two-category work package would pin it down. If this PR goes first instead, the swap can move to #27253.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also take care of this after the fact @brunopagno so all good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was hoping to do a "multi version baseline" in a separate step. This was meant to cover only the current state of things. But probably worth a comment on it.

let!(:beta_wp) { create(:work_package, project:, category_ids_replacements: [beta.id]) }
let!(:uncategorized_wp) { create(:work_package, project:) }

describe "filtering" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍏 Could the flag-on block also cover *, !*, a multi-value = and DESC? With several categories per work package only single-value = and ! are exercised right now.

Comment on lines +125 to +132
describe "#where" do
let(:values) { ["1"] }

it "reads the work_package_categories join rows" do
expect(instance.where).to include("work_package_categories")
expect(instance.where).not_to include("#{WorkPackage.table_name}.category_id")
end
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍏 This only checks that the SQL mentions a table name, which the integration spec already proves by behavior. Drop it? Same for the two "via the work_package_categories join rows" examples in property_select_spec.rb.

akabiru
akabiru previously approved these changes Nov 27, 2026
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/admin/backup_spec.rb[1:3:2]
  • rspec ./spec/features/work_packages/sorting/manual_sorting_spec.rb[1:6:2]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #27149, linked for reference only):

- `rspec ./spec/features/admin/backup_spec.rb[1:3:2]`
- `rspec ./spec/features/work_packages/sorting/manual_sorting_spec.rb[1:6:2]`

Treat this as a standalone task, unrelated to PR #27149. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #27149 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @brunopagno to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @brunopagno, and request a review from @brunopagno.
On every commit, set @brunopagno as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line.

Development

Successfully merging this pull request may close these issues.

2 participants