casa icon indicating copy to clipboard operation
casa copied to clipboard

Added search to new case contact datatable view

Open jamesh38 opened this issue 4 weeks ago • 1 comments

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

jamesh38 avatar Dec 13 '25 20:12 jamesh38

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

jamesh38 avatar Dec 16 '25 05:12 jamesh38

:)

compwron avatar Dec 16 '25 15:12 compwron