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

Commit

Permalink
fix: fixes warnings/errors appearing in console
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Apr 26, 2020
1 parent c2502ac commit 5cfbc32
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 121 deletions.
22 changes: 13 additions & 9 deletions src/__tests__/HospitalRun.test.tsx
Expand Up @@ -411,7 +411,7 @@ describe('HospitalRun', () => {
})

describe('/labs', () => {
it('should render the Labs component when /labs is accessed', () => {
it('should render the Labs component when /labs is accessed', async () => {
jest.spyOn(LabRepository, 'findAll').mockResolvedValue([])
const store = mockStore({
title: 'test',
Expand All @@ -420,18 +420,22 @@ describe('HospitalRun', () => {
components: { sidebarCollapsed: false },
})

const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/labs']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)
let wrapper: any
await act(async () => {
wrapper = await mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/labs']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)
})
wrapper.update()

expect(wrapper.find(ViewLabs)).toHaveLength(1)
})

it('should render the dasboard if the user does not have permissions to view labs', () => {
it('should render the dashboard if the user does not have permissions to view labs', () => {
jest.spyOn(LabRepository, 'findAll').mockResolvedValue([])
const store = mockStore({
title: 'test',
Expand Down
7 changes: 5 additions & 2 deletions src/__tests__/page-header/ButtonBarProvider.test.tsx
@@ -1,5 +1,5 @@
import '../../__mocks__/matchMediaMock'
import React from 'react'
import React, { useEffect } from 'react'
import { renderHook } from '@testing-library/react-hooks'
import {
ButtonBarProvider,
Expand All @@ -16,7 +16,10 @@ describe('Button Bar Provider', () => {
const { result } = renderHook(
() => {
const update = useButtonToolbarSetter()
update(expectedButtons)
useEffect(() => {
update(expectedButtons)
}, [update])

return useButtons()
},
{ wrapper },
Expand Down
8 changes: 4 additions & 4 deletions src/labs/ViewLab.tsx
Expand Up @@ -98,22 +98,22 @@ const ViewLab = () => {
}

buttons.push(
<Button className="mr-2" color="success" onClick={onUpdate}>
<Button className="mr-2" color="success" onClick={onUpdate} key="actions.update">
{t('actions.update')}
</Button>,
)

if (permissions.includes(Permissions.CompleteLab)) {
buttons.push(
<Button className="mr-2" onClick={onComplete} color="primary">
<Button className="mr-2" onClick={onComplete} color="primary" key="labs.requests.complete">
{t('labs.requests.complete')}
</Button>,
)
}

if (permissions.includes(Permissions.CancelLab)) {
buttons.push(
<Button onClick={onCancel} color="danger">
<Button onClick={onCancel} color="danger" key="labs.requests.cancel">
{t('labs.requests.cancel')}
</Button>,
)
Expand Down Expand Up @@ -199,7 +199,7 @@ const ViewLab = () => {
value={labToView.result}
isEditable={isEditable}
isInvalid={!!error.result}
feedback={t(error.result || '')}
feedback={t(error.result as string)}
onChange={onResultChange}
/>
<TextFieldWithLabelFormGroup
Expand Down
23 changes: 16 additions & 7 deletions src/labs/ViewLabs.tsx
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'
import React, { useState, useEffect, useCallback } from 'react'
import useTitle from 'page-header/useTitle'
import { useTranslation } from 'react-i18next'
import format from 'date-fns/format'
Expand All @@ -21,21 +21,25 @@ const ViewLabs = () => {
const { permissions } = useSelector((state: RootState) => state.user)
const [labs, setLabs] = useState<Lab[]>([])

const getButtons = () => {
const getButtons = useCallback(() => {
const buttons: React.ReactNode[] = []

if (permissions.includes(Permissions.RequestLab)) {
buttons.push(
<Button icon="add" onClick={() => history.push('/labs/new')} outlined color="success">
<Button
icon="add"
onClick={() => history.push('/labs/new')}
outlined
color="success"
key="lab.requests.new"
>
{t('labs.requests.new')}
</Button>,
)
}

return buttons
}

setButtons(getButtons())
}, [permissions, history, t])

useEffect(() => {
const fetch = async () => {
Expand All @@ -51,8 +55,13 @@ const ViewLabs = () => {
setLabs(fetchedLabs)
}

setButtons(getButtons())
fetch()
}, [])

return () => {
setButtons([])
}
}, [getButtons, setButtons])

const onTableRowClick = (lab: Lab) => {
history.push(`/labs/${lab.id}`)
Expand Down
2 changes: 1 addition & 1 deletion src/labs/requests/NewLabRequest.tsx
Expand Up @@ -95,7 +95,7 @@ const NewLabRequest = () => {
isRequired
isEditable
isInvalid={!!error.type}
feedback={t(error.type || '')}
feedback={t(error.type as string)}
value={newLabRequest.type}
onChange={onLabTypeChange}
/>
Expand Down
56 changes: 26 additions & 30 deletions src/patients/list/Patients.tsx
Expand Up @@ -22,17 +22,6 @@ const Patients = () => {
const { patients, isLoading } = useSelector((state: RootState) => state.patients)

const setButtonToolBar = useButtonToolbarSetter()
setButtonToolBar([
<Button
key="newPatientButton"
outlined
color="success"
icon="patient-add"
onClick={() => history.push('/patients/new')}
>
{t('patients.newPatient')}
</Button>,
])

const [searchText, setSearchText] = useState<string>('')

Expand All @@ -45,28 +34,25 @@ const Patients = () => {
useEffect(() => {
dispatch(fetchPatients())

setButtonToolBar([
<Button
key="newPatientButton"
outlined
color="success"
icon="patient-add"
onClick={() => history.push('/patients/new')}
>
{t('patients.newPatient')}
</Button>,
])

return () => {
setButtonToolBar([])
}
}, [dispatch, setButtonToolBar])
}, [dispatch, setButtonToolBar, t, history])

const loadingIndicator = <Spinner color="blue" loading size={[10, 25]} type="ScaleLoader" />

const listBody = (
<tbody>
{patients.map((p) => (
<tr key={p.id} onClick={() => history.push(`/patients/${p.id}`)}>
<td>{p.code}</td>
<td>{p.givenName}</td>
<td>{p.familyName}</td>
<td>{p.sex}</td>
<td>{p.dateOfBirth ? format(new Date(p.dateOfBirth), 'yyyy-MM-dd') : ''}</td>
</tr>
))}
</tbody>
)

const list = (
const table = (
<table className="table table-hover">
<thead className="thead-light ">
<tr>
Expand All @@ -77,7 +63,17 @@ const Patients = () => {
<th>{t('patient.dateOfBirth')}</th>
</tr>
</thead>
{isLoading ? loadingIndicator : listBody}
<tbody>
{patients.map((p) => (
<tr key={p.id} onClick={() => history.push(`/patients/${p.id}`)}>
<td>{p.code}</td>
<td>{p.givenName}</td>
<td>{p.familyName}</td>
<td>{p.sex}</td>
<td>{p.dateOfBirth ? format(new Date(p.dateOfBirth), 'yyyy-MM-dd') : ''}</td>
</tr>
))}
</tbody>
</table>
)

Expand All @@ -99,7 +95,7 @@ const Patients = () => {
</Column>
</Row>

<Row>{list}</Row>
<Row> {isLoading ? loadingIndicator : table}</Row>
</Container>
)
}
Expand Down
40 changes: 20 additions & 20 deletions src/patients/view/ViewPatient.tsx
Expand Up @@ -40,25 +40,6 @@ const ViewPatient = () => {

const setButtonToolBar = useButtonToolbarSetter()

const buttons = []
if (permissions.includes(Permissions.WritePatients)) {
buttons.push(
<Button
key="editPatientButton"
color="success"
icon="edit"
outlined
onClick={() => {
history.push(`/patients/edit/${patient.id}`)
}}
>
{t('actions.edit')}
</Button>,
)
}

setButtonToolBar(buttons)

const breadcrumbs = [
{ i18nKey: 'patients.label', location: '/patients' },
{ text: getPatientFullName(patient), location: `/patients/${patient.id}` },
Expand All @@ -71,10 +52,29 @@ const ViewPatient = () => {
dispatch(fetchPatient(id))
}

const buttons = []
if (permissions.includes(Permissions.WritePatients)) {
buttons.push(
<Button
key="editPatientButton"
color="success"
icon="edit"
outlined
onClick={() => {
history.push(`/patients/edit/${patient.id}`)
}}
>
{t('actions.edit')}
</Button>,
)
}

setButtonToolBar(buttons)

return () => {
setButtonToolBar([])
}
}, [dispatch, id, setButtonToolBar])
}, [dispatch, id, setButtonToolBar, history, patient.id, permissions, t])

if (isLoading || !patient) {
return <Spinner color="blue" loading size={[10, 25]} type="ScaleLoader" />
Expand Down
24 changes: 12 additions & 12 deletions src/scheduling/appointments/Appointments.tsx
Expand Up @@ -28,26 +28,26 @@ const Appointments = () => {
const { appointments } = useSelector((state: RootState) => state.appointments)
const [events, setEvents] = useState<Event[]>([])
const setButtonToolBar = useButtonToolbarSetter()
setButtonToolBar([
<Button
key="newAppointmentButton"
outlined
color="success"
icon="appointment-add"
onClick={() => history.push('/appointments/new')}
>
{t('scheduling.appointments.new')}
</Button>,
])
useAddBreadcrumbs(breadcrumbs, true)

useEffect(() => {
dispatch(fetchAppointments())
setButtonToolBar([
<Button
key="newAppointmentButton"
outlined
color="success"
icon="appointment-add"
onClick={() => history.push('/appointments/new')}
>
{t('scheduling.appointments.new')}
</Button>,
])

return () => {
setButtonToolBar([])
}
}, [dispatch, setButtonToolBar])
}, [dispatch, setButtonToolBar, history, t])

useEffect(() => {
const getAppointments = async () => {
Expand Down

0 comments on commit 5cfbc32

Please sign in to comment.