-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OHRI-1350 Move custom side nav links to utilize openmrs homepage (#1751)
- Loading branch information
1 parent
8e878e2
commit a69daad
Showing
46 changed files
with
576 additions
and
435 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/esm-commons-lib/src/components/ohri-home/welcome-section/ohri-welcome-section.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.welcomeContainer { | ||
display: flex; | ||
flex-direction: column; | ||
margin: 1rem; | ||
} | ||
|
||
.location { | ||
|
1 change: 1 addition & 0 deletions
1
packages/esm-commons-lib/src/components/tile/ohri-programme-summary-tiles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.desktopView { | ||
display: flex; | ||
gap: 8px; | ||
margin: 1rem; | ||
} | ||
|
||
.tileView { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/esm-commons-lib/src/utils/createNewOHRIDashboardLink.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import classNames from 'classnames'; | ||
import { BrowserRouter, useLocation } from 'react-router-dom'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { ConfigurableLink, navigate } from '@openmrs/esm-framework'; | ||
import { SideNavLink, SideNavMenu, SideNavMenuItem, Button } from '@carbon/react'; | ||
import styles from './sidenav-links.scss'; | ||
|
||
interface DashboardLinkConfig { | ||
name: string; | ||
title: string; | ||
icon: React.ComponentType<any>; | ||
} | ||
|
||
function NewDashboardExtension({ dashboardLinkConfig }: { dashboardLinkConfig: DashboardLinkConfig }) { | ||
const { name, title, icon } = dashboardLinkConfig; | ||
const location = useLocation(); | ||
const spaBasePath = `${window.spaBase}/home`; | ||
|
||
const navLink = useMemo(() => { | ||
const pathArray = location.pathname.split('/home'); | ||
const lastElement = pathArray[pathArray.length - 1]; | ||
return decodeURIComponent(lastElement); | ||
}, [location.pathname]); | ||
|
||
return ( | ||
<SideNavLink | ||
renderIcon={icon} | ||
href={`${spaBasePath}/${name}`} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
navigate({ to: `${spaBasePath}/${name}` }); | ||
}} | ||
className={navLink.match(name) ? styles.currentNavItem : ''}> | ||
{title} | ||
</SideNavLink> | ||
); | ||
} | ||
|
||
export const createNewOHRIDashboardLink = (dashboardLinkConfig: DashboardLinkConfig) => () => ( | ||
<BrowserRouter> | ||
<NewDashboardExtension dashboardLinkConfig={dashboardLinkConfig} /> | ||
</BrowserRouter> | ||
); |
78 changes: 78 additions & 0 deletions
78
packages/esm-commons-lib/src/utils/createOHRIGroupedLink.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { useMemo } from 'react'; | ||
import classNames from 'classnames'; | ||
import { BrowserRouter, useLocation } from 'react-router-dom'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { ConfigurableLink } from '@openmrs/esm-framework'; | ||
import { SideNavMenu, SideNavItems } from '@carbon/react'; | ||
|
||
interface DashboardLinkConfig { | ||
name: string; | ||
title: string; | ||
isFolder: boolean; | ||
folderTitle: string; | ||
folderIcon: React.ComponentType<any>; | ||
childLinks?: Array<any>; | ||
isHidden?: boolean; | ||
} | ||
|
||
function DashboardExtension({ dashboardLinkConfig }: { dashboardLinkConfig: DashboardLinkConfig }) { | ||
const { t } = useTranslation(); | ||
const { name, title, isFolder, folderTitle, folderIcon, childLinks, isHidden } = dashboardLinkConfig; | ||
const location = useLocation(); | ||
const spaBasePath = `${window.spaBase}/home`; | ||
|
||
const navLink = useMemo(() => { | ||
const pathArray = location.pathname.split('/home'); | ||
const lastElement = pathArray[pathArray.length - 1]; | ||
return decodeURIComponent(lastElement); | ||
}, [location.pathname]); | ||
|
||
if (isHidden) { | ||
return; | ||
} | ||
|
||
if (isFolder) { | ||
return ( | ||
<SideNavItems> | ||
<SideNavMenu title={folderTitle} renderIcon={folderIcon}> | ||
<ConfigurableLink | ||
className={classNames('cds--side-nav__link', { | ||
'active-left-nav-link': navLink.match(name), | ||
})} | ||
to={`${spaBasePath}/${name}`}> | ||
{t(title)} | ||
</ConfigurableLink> | ||
{Array.isArray(childLinks) && | ||
childLinks.map((childLink, childIndex) => ( | ||
<ConfigurableLink | ||
key={childIndex} | ||
className={classNames('cds--side-nav__link', { | ||
'active-left-nav-link': navLink.match(childLink.name), | ||
})} | ||
to={`${spaBasePath}/${childLink.name}`}> | ||
{t(childLink.title)} | ||
</ConfigurableLink> | ||
))} | ||
</SideNavMenu> | ||
</SideNavItems> | ||
); | ||
} else { | ||
return ( | ||
<SideNavItems> | ||
<ConfigurableLink | ||
className={classNames('cds--side-nav__link', { | ||
'active-left-nav-link': navLink.match(name), | ||
})} | ||
to={`${spaBasePath}/${name}`}> | ||
{t(title)} | ||
</ConfigurableLink> | ||
</SideNavItems> | ||
); | ||
} | ||
} | ||
|
||
export const createOHRIGroupedLink = (dashboardLinkConfig: DashboardLinkConfig) => () => ( | ||
<BrowserRouter> | ||
<DashboardExtension dashboardLinkConfig={dashboardLinkConfig} /> | ||
</BrowserRouter> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { OHRIWelcomeSection } from '@ohri/openmrs-esm-ohri-commons-lib'; | ||
import React from 'react'; | ||
import CovidHomePatientTabs from './views/dashboard/patient-list-tabs/covid-patient-list-tabs.component'; | ||
import CovidSummaryTiles from './views/dashboard/summary-tiles/covid-summary-tiles.component'; | ||
|
||
const Homecomponent = () => { | ||
return ( | ||
<div> | ||
<OHRIWelcomeSection title="COVID-19 Cases" /> | ||
<CovidSummaryTiles /> | ||
<CovidHomePatientTabs /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Homecomponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { SWRConfig } from 'swr'; | ||
import { BrowserRouter, Route, Routes } from 'react-router-dom'; | ||
import Home from './home.component'; | ||
|
||
const swrConfiguration = { | ||
// Maximum number of retries when the backend returns an error | ||
errorRetryCount: 3, | ||
}; | ||
|
||
const Root: React.FC = () => { | ||
const covidBasename = window.getOpenmrsSpaBase() + 'home/covid-cases'; | ||
|
||
return ( | ||
<main> | ||
<SWRConfig value={swrConfiguration}> | ||
<BrowserRouter basename={covidBasename}> | ||
<Routes> | ||
<Route path="/" element={<Home />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
</SWRConfig> | ||
</main> | ||
); | ||
}; | ||
|
||
export default Root; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { OHRIWelcomeSection } from '@ohri/openmrs-esm-ohri-commons-lib'; | ||
import React from 'react'; | ||
import CTSummaryTiles from './views/hts/care-and-treatment/summary-tiles/ct-summary-tiles.component'; | ||
import CTHomePatientTabs from './views/hts/patient-list-tabs/ct-patient-list-tabs.component'; | ||
|
||
const Homecomponent = () => { | ||
return ( | ||
<div> | ||
<OHRIWelcomeSection title="Care and Treatment" /> | ||
<CTSummaryTiles /> | ||
<CTHomePatientTabs /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Homecomponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { SWRConfig } from 'swr'; | ||
import { BrowserRouter, Route, Routes } from 'react-router-dom'; | ||
import Home from './hiv-treatment-home.component'; | ||
|
||
const swrConfiguration = { | ||
// Maximum number of retries when the backend returns an error | ||
errorRetryCount: 3, | ||
}; | ||
|
||
const Root: React.FC = () => { | ||
const hivTreatmentBasename = window.getOpenmrsSpaBase() + 'home/care-and-treatment'; | ||
|
||
return ( | ||
<main> | ||
<SWRConfig value={swrConfiguration}> | ||
<BrowserRouter basename={hivTreatmentBasename}> | ||
<Routes> | ||
<Route path="/" element={<Home />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
</SWRConfig> | ||
</main> | ||
); | ||
}; | ||
|
||
export default Root; |
Oops, something went wrong.