Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Related Persons modal should provide better error feedback #1925

Closed
jackcmeyer opened this issue Mar 19, 2020 · 8 comments 路 Fixed by #1991
Closed

Related Persons modal should provide better error feedback #1925

jackcmeyer opened this issue Mar 19, 2020 · 8 comments 路 Fixed by #1991
Assignees
Labels
馃殌enhancement an issue/pull request that adds a feature to the application good first issue indicates an issue is good for a first time contributor in progress indicates that issue/pull request is currently being worked on patients issue/pull request that interacts with patients module
Projects
Milestone

Comments

@jackcmeyer
Copy link
Member

馃殌 Feature Proposal

I would like the add related persons modal to provide better feedback for error messages.

Currently, the only error message is a banner error message.

After the completion of this issue, I would like it to provide feedback at the field level when possible.

The following should happen:

  • When a Related Persons is not filled in, the related person should highlight in red, and provide feedback saying Related Person is required.
  • When a Relationship Type is not filled in, the relationship type field should highlight in red, and provide feedback saying Relationship Type is required.
  • The banner message should read Unable to add new related person.

Motivation

Better user experience.

@jackcmeyer jackcmeyer transferred this issue from HospitalRun/hospitalrun Mar 19, 2020
@jackcmeyer jackcmeyer added 馃殌enhancement an issue/pull request that adds a feature to the application good first issue indicates an issue is good for a first time contributor help wanted indicates that an issue is open for contributions patients issue/pull request that interacts with patients module labels Mar 19, 2020
@jackcmeyer jackcmeyer added this to To do in Version 2.0 via automation Mar 19, 2020
@jackcmeyer jackcmeyer added this to the v2.0 milestone Mar 19, 2020
@bmoore235
Copy link
Contributor

I would love to tackle this issue, along with New Related Persons Modal should mark required fields #1927

@jackcmeyer
Copy link
Member Author

@bmoore235 sounds good! I've assigned this to you.

@jackcmeyer jackcmeyer added in progress indicates that issue/pull request is currently being worked on and removed help wanted indicates that an issue is open for contributions labels Mar 19, 2020
@bmoore235
Copy link
Contributor

Sorry this has taken so long. These first couple weeks of isolation made me less productive than I anticipated. I'll have the pull request on this in today.

@jamesinsf-git
Copy link
Contributor

jamesinsf-git commented Mar 30, 2020

@bmoore235 I started looking at this recently and got stuck on this issue with Typeahead:
ericgio/react-bootstrap-typeahead#432

Basically, the Feedback component does not play nicely with Typeahead. Not sure if you've figured out a workaround.

update: nevermind, I see you're not using feedback for the Typeahead input. gotcha.

bmoore235 added a commit to bmoore235/hospitalrun-frontend that referenced this issue Mar 31, 2020
@bmoore235
Copy link
Contributor

Ya typeahead doesn't support feedback unfortunately.

I have the feature set, but I'm having some issues with testing. I have the following code, but neither test condition triggers the patient.relatedPersons.error.relatedPersonRequired text.

it('should provide feedback when no relationship given', () => {
      act(() => {
        const patientTypeahead = wrapper.find(Typeahead)
        patientTypeahead.prop('onChange')([{ id: '123' }])
      })
      wrapper.update()

      act(() => {
        ;(wrapper.find(Modal).prop('successButton') as any).onClick(
          {} as React.MouseEvent<HTMLButtonElement, MouseEvent>,
        )
      })
      ....
      ....
      ....
    })

    it('should provide feedback when no related person given', () => {
      act(() => {
        const relationshipTypeTextInput = wrapper.findWhere((w) => w.prop('name') === 'type')
        relationshipTypeTextInput.prop('onChange')({ target: { value: 'relationship' } })
      })
      wrapper.update()

      act(() => {
        ;(wrapper.find(Modal).prop('successButton') as any).onClick(
          {} as React.MouseEvent<HTMLButtonElement, MouseEvent>,
        )
      })
   ....
   ....
   ....
    })

@jamesinsf-git
Copy link
Contributor

Is it only a test issue? Does it work when you test this manually?

@jackcmeyer
Copy link
Member Author

jackcmeyer commented Mar 31, 2020

@bmoore235 I think this issue is that the onChange function for the Typeahead component is async.

So you'll need to make the tests async, the act async, and then await the onChange.

Something like

it('should provide feedback when no relationship given', async () => {
      await act(async () => {
        const patientTypeahead = wrapper.find(Typeahead)
        await patientTypeahead.prop('onChange')([{ id: '123' }])
      })
      wrapper.update()

      act(() => {
        ;(wrapper.find(Modal).prop('successButton') as any).onClick(
          {} as React.MouseEvent<HTMLButtonElement, MouseEvent>,
        )
      })
      ....
      ....
      ....
    })

    it('should provide feedback when no related person given', async () => {
      await act((async ) => {
        const relationshipTypeTextInput = wrapper.findWhere((w) => w.prop('name') === 'type')
        await relationshipTypeTextInput.prop('onChange')({ target: { value: 'relationship' } })
      })
      wrapper.update()

      act(() => {
        ;(wrapper.find(Modal).prop('successButton') as any).onClick(
          {} as React.MouseEvent<HTMLButtonElement, MouseEvent>,
        )
      })
   ....
   ....
   ....
    })

@jackcmeyer
Copy link
Member Author

@bmoore235 feel free to open a pull request with the code you have (preferably compiling code, however tests don't have to pass) and we can provide help since we will be able to see all of the changes!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
馃殌enhancement an issue/pull request that adds a feature to the application good first issue indicates an issue is good for a first time contributor in progress indicates that issue/pull request is currently being worked on patients issue/pull request that interacts with patients module
Projects
Version 2.0
  
Done
3 participants