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

feat(menu): added icons to items in the hamburger menu #2213

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/__tests__/shared/components/navbar/Navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ describe('Navbar', () => {
const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)
const hamberger = hospitalRunNavbar.find('.nav-hamberger')
const { children } = hamberger.first().props() as any

expect(children[0].props.children).toEqual([undefined, 'dashboard.label'])
expect(children[1].props.children).toEqual([undefined, 'patients.newPatient'])
expect(children[children.length - 1].props.children).toEqual([undefined, 'settings.label'])
const [dashboardIcon, dashboardLabel] = children[0].props.children
const [newPatientIcon, newPatientLabel] = children[1].props.children
const [settingsIcon, settingsLabel] = children[children.length - 1].props.children

expect(dashboardIcon.props.icon).toEqual('dashboard')
expect(dashboardLabel).toEqual('dashboard.label')
expect(newPatientIcon.props.icon).toEqual('patient-add')
expect(newPatientLabel).toEqual('patients.newPatient')
expect(settingsIcon.props.icon).toEqual('setting')
expect(settingsLabel).toEqual('settings.label')
})

it('should not show an item if user does not have a permission', () => {
Expand Down Expand Up @@ -141,8 +147,10 @@ describe('Navbar', () => {
const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)
const addNew = hospitalRunNavbar.find('.nav-add-new')
const { children } = addNew.first().props() as any
const [icon, label] = children[0].props.children

expect(children[0].props.children).toEqual([undefined, 'patients.newPatient'])
expect(label).toEqual('patients.newPatient')
expect(icon.props.icon).toEqual('patient-add')
})

it('should not show a shortcut if user does not have a permission', () => {
Expand Down
1 change: 1 addition & 0 deletions src/shared/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Navbar = () => {
.map((page) => ({
type: 'link',
label: t(page.label),
icon: page.icon,
onClick: () => {
navigateTo(page.path)
},
Expand Down
12 changes: 11 additions & 1 deletion src/shared/components/navbar/pageMap.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Permissions from '../../model/Permissions'

type Page = { permission: Permissions | null; label: string; path: string }
type Page = { permission: Permissions | null; label: string; path: string; icon?: string }

const pageMap: {
[key: string]: Page
Expand All @@ -9,51 +9,61 @@ const pageMap: {
permission: null,
label: 'dashboard.label',
path: '/',
icon: 'dashboard',
},
newPatient: {
permission: Permissions.WritePatients,
label: 'patients.newPatient',
path: '/patients/new',
icon: 'patient-add',
},
viewPatients: {
permission: Permissions.ReadPatients,
label: 'patients.patientsList',
path: '/patients',
icon: 'incident',
},
newAppointment: {
permission: Permissions.WriteAppointments,
label: 'scheduling.appointments.new',
path: '/appointments/new',
icon: 'appointment-add',
},
viewAppointments: {
permission: Permissions.ReadAppointments,
label: 'scheduling.appointments.schedule',
path: '/appointments',
icon: 'incident',
},
newLab: {
permission: Permissions.RequestLab,
label: 'labs.requests.new',
path: '/labs/new',
icon: 'add',
},
viewLabs: {
permission: Permissions.ViewLabs,
label: 'labs.requests.label',
path: '/labs',
icon: 'incident',
},
newIncident: {
permission: Permissions.ReportIncident,
label: 'incidents.reports.new',
path: '/incidents/new',
icon: 'add',
},
viewIncidents: {
permission: Permissions.ViewIncidents,
label: 'incidents.reports.label',
path: '/incidents',
icon: 'incident',
},
settings: {
permission: null,
Copy link
Member

Choose a reason for hiding this comment

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

we have a settings icon that we can use here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of incident for viewIncidents(the marked line) or for the settings field? I assume the settings field?

Do you know the name of the icon?

Copy link
Member

Choose a reason for hiding this comment

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

For the settings field, sorry the marked line got a little weird.

The name of the icon is called setting.

For future reference, here are a list of our icon set: https://components.hospitalrun.io/?path=/story/icons--icon-set

label: 'settings.label',
path: '/settings',
icon: 'setting',
},
}

Expand Down