Skip to content

fix: enable sorting on computed records_count column in top teams widget#130

Merged
ManukMinasyan merged 1 commit intomainfrom
fix/top-teams-records-count-sorting
Feb 16, 2026
Merged

fix: enable sorting on computed records_count column in top teams widget#130
ManukMinasyan merged 1 commit intomainfrom
fix/top-teams-records-count-sorting

Conversation

@ManukMinasyan
Copy link
Copy Markdown
Contributor

Summary

  • Extract getDateRange() method from buildQuery() so it can be reused in the column's custom sortable query
  • Add custom sortable() closure on the records_count column using orderByRaw with the same subquery expression
  • Fixes sorting on the computed records count column which previously failed silently

Test plan

  • Verify sorting by "Records" column works in both directions on the Top Teams widget

Extract getDateRange() so the records_count column can use a custom
sortable query with orderByRaw, fixing sorting on the computed subquery.
Copilot AI review requested due to automatic review settings February 16, 2026 19:23
@ManukMinasyan ManukMinasyan merged commit a9b3e9f into main Feb 16, 2026
13 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where sorting on the computed records_count column in the Top Teams widget failed silently. The fix extracts the date range logic into a reusable getDateRange() method and implements a custom sortable closure that uses the same SQL subquery expression used to compute the column value.

Changes:

  • Extracted getDateRange() method to enable reuse of date range logic
  • Added custom sortable closure to the records_count column using orderByRaw with parameterized bindings
  • Ensures sorting on computed column works correctly by mirroring the calculation logic used in the query

Comment on lines +59 to +66
->sortable(query: function (Builder $query, string $direction): Builder {
[$sql, $bindings] = $this->buildRecordsCountExpression(
CreationSource::SYSTEM->value,
...array_values($this->getDateRange()),
);

return $query->orderByRaw("({$sql}) {$direction}", $bindings);
})
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The sorting functionality on the records_count column lacks test coverage. Based on the testing patterns established for other Filament resources in this codebase (e.g., CompanyResourceTest, NoteResourceTest), you should add a test that verifies sorting works correctly in both ascending and descending directions. Consider creating a test file for this widget that tests the sortable column behavior, similar to how other resources test their sortable columns using livewire()->sortTable() and assertCanSeeTableRecords().

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants