Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/javascript/__tests__/dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ describe('defineCaseContactsTable', () => {
expect(config.searching).toBe(true)
})

it('configures scrollX for horizontal scrolling', () => {
it('disables autoWidth so columns do not expand to oversized fixed widths', () => {
defineCaseContactsTable()

const config = mockDataTable.mock.calls[0][0]

expect(config.scrollX).toBe(true)
expect(config.autoWidth).toBe(false)
expect(config.scrollX).toBeUndefined()
})

it('sets default sort to Date column descending', () => {
Expand Down Expand Up @@ -674,7 +675,7 @@ describe('defineCaseContactsTable', () => {
const config = mockDataTable.mock.calls[0][0]

// Verify all critical config options are present
expect(config).toHaveProperty('scrollX')
expect(config).toHaveProperty('autoWidth')
expect(config).toHaveProperty('searching')
expect(config).toHaveProperty('processing')
expect(config).toHaveProperty('serverSide')
Expand Down
59 changes: 58 additions & 1 deletion app/javascript/src/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,37 @@ function buildExpandedContent (data) {

const defineCaseContactsTable = function () {
const table = $('table#case_contacts').DataTable({
scrollX: true,
autoWidth: false,
stateSave: true,
stateSaveCallback: function (settings, data) {
$.ajax({
url: '/preference_sets/table_state_update/' + settings.nTable.id + '_table',
data: { table_state: JSON.stringify(data) },
dataType: 'json',
type: 'POST',
error: function (jqXHR, textStatus, errorMessage) {
console.error(errorMessage)
}
})
},
stateSaveParams: function (settings, data) {
data.search.search = ''
return data
},
stateLoadCallback: function (settings, callback) {
$.ajax({
url: '/preference_sets/table_state/' + settings.nTable.id + '_table',
dataType: 'json',
type: 'GET',
success: function (json) { callback(json) }
})
},
initComplete: function () {
$('.cc-column-toggle').each(function () {
$(this).prop('checked', table.column($(this).data('column-index')).visible())
})
updateColumnsButtonBadge()
},
searching: true,
processing: true,
serverSide: true,
Expand Down Expand Up @@ -256,6 +286,33 @@ const defineCaseContactsTable = function () {
})
})

function updateColumnsButtonBadge () {
const total = $('.cc-column-toggle').length
const visible = $('.cc-column-toggle:checked').length
$('#cc-columns-count').text(`(${visible}/${total})`).css('visibility', 'visible')
}

$('#cc-columns-toggle').on('click', function () {
$('#cc-columns-panel').toggle()
})

$('#cc-columns-update').on('click', function () {
$('.cc-column-toggle').each(function () {
table.column($(this).data('column-index')).visible($(this).is(':checked'))
})
updateColumnsButtonBadge()
$('#cc-columns-panel').hide()
})

$('#cc-columns-show-all').on('click', function () {
$('.cc-column-toggle').prop('checked', true)
$('.cc-column-toggle').each(function () {
table.column($(this).data('column-index')).visible(true)
})
updateColumnsButtonBadge()
$('#cc-columns-panel').hide()
})

$('#cc-filter-toggle').on('click', function () {
$('#cc-filter-panel').toggle()
})
Expand Down
9 changes: 9 additions & 0 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ def active_or_notes?
LETTER = "letter".freeze
CONTACT_MEDIUMS = [IN_PERSON, TEXT_EMAIL, VIDEO, VOICE_ONLY, LETTER].freeze

TOGGLEABLE_COLUMNS = [
{key: "relationship", label: "Relationship", index: 4},
{key: "medium", label: "Medium", index: 5},
{key: "created_by", label: "Created By", index: 6},
{key: "contacted", label: "Contacted", index: 7},
{key: "topics", label: "Topics", index: 8},
{key: "draft", label: "Draft", index: 9}
].freeze

def update_cleaning_contact_types(args)
transaction do
contact_types.clear
Expand Down
43 changes: 38 additions & 5 deletions app/views/case_contacts/case_contacts_new_design/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
<h1 class="mb-20">Case Contacts</h1>

<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3" id="cc-filter-toolbar">
<button type="button" id="cc-filter-toggle" class="main-btn secondary-btn btn-sm btn-hover">
<i class="lni lni-funnel mr-5" aria-hidden="true"></i>
Filter
</button>
<div class="d-flex gap-2">
<button type="button" id="cc-filter-toggle" class="main-btn secondary-btn btn-sm btn-hover">
<i class="lni lni-funnel mr-5" aria-hidden="true"></i>
Filter
</button>

<button type="button" id="cc-columns-toggle" class="main-btn secondary-btn btn-sm btn-hover">
<i class="lni lni-list mr-5" aria-hidden="true"></i>
Columns <span id="cc-columns-count" style="visibility: hidden">(<%= CaseContact::TOGGLEABLE_COLUMNS.length %>/<%= CaseContact::TOGGLEABLE_COLUMNS.length %>)</span>
</button>
</div>

<%= link_to new_case_contact_path, class: "main-btn primary-btn btn-sm btn-hover" do %>
<i class="lni lni-plus mr-10" aria-hidden="true"></i>
Expand Down Expand Up @@ -100,10 +107,36 @@
</div>
</div>
</div>

<div id="cc-columns-panel" class="card-style mb-3" style="display: none;">
<div class="card-content">
<div class="row mb-3">
<% CaseContact::TOGGLEABLE_COLUMNS.each do |col| %>
<div class="col-md-4">
<div class="form-check form-switch">
<input type="checkbox"
class="form-check-input cc-column-toggle"
id="cc-col-<%= col[:key] %>"
data-column-index="<%= col[:index] %>"
role="switch"
checked>
<label class="form-check-label" for="cc-col-<%= col[:key] %>">
<%= col[:label] %>
</label>
</div>
</div>
<% end %>
</div>
<div class="d-flex gap-2">
<button type="button" id="cc-columns-update" class="main-btn primary-btn btn-sm btn-hover">Update View</button>
<button type="button" id="cc-columns-show-all" class="main-btn dark-btn-outline btn-sm btn-hover">Show All</button>
</div>
</div>
</div>
</div>

<div class="card-style mb-30">
<div class="table-wrapper">
<div class="table-wrapper" style="overflow-x: auto">
<table
id="case_contacts"
class="table"
Expand Down
90 changes: 90 additions & 0 deletions spec/system/case_contacts/case_contacts_new_design_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,96 @@
end
end

describe "columns panel" do
include_context "signed in as admin"

it "shows a Columns button in the toolbar" do
expect(page).to have_button("Columns")
end

it "shows a visible count badge on the Columns button" do
expect(page).to have_button(text: /Columns\s*\(6\/6\)/)
end

it "hides the columns panel by default" do
expect(page).not_to have_css("#cc-columns-panel", visible: true)
end

it "opens the columns panel when the Columns button is clicked" do
click_button "Columns"
expect(page).to have_css("#cc-columns-panel", visible: true)
end

it "closes the columns panel when the Columns button is clicked again" do
click_button "Columns"
click_button "Columns"
expect(page).not_to have_css("#cc-columns-panel", visible: true)
end

it "hides a column when its toggle is switched off and Update View is clicked" do
click_button "Columns"
uncheck "Medium"
click_button "Update View"

expect(page).not_to have_css("th", text: "Medium")
end

it "shows a column again when its toggle is switched back on and Update View is clicked" do
click_button "Columns"
uncheck "Medium"
click_button "Update View"

click_button "Columns"
check "Medium"
click_button "Update View"

expect(page).to have_css("th", text: "Medium")
end

it "updates the badge count when a column is hidden" do
click_button "Columns"
uncheck "Medium"
click_button "Update View"

expect(page).to have_button(text: /Columns\s*\(5\/6\)/)
end

it "shows all columns and closes the panel when Show All is clicked" do
click_button "Columns"
uncheck "Medium"
uncheck "Topics"
click_button "Update View"

click_button "Columns"
click_button "Show All"

expect(page).to have_css("th", text: "Medium")
expect(page).to have_css("th", text: "Topics")
expect(page).to have_button(text: /Columns\s*\(6\/6\)/)
expect(page).not_to have_css("#cc-columns-panel", visible: true)
end

it "persists hidden columns across page reloads" do
click_button "Columns"
uncheck "Medium"
click_button "Update View"

visit case_contacts_new_design_path

expect(page).not_to have_css("th", text: "Medium")
expect(page).to have_button(text: /Columns\s*\(5\/6\)/)
end

it "lists all 6 toggleable columns with toggle switches, all on by default" do
%w[Relationship Medium Contacted Topics Draft].each do |label|
expect(page).to have_css("#cc-columns-panel .form-switch", text: label, visible: :all)
expect(page).to have_field(label, checked: true, visible: :all)
end
expect(page).to have_css("#cc-columns-panel .form-switch", text: "Created By", visible: :all)
expect(page).to have_field("Created By", checked: true, visible: :all)
end
end

describe "filter panel" do
let!(:in_person_contact) do
create(:case_contact, :active, casa_case: casa_case,
Expand Down
Loading