Skip to content
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

Set status directly instead of in form data #44874

Merged
merged 9 commits into from Feb 18, 2022
Merged

Conversation

megcrenshaw
Copy link
Contributor

@megcrenshaw megcrenshaw commented Feb 16, 2022

To save teacher applications, I was originally passing in the status via the form_data: if the user hits "submit application," {"status": "unreviewed"} would be added to the form data, and if the user hits "save application," {"status": "incomplete"} would be added to the form data.

This presented some challenges:

  1. When an RP sets the status, we want to ignore the form_data status. I did some work Remove status from form data after status gets set #44845 due to a bug from this.
  2. We now pass in the status to the form_data and then remove the status from the form_data as soon as the application is saved––it's a bit clunky.
  3. I had to do a bit of work in application_base to allow for the status to be set via the form_data––we can avoid this if we set status in a separate param.

Here, the status is set through a separate param in the frontend. Now we don't need to worry about removing form data. It seems cleaner to me, but I'm curious to hear y'all's thoughts!

See recording here: https://watch.screencastify.com/v/hA8VKZ573lGMF6I5oAou

Links

Testing story

Deployment strategy

Follow-up work

Need to add an eyes test for the application_dashboard. Will do this after (a) the "reopened" application status is set, and (b) RP's can't modify form data while an application is "incomplete" (maybe "reopened" too––not sure)

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@megcrenshaw megcrenshaw requested review from davidsbailey and a team February 16, 2022 20:15
@@ -180,6 +180,7 @@ describe('FormController', () => {
});

describe('Saving', () => {
// [MEG] TODO: Refactor this to use savedStatus instead of form_data
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm leaving this as a to-do because soon, we'll need to have a 'reopened' status if an RP reopens an application. We should check savedStatus for both of these cases.

@@ -36,6 +37,7 @@ def new
userId: current_user.id,
schoolId: current_user.school_info&.school&.id,
applicationId: @application_id,
savedStatus: @saved_status,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be needed once an RP can reopen an application

@@ -91,14 +91,6 @@ class Pd::FormTest < ActiveSupport::TestCase
refute form.valid?
end

test 'pd form does not check required fields if status is incomplete' do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the most awkward part of using this approach ... to test, we'd need to create an application with a status, rather than keep it as a form because a form doesn't have a status. Similar tests already exist in TeacherApplicationTest, so rather than duplicate here, I didn't include a test.

return if hash && hash[:status] == 'incomplete'
# No validation is required if an application is still in progress
# Check that status is defined because not all forms have status
return if defined?(status) && status == 'incomplete'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See form_test for more discussion of this

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

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

looks good, Meg! Thanks for adding the screencast.

form.form_data_hash = JSON.parse(form_data_json)

status = params.try(:[], :status)
if status
Copy link
Member

Choose a reason for hiding this comment

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

optional / for next time: I am not sure why the existing code is using params.try here, because params should always be defined in a controller method. params[:status] would be more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, good to know! I'll make a note of it and include in a future PR. Thanks.

@megcrenshaw megcrenshaw merged commit 4f5cc0a into staging Feb 18, 2022
@megcrenshaw megcrenshaw deleted the set-status-consitently branch February 18, 2022 18:47
@megcrenshaw megcrenshaw restored the set-status-consitently branch February 18, 2022 20:15
@fisher-alice fisher-alice deleted the set-status-consitently branch July 13, 2022 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants