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

(feat) O3-4026 Add an icon for vitals and biometrics on the left nav #2079

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ import classNames from 'classnames';
import last from 'lodash-es/last';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { ConfigurableLink } from '@openmrs/esm-framework';
import {
ConfigurableLink,
ActivityIcon,
ShoppingCartIcon,
MedicationIcon,
ChartAverageIcon,
CalendarHeatMapIcon,
WarningIcon,
ListCheckedIcon,
DocumentAttachmentIcon,
TableIcon,
EventScheduleIcon,
} from '@openmrs/esm-framework';
import { Report } from '@carbon/react/icons';
import styles from './dashboard-extension.scss';

export interface DashboardExtensionProps {
path: string;
Expand All @@ -22,13 +36,47 @@ export const DashboardExtension = ({
const location = useLocation();
const navLink = useMemo(() => decodeURIComponent(last(location.pathname.split('/'))), [location.pathname]);

const menuIcon = (title: string) => {
switch (title) {
case 'Patient Summary':
return <Report className={styles.icon} />;
case 'Vitals & Biometrics':
return <ActivityIcon className={styles.icon} />;
case 'Orders':
return <ShoppingCartIcon className={styles.icon} />;
case 'Medications':
return <MedicationIcon className={styles.icon} />;
case 'Results':
return <ChartAverageIcon className={styles.icon} />;
case 'Visits':
return <CalendarHeatMapIcon className={styles.icon} />;
case 'Allergies':
return <WarningIcon className={styles.icon} />;
case 'Conditions':
return <ListCheckedIcon className={styles.icon} />;
case 'Attachments':
return <DocumentAttachmentIcon className={styles.icon} />;
case 'Programs':
return <TableIcon className={styles.icon} />;
case 'Appointments':
return <EventScheduleIcon className={styles.icon} />;
default:
return null;
}
};

const renderIcon = menuIcon(title);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe an object lookup like the following is more preferable. It has less code and better type inference, and it should be straightforward to pop in more icons:

Suggested change
const menuIcon = (title: string) => {
switch (title) {
case 'Patient Summary':
return <Report className={styles.icon} />;
case 'Vitals & Biometrics':
return <ActivityIcon className={styles.icon} />;
case 'Orders':
return <ShoppingCartIcon className={styles.icon} />;
case 'Medications':
return <MedicationIcon className={styles.icon} />;
case 'Results':
return <ChartAverageIcon className={styles.icon} />;
case 'Visits':
return <CalendarHeatMapIcon className={styles.icon} />;
case 'Allergies':
return <WarningIcon className={styles.icon} />;
case 'Conditions':
return <ListCheckedIcon className={styles.icon} />;
case 'Attachments':
return <DocumentAttachmentIcon className={styles.icon} />;
case 'Programs':
return <TableIcon className={styles.icon} />;
case 'Appointments':
return <EventScheduleIcon className={styles.icon} />;
default:
return null;
}
};
const renderIcon = menuIcon(title);
type MenuTitle = keyof typeof MenuIcons;
const MenuIcons = {
Allergies: WarningIcon,
Appointments: EventScheduleIcon,
Attachments: DocumentAttachmentIcon,
Conditions: ListCheckedIcon,
Medications: MedicationIcon,
Orders: ShoppingCartIcon,
'Patient Summary': Report,
Programs: TableIcon,
Results: ChartAverageIcon,
Visits: CalendarHeatMapIcon,
'Vitals & Biometrics': ActivityIcon,
} as const;
const menuIcon = (title: MenuTitle) => {
const Icon = MenuIcons[title];
return Icon ? <Icon className={styles.icon} /> : null;
};
const renderIcon = menuIcon(title as MenuTitle);


return (
<div key={path}>
<ConfigurableLink
className={classNames('cds--side-nav__link', { 'active-left-nav-link': path === navLink })}
to={`${basePath}/${encodeURIComponent(path)}`}
>
{t(title)}
<span className={styles.menu}>
{renderIcon}
<span>{t(title)}</span>
</span>
</ConfigurableLink>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.menu {
display: flex;
align-items: center;
}

.icon {
margin-right: 0.5rem;
}
Empty file.