-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(patients): add no patients exist #2235
feat(patients): add no patients exist #2235
Conversation
add missing useEffect dependency in ViewPatients.tsx
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/hospitalrun/hospitalrun-frontend/rdymsc2nf |
so for some reason i added a patient to the vercel build to check if the "add new patient" shows up when patients exist (even tho the tests passed) and i couldn't find a way to remove the patient, which means my commit won't be displayed (because there's a patient) so whomever reviews the code in vercel have to remove that test patient. |
src/patients/list/ViewPatients.tsx
Outdated
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<div style={{ display: 'flex', flexDirection: 'column' }}> | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<Icon icon="patient" outline={false} size="6x" /> |
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.
lets use the patients
icon rather than patient
.
src/patients/list/ViewPatients.tsx
Outdated
outlined | ||
color="success" |
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.
rather than using a success and outlined button, I think a primary
button makes more sense here since it is the call to action on the page.
</Button>, | ||
]) | ||
|
||
if (patients && patients.length > 0) { |
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 patients
variable represents the current patients in state.
This could be the default page of patients or a search result. When searching for patients and my search results return 0, I would not expect the new icon to appear.
I think that we should implement a new function called count
in Repository
that returns the number of documents that are available for a type.
Then here, we use that count
function to determine if the new icon should display or not.
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 get it, what i don't get is why do we need to implement count
?
it seems like PatientRepository.findAll()
returns all the existing patients in the db, we can use it as:
- implement a state called
count
- at initial load, setCount(PatientRepository.findAll().length)
- if (count == 0) show
addNewPations
component, else show the table
but it seems that implementing a count
in Repository
seems like a better solution here, since it makes Repository
more flexible for future issues/enhancements
src/patients/list/ViewPatients.tsx
Outdated
return ( | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<div style={{ display: 'flex', flexDirection: 'column' }}> | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<Icon icon="patient" outline={false} size="6x" /> | ||
</div> | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<div style={{ textAlign: 'center', width: '60%', margin: 16 }}> | ||
<Typography variant="h5">{t('patients.noPatients')}</Typography> | ||
</div> | ||
</div> | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<Button | ||
key="newPatientButton" | ||
outlined | ||
color="success" | ||
icon="patient-add" | ||
onClick={() => history.push('/patients/new')} | ||
> | ||
{t('patients.newPatient')} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> |
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 think that we should move this to its own component to:
- keep components smaller and easier to understand
- make it easier to test
@Fibii please let me know if you have any questions or need help addressing the code review feedback. |
@jackcmeyer how would i add i already added async count(): Promise<number> {
const result = await this.findAll()
return result.length
} what i want to do now is use it in const { patients, isLoading, count } = useSelector((state: RootState) => state.patients) but i couldn't figure it out. I updated the interface in interface PatientsState {
isLoading: boolean
patients: Patient[]
count: number
} and called export const fetchPatients = (sortRequest: SortRequest = Unsorted): AppThunk => async (
dispatch,
) => {
dispatch(fetchPatientsStart())
const patients = await PatientRepository.findAll(sortRequest)
const count = await PatientRepository.count()
// dispatch(fetchPatientsSuccess(... ? ))
} but i couldn't figure what to dispatch there. I need a little bit of help here. |
@fox1t some advice? |
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.
Few more code related comments.
One other thing:
The AddNewPatient
component should not display because a search result has no results.
It should show up when there are no patients in the database.
it('should render no patients exists when no patients exist', () => { | ||
const wrapper = setup(false, [], 0) | ||
|
||
const addNewPatient = wrapper.find(AddNewPatient) | ||
expect(addNewPatient).toHaveLength(1) | ||
|
||
const icon = wrapper.find(Icon).first() | ||
const typography = wrapper.find(Typography) | ||
const button = wrapper.find(Button) | ||
const iconType = icon.prop('icon') | ||
const iconSize = icon.prop('size') | ||
const typographyText = typography.prop('children') | ||
const typographyVariant = typography.prop('variant') | ||
const buttonIcon = button.prop('icon') | ||
const buttonText = button.prop('children') | ||
|
||
expect(iconType).toEqual('patients') | ||
expect(iconSize).toEqual('6x') | ||
expect(typographyText).toEqual('patients.noPatients') | ||
expect(typographyVariant).toEqual('h5') | ||
expect(buttonIcon).toEqual('patient-add') | ||
expect(buttonText).toEqual('patients.newPatient') | ||
}) |
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 test is testing behavior inside the AddNewPatient
component. I think instead, this test should test that the AddNewPatient
component gets rendered and then this current test should be moved to an AddNewPatient
test.
src/patients/view/AddNewPatient.tsx
Outdated
|
||
import useTranslator from '../../shared/hooks/useTranslator' | ||
|
||
const AddNewPatient = () => { |
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.
Thoughts on NoPatientsExist
for this component name? AddNewPatient
could potentially be confusing with NewPatient
component.
Fixes #2231
Changes proposed in this pull request:
/patient
as discussed in Implement "no patients" state on the /patients route #2231noPatients
for languages: eng/de/fr/ar/ru