Skip to content

Issue 6187 admin new case contacts#6215

Merged
compwron merged 12 commits intorubyforgood:mainfrom
alex-yi37:issue-6187-admin-new-case-contacts
Mar 21, 2025
Merged

Issue 6187 admin new case contacts#6215
compwron merged 12 commits intorubyforgood:mainfrom
alex-yi37:issue-6187-admin-new-case-contacts

Conversation

@alex-yi37
Copy link
Contributor

@alex-yi37 alex-yi37 commented Feb 6, 2025

What github issue is this PR for, if any?

Resolves #6187

What changed, and why?

This PR updates the case create/edit (/casa_cases/new and /casa_cases/:case_id/edit) pages by adding an option to select and unselect all contact type options and defaults to selecting all options when creating a case. Most of the changes revolve around a view component (app/components/form/multiple_select_component.html.erb) and its associated template and stimulus controller.

I assumed that a case needs to be created with associated contact types to be valid, so if an existing case were to have no contact types (some records in my local set up are like this), we would select all contact types when editing the case.

Also noted that existing functionality seems to be working when logged in as a volunteer and trying to add a new case contact (/case_contacts/:case_contact_id/form/details - seems case contact gets created when page is viewed?). If one case is assigned, defaults to that option in the form, if multiple cases are assigned, defaults to no cases being selected.

How is this tested? (please write tests!) 💖💪

Note: if you see a flake in your test build in github actions, please post in slack #casa "Flaky test: " :) 💪
Note: We love capybara tests! If you are writing both haml/js and ruby, please try to test your work with tests at every level including system tests like https://github.com/rubyforgood/casa/tree/main/spec/system

Added test cases in spec/system/casa_cases/new_spec.rb and spec/system/casa_cases/edit_spec.rb to check that selecting/unselecting all options works, all options are selected by default when creating a case, and existing contact types are selected when editing a case. Originally I wanted to test this functionality in a jest test for the stimulus controller end but was running into errors setting it up. Not sure if system specs are the best place to test this.

Screenshots please :)

Run your local server and take a screenshot of your work! Try to include the URL of the page as well as the contents of the page.

Admin page for creating a new case, all contact type options selected by default

image

Admin page for editing an existing case, existing contact types are selected by default

image

Selecting and unselecting all options

Screen.Recording.2025-02-17.at.6.26.34.PM.mov

Feelings gif (optional)

What gif best describes your feeling working on this issue? https://giphy.com/
How to embed:

![alt text](https://media.giphy.com/media/1nP7ThJFes5pgXKUNf/giphy.gif)

the multiselect rendered in the casa_cases/form partial gets used in both casa_cases/new view and casa_cases/edit view
@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 erb labels Feb 6, 2025
let orderedOptionVals = this.optionsValue.map(opt => opt.value)
if (showAllOptionCheck) {
// using " " as value instead of "" bc tom-select doesn't init the "" in the item list
orderedOptionVals = [' '].concat(orderedOptionVals)
Copy link
Contributor Author

@alex-yi37 alex-yi37 Feb 18, 2025

Choose a reason for hiding this comment

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

Using ' ' (space character) here seems to be treated the same as '' (empty string) when form data gets parsed in the back end. Not sure how empty string values are getting stripped when associating contact type ids with a case, but seems to work as expected since I can create casa cases locally.

@alex-yi37 alex-yi37 marked this pull request as ready for review February 18, 2025 18:23
Copy link
Collaborator

@compwron compwron left a comment

Choose a reason for hiding this comment

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

Looks plausible. Let's do it.

@compwron compwron merged commit de5e668 into rubyforgood:main Mar 21, 2025
18 of 19 checks passed
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.

default to all contact types for new cases

2 participants

Comments