-
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.
- Loading branch information
Showing
18 changed files
with
273 additions
and
119 deletions.
There are no files selected for viewing
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
File renamed without changes.
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
36 changes: 36 additions & 0 deletions
36
packages/esm-ohri-core-app/src/dashboard/create-dashboard-link.component.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,36 @@ | ||
import React, { useMemo } from 'react'; | ||
import { BrowserRouter, useLocation } from 'react-router-dom'; | ||
import { ConfigurableLink } from '@openmrs/esm-framework'; | ||
|
||
export interface DashboardLinkConfig { | ||
name: string; | ||
title: string; | ||
} | ||
|
||
const DashboardLink = ({ dashboardLinkConfig }: { dashboardLinkConfig: DashboardLinkConfig }) => { | ||
const { name } = dashboardLinkConfig; | ||
const location = useLocation(); | ||
const spaBasePath = `${window.spaBase}/home`; | ||
|
||
const navLink = useMemo(() => { | ||
const pathArray = location.pathname.split('/'); | ||
const lastElement = pathArray[pathArray.length - 1]; | ||
return decodeURIComponent(lastElement); | ||
}, [location.pathname]); | ||
|
||
return ( | ||
<ConfigurableLink | ||
to={spaBasePath} | ||
className={`cds--side-nav__link ${navLink === 'home' && 'active-left-nav-link'}`}> | ||
{name} | ||
</ConfigurableLink> | ||
); | ||
}; | ||
|
||
export const createDashboardLink = (dashboardLinkConfig: DashboardLinkConfig) => { | ||
return () => ( | ||
<BrowserRouter> | ||
<DashboardLink dashboardLinkConfig={dashboardLinkConfig} /> | ||
</BrowserRouter> | ||
); | ||
}; |
9 changes: 9 additions & 0 deletions
9
packages/esm-ohri-core-app/src/dashboard/dashboard-view.component.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,9 @@ | ||
import React from 'react'; | ||
import { ExtensionSlot } from '@openmrs/esm-framework'; | ||
import styles from './dashboard-view.scss'; | ||
|
||
const DashboardView: React.FC<{ dashboardSlot: string; title: string }> = ({ dashboardSlot, title }) => { | ||
return <ExtensionSlot className={styles.dashboardView} name={dashboardSlot} state={{ dashboardTitle: title }} />; | ||
}; | ||
|
||
export default DashboardView; |
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,5 @@ | ||
@use '@carbon/colors'; | ||
|
||
.dashboardView { | ||
background-color: colors.$white-0; | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/esm-ohri-core-app/src/dashboard/home.component.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,31 @@ | ||
import React from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useLayoutType, isDesktop, useExtensionStore, ExtensionSlot } from '@openmrs/esm-framework'; | ||
import DashboardView from './dashboard-view.component'; | ||
import styles from './home-dashboard.scss'; | ||
|
||
// TODO PIUS move this to a shared location | ||
export interface DashboardConfig { | ||
name: string; | ||
slot: string; | ||
title: string; | ||
} | ||
|
||
export default function HomeDashboard() { | ||
const params = useParams(); | ||
const extensionStore = useExtensionStore(); | ||
const layout = useLayoutType(); | ||
const ungroupedDashboards = | ||
extensionStore.slots['ohri-dashboard-slot']?.assignedExtensions | ||
.map((e) => e.meta) | ||
.filter((e) => Object.keys(e).length) || []; | ||
const dashboards = ungroupedDashboards as Array<DashboardConfig>; | ||
const activeDashboard = dashboards.find((dashboard) => dashboard.name === params?.dashboard) || dashboards[0]; | ||
|
||
return ( | ||
<section className={isDesktop(layout) && styles.dashboardContainer}> | ||
{isDesktop(layout) && <ExtensionSlot name="ohri-sidebar-slot" key={layout} />} | ||
<DashboardView title={activeDashboard?.name} dashboardSlot={activeDashboard?.slot} /> | ||
</section> | ||
); | ||
} |
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,43 @@ | ||
{ | ||
"$schema": "https://json.openmrs.org/routes.schema.json", | ||
"backendDependencies": { | ||
"webservices.rest": "^2.24.0" | ||
}, | ||
"pages": [ | ||
{ | ||
"component": "root", | ||
"route": "home", | ||
"online": true, | ||
"offline": true | ||
} | ||
], | ||
"extensions": [ | ||
{ | ||
"name": "home-nav-menu", | ||
"slot": "home-sidebar-slot", | ||
"component": "homeNavMenu", | ||
"online": true, | ||
"offline": true | ||
}, | ||
{ | ||
"name": "home-widget-db-link", | ||
"slot": "ohri-dashboard-slot", | ||
"component": "homeWidgetDbLink", | ||
"meta": { | ||
"name": "Home", | ||
"slot": "home-dashboard-slot", | ||
"title": "" | ||
}, | ||
"order": 0, | ||
"online": true, | ||
"offline": true | ||
}, | ||
{ | ||
"name": "home-widget-dashboard", | ||
"slot": "home-dashboard-slot", | ||
"component": "homeWidgetDashboard", | ||
"online": true, | ||
"offline": true | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/esm-ohri-core-app/src/dashboard/side-menu.component.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,6 @@ | ||
import React from 'react'; | ||
import { LeftNavMenu } from '@openmrs/esm-framework'; | ||
|
||
const SideMenu = () => <LeftNavMenu />; | ||
|
||
export default SideMenu; |
File renamed without changes.
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 |
---|---|---|
@@ -1,15 +1,28 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'; | ||
import OHRIDashboard from './ohri-dashboard/ohri-dashboard.component'; | ||
import HomeDashboard from './dashboard/home.component'; | ||
import { setLeftNav, unsetLeftNav } from '@openmrs/esm-framework'; | ||
|
||
const Root: React.FC = () => { | ||
const spaBasePath = window.spaBase; | ||
|
||
useEffect(() => { | ||
setLeftNav({ name: 'ohri-dashboard-slot', basePath: spaBasePath }); | ||
return () => unsetLeftNav('ohri-dashboard-slot'); | ||
}, [spaBasePath]); | ||
|
||
export default function Root() { | ||
return ( | ||
<BrowserRouter basename={window['getOpenmrsSpaBase']()}> | ||
<Routes> | ||
<Route path="/dashboard" element={<OHRIDashboard />} /> | ||
<Route path="/dashboard/:view" element={<OHRIDashboard />} /> | ||
<Route path="/home" element={<Navigate to={'/dashboard/home'} replace />} /> | ||
</Routes> | ||
<BrowserRouter basename={window.spaBase}> | ||
<main className="omrs-main-content"> | ||
<Routes> | ||
<Route path="/dashboard" element={<HomeDashboard />} /> | ||
<Route path="/dashboard/:view" element={<HomeDashboard />} /> | ||
<Route path="/home" element={<Navigate to={'/dashboard/home'} replace />} /> | ||
</Routes> | ||
</main> | ||
</BrowserRouter> | ||
); | ||
} | ||
}; | ||
|
||
export default Root; |
File renamed without changes.
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
Oops, something went wrong.