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

Fix bug on hearing details page where email error messages weren't being displayed #15044

Merged
merged 22 commits into from
Aug 25, 2020

Conversation

ferristseng
Copy link
Contributor

@ferristseng ferristseng commented Aug 21, 2020

Resolves #14990

Description

  • Update server to throw if there are validation errors (update => update!)
  • Update server to handle setting the representative email to null
    • Updated server to not send down virtual hearing notification alerts if only the representative email was updated
  • Small fixes to remove PropType warnings
  • Add tests for email validations on the hearing details page

Acceptance Criteria

  • Ensure validations display when modifying any email address on the hearing details page for a virtual hearing

Testing Plan

  1. Login as a Hearing Coordinator
  2. Go to the hearing details page for a virtual hearing
  3. Try changing representative email to 123456
  4. Try deleting the representative email
  5. Try changing veteran email and deleting the representative email
  6. Try changing the representative timezone and then deleting the representative email (the timezone should revert)
  7. Try making both the veteran email and representative email invalid

User Facing Changes

Screen Shot 2020-08-25 at 10 44 44 AM

@va-bot
Copy link
Collaborator

va-bot commented Aug 21, 2020

2 Warnings
⚠️ This is a Big PR. Try to break this down if possible. Stacked pull requests encourage more detailed and thorough code reviews
⚠️ This PR modifies React components — consider adding/updating corresponding Storybook file

Generated by 🚫 Danger

@codeclimate
Copy link

codeclimate bot commented Aug 21, 2020

Code Climate has analyzed commit d98fe9a and detected 0 issues on this pull request.

View more on Code Climate.

@@ -148,7 +148,7 @@ export const HearingConversion = ({
<div className={classNames('usa-width-one-half', { [noMaxWidth]: true })} >
<Timezone
errorMessage={errors?.representativeTz}
required={virtualHearing?.representativeEmail}
required={Boolean(virtualHearing?.representativeEmail)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes a console PropType warning

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you so much for fixing this!

@@ -55,7 +56,7 @@ export const VirtualHearingFields = ({
<div className="usa-width-one-third">
<Timezone
errorMessage={errors?.representativeTz}
required={virtualHearing?.representativeEmail}
required={Boolean(virtualHearing?.representativeEmail)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes a console PropType warning

<p>
<strong>Representative Email</strong>
<strong>POA/Representative Email</strong>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes this label match the pop-up that shows for formerly central virtual hearings

@@ -15,7 +15,7 @@ def update_hearing
end

def hearing_updated?
super || advance_on_docket_motion_attributes&.present?
super || advance_on_docket_motion_attributes.present?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small fix so this returns false instead of nil if advance_on_docket_motion_attributes == nil

@ferristseng ferristseng changed the title [WIP] Fix bug on hearing details page where email error messages weren't being displayed Fix bug on hearing details page where email error messages weren't being displayed Aug 25, 2020
@ferristseng ferristseng requested review from a team and rubaiyat22 and removed request for a team and rubaiyat22 August 25, 2020 14:47
Copy link
Contributor

@sahalliburton sahalliburton left a comment

Choose a reason for hiding this comment

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

Logic looks great! Just mentioned a few things I think we should address, thanks!

hearing: { ...state.hearing, ...value },
formsUpdated: !isEmpty(deepDiff(state.initialHearing, { ...state.hearing, ...value }))
});
const setUpdated = (state, value) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring this way doesnt change the logic at all, I think we should leave this as is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO the refactor makes it a bit easier to understand what's going on. Previously, the expression which represents the merged new hearing, { ...state.hearing, ...value }, was repeated twice. I think the intention of the call to deepDiff is to determine if there are changes between the new hearing and the initial hearing, which I think the refactor captures a bit better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring this way also adds mutation to the function because instead of using the splat operator to assign the formsUpdated value, you are first creating an object and then assigning the value. I really think we should leave this as is because it follows functional programming guidelines of not-mutating

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 generally agree with not-mutating, but I don't see the downside here because we are mutating a local that's declared and instantiated inside the function. I could see it being a bigger problem if we were mutating the field of an argument that was being passed in.

One alternative way of doing this could be:

const setUpdated = (state, value) => {
  const newHearing = { ...state.hearing, ...value };
  return {
    ...state,
    hearing: newHearing,
    formsUpdated: !isEmpty(deepDiff(newState.initialHearing, newHearing))
  };
};

Copy link
Contributor

Choose a reason for hiding this comment

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

That refactor is better because it does not mutate. While I don't agree that this makes the code easier to read IMO it actually makes it more difficult, this does follow guidelines so I will concede

@@ -63,9 +63,15 @@ export const deepDiff = (firstObj, secondObj) => {
const secondVal = secondObj[key];

if (_.isEqual(firstVal, secondVal)) {
result[key] = null;
delete result[key];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we refactor this to be a pure function? I am concerned about using delete because it can lead to unintended side-effects that are hard to debug due to JavaScripts asynchronous data access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed the calls to delete! Please take a look again!

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM thanks!

Copy link
Contributor

@sahalliburton sahalliburton left a comment

Choose a reason for hiding this comment

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

LGTM

@ferristseng ferristseng added the Ready-to-Merge This PR is ready to be merged and will be picked up by va-bot to automatically merge to master label Aug 25, 2020
@va-bot va-bot merged commit 9afb417 into master Aug 25, 2020
@va-bot va-bot deleted the ftseng-hearing-details-email-validation branch August 25, 2020 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready-to-Merge This PR is ready to be merged and will be picked up by va-bot to automatically merge to master Team: Tango 💃
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dogfooding Bug] No email validation on the hearing details page when modifying a virtual hearing's email
3 participants