Skip to content

Conversation

@jamesh38
Copy link
Contributor

@jamesh38 jamesh38 commented Dec 13, 2025

What github issue is this PR for, if any?

Resolves #6504

What changed, and why?

Added server-side search to the new case contacts table for better performance with large datasets.

Backend:

  • Created CaseContactDatatable to handle server-side DataTables processing with search across creator name, creator email, case number, notes, and contact types
  • Added datatable? permission in CaseContactPolicy for admins, supervisors, and volunteers
  • Used ActiveRecord + .to_sql pattern instead of raw SQL for maintainability

Frontend:

  • Updated dashboard.js to configure DataTables with server-side processing
  • Set up all 11 column renderers (icons, links, duration formatting, draft badges)

Why?
Loading all case contacts client-side would get slow with lots of data. Server-side processing lets the database handle filtering and pagination, only returning one page at a time.

How is this tested?

rspec (46 tests):

  • spec/datatables/case_contact_datatable_spec.rb - 35 tests for data structure, search, ordering, pagination, sanitization
  • spec/policies/case_contact_policy_spec.rb - 3 tests for permissions
  • spec/requests/case_contacts/case_contacts_new_design_spec.rb - 8 tests for endpoint authorization and scoped data

jest (48 tests):

  • app/javascript/__tests__/dashboard.test.js - tests for DataTable config, AJAX setup, all column renderers
# run tests
bin/rspec spec/datatables/case_contact_datatable_spec.rb
npm test -- dashboard.test.js
image

@github-actions github-actions bot added javascript for use by Github Labeler to mark pull requests that update Javascript code ruby Pull requests that update Ruby code Tests! 🎉💖👏 erb labels Dec 13, 2025
compwron
compwron previously approved these changes Dec 15, 2025
Copy link
Contributor

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 implements server-side DataTables functionality for the new case contacts table to improve performance with large datasets. The implementation includes backend processing via a CaseContactDatatable class, policy updates to authorize access, and comprehensive frontend column renderers.

Key Changes:

  • Server-side DataTables processing with search across creator name, email, case number, notes, and contact types
  • Authorization via CaseContactPolicy#datatable? for admins, supervisors, and volunteers
  • 11 column renderers handling icons, links, duration formatting, and draft badges

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
app/datatables/case_contact_datatable.rb New datatable class implementing server-side search, ordering, and pagination with ActiveRecord queries
app/policies/case_contact_policy.rb Added datatable? permission aliased to existing authorization method
app/controllers/case_contacts/case_contacts_new_design_controller.rb Added datatable action to return JSON response
config/routes.rb Added POST route for datatable endpoint
app/views/case_contacts/case_contacts_new_design/index.html.erb Updated data-source attribute to point to new datatable endpoint
app/javascript/src/dashboard.js Configured DataTables with server-side processing, AJAX setup, and 11 column renderers
app/javascript/tests/dashboard.test.js Comprehensive Jest tests for DataTable configuration and column renderers
spec/datatables/case_contact_datatable_spec.rb RSpec tests for data structure, search, ordering, pagination, and edge cases
spec/policies/case_contact_policy_spec.rb Tests for datatable permission authorization
spec/requests/case_contacts/case_contacts_new_design_spec.rb Integration tests for datatable endpoint authorization and scoped data

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
compwron and others added 6 commits December 15, 2025 09:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jamesh38
Copy link
Contributor Author

Thanks for triggering the review @compwron addressed final two issues and fixed tests

@jamesh38 jamesh38 requested a review from compwron December 16, 2025 05:28
@compwron compwron merged commit dc6ac28 into rubyforgood:main Dec 16, 2025
13 checks passed
@compwron
Copy link
Collaborator

:)

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

Labels

erb javascript for use by Github Labeler to mark pull requests that update Javascript code ruby Pull requests that update Ruby code Tests! 🎉💖👏

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Case Contact Table: implement "search" button/functionality

2 participants