-
Notifications
You must be signed in to change notification settings - Fork 242
React autosave: patient dashboard form (bugs fixed 🙂 ) #3337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
React autosave: patient dashboard form (bugs fixed 🙂 ) #3337
Conversation
c649765 to
5db331b
Compare
|
I will get this into sandbox and tested shortly! Fixes #3240 |
colinxfleming
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is looking pretty good to me. I want to have @lomky take a look at it real quick but then I'm comfortable rolling with it. One minor regression noted in a comment but (as noted) I'm good to roll with this.
Sorry again for the review delay!
| describe 'updating name' do | ||
| before do | ||
| fill_in 'First and last name', with: 'Susie Everyteen 2' | ||
| click_away_from_field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly dope
| return debounce(autosave, 300) | ||
| }, []); | ||
| const debouncedAutosave = (params) => { | ||
| return debounce(autosave(params), 300) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works like a charm for me fysa
| weeksOptions: weeks_options.map { |opt| { label: opt[0], value: opt[1] } }, | ||
| daysOptions: days_options.map { |opt| { label: opt[0], value: opt[1] } }, | ||
| initialCallDate: patient.initial_call_date.strftime("%m/%d/%Y"), | ||
| statusHelpText: status_help_text(patient), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at some point we'll need to find a way to re-rack this from changes (easiest example on main: setting an appointment date makes the status Fundraising, removing appointment dates makes the status Needs Appointment. That said I'm perfectly fine letting this regress a bit and merging this, and tackling this later, because I'd like to start running this react code in prod again. (Please make an issue if we do that so we don't forget.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally following your comment but I think that's b/c I'm not as familiar with all the parts of the app as you are. Can you clarify by what you mean by "this"? The status help text? Or the status input itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the status help text -- the content changes based on the state of the patient (and I believe that's a model field right now). On prod now it refreshes after a change without a page reload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool cool, I went ahead and fixed that in this branch 🤗 hopefully no regressions now
|
|
||
| const autosave = async (updatedData) => { | ||
| const updatedPatientData = { ...patientData, ...updatedData } | ||
| setPatientData(updatedPatientData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the main culprit right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually the change below with the debounce was the main culprit. a combo of the useMemo and not passing the params through to the autosave function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good to know! makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really need to learn to just stop reaching for useMemo. I mess it up nearly every time and it has cost me hours of my life 😅
8387079 to
8120369
Compare
|
Looks like I'm running into test failures due to the debounced save and ajax stuff with Capybara. I'll continue looking into this this week. |
|
I'm seeing a small bug when I try to set "0 days" in the weeks along settings, it blanks it out. I suspect its something to do with the javascript -> ruby translation with "whats a false", but I haven't dug in more |
Great, I'll add that to my list when I'm resolving the specs issue |
|
😮💨 ok I think we're good! finally. sorry for the avalanche of notifications. I've addressed all feedback
have a great week! |
|
All the functionality is looking great! I think we have one last visual to fix where the Days Along field is shifting up, but otherwise it seems to be working great for me and i'm so excited to get it merged! in the old component, it had an invisible label pushing it down to be level with Weeks Along. |
cd785c7 to
9134b28
Compare
|
Visual regression fixed. I've rebased this branch on latest main but am getting a security vulnerability that needs to be fixed (the I'm going to let this be and hope that those issues are resolved in the base branch. Let me know if you need me to rebase or retrigger workflows this week. |
|
Popping in here to say re: build, there's currently SOMETHING up with github actions and capybara, this results in about 10 system test failures and we can ignore those for now. I also bumped the json gem on main, so if the regression is solved for I think we can smash merge even if build's not passing. |
| // if we don't have an onChange handler, this component is an uncontrolled component | ||
| // if we have an onChange handler, we'll manage state like a traditional controlled component | ||
| let value, setValue; | ||
| if (!onChange) { | ||
| value = initialValue | ||
| } else { | ||
| ([value, setValue] = useState(initialValue || "")) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note after talking with Kat: I'd consider always calling the useState hook instead of conditionally, even if you're not using the value. This violates the "Rule of Hooks"
🔴 Do not call Hooks inside conditions or loops.
It may be fine since there's only ever one hook. But it may not be. I haven't actually tested it
| // if we don't have an onChange handler, this component is an uncontrolled component | |
| // if we have an onChange handler, we'll manage state like a traditional controlled component | |
| let value, setValue; | |
| if (!onChange) { | |
| value = initialValue | |
| } else { | |
| ([value, setValue] = useState(initialValue || "")) | |
| } | |
| // if we don't have an onChange handler, this component is an uncontrolled component | |
| // if we have an onChange handler, we'll manage state like a traditional controlled component | |
| let [value] = useState(initialValue || "") | |
| if (!onChange) { | |
| value = initialValue | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point and something I went back and forth on a lot. I don't want to mutate the state variable directly either since that also breaks React conventions.
I've pushed up a more complex but more complete solution in today's commits.
|
Re: "Field Changes sometimes 'saved' but then lost", I currently have a 300 ms debounce on the input. I'm not able to reproduce what you've described. But I can sometimes force a page reload faster than the 300 ms if I'm realllllllyyyyy trying. Could that be something you're running into? Seeing the green banner from a previous save and reloading the page before the new change can be committed? Want me to decrease the 300 ms debounce on the autosave? Re: Days Along off-by-one |
9134b28 to
3d360f7
Compare
|
Re: "Field Changes" - I'm not trying especially hard, just typing and tabbing through fields! but that is pretty fast. Re: Days Along off-by-one - The value selected is 2, but the display (see the weeks along below) says 3. That's true of the other places the value showed, too. But when I checked the console, it was saved properly as 2. If I changed the value, the display also changed, but still off by one. it was a weird bug and I couldn't reproduce it on another record, but it persisted on that record. For overall context, I spent about 5-10 minutes just naviating around, typing, and changing things, and saw the off-by-one once and field change loss two or three times. So it wasn't even the most common occurence, but too often for my comfort, if that makes sense? |
3d360f7 to
5c3ea3b
Compare
|
I think bugs are fixed? I'm getting |



I rule and have completed some work on Case Manager that's ready for review!
This PR rewrites the patient dashboard form in React with safe autosave. This is mostly the same as #3216 but with the identified bugs fixed. Fixes #3240
Let me know if anything else pops up. I'm sorry for the long delay on this 🫣
For reviewer:
featureif it contains a feature, fix, or similar. This is anything that contains a user-facing fix in some way, such as frontend changes, alterations to backend behavior, or bug fixes.dependenciesif it contains library upgrades or similar. This is anything that upgrades any dependency, such as a Gemfile update or npm package upgrade.