Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pirupius committed Sep 11, 2023
1 parent d073546 commit 70935fc
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 119 deletions.
2 changes: 1 addition & 1 deletion packages/esm-commons-lib/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export interface OhriDashboardMeta {
* Used to generate the menu title displayed on the sidenav
* @example "Covid Cases"
*/
menuTitle: string;
title: string;
slot: string;
config: {
columns?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,3 @@ export const createOHRIPatientChartSideNavLink = (meta) => {
};
return NavItem;
};

export const patientChartDivider_dashboardMeta = {
name: 'clinical-views-divider',
slot: 'patient-chart-sidenav-divider-slot',
config: { columns: 1, type: 'grid' },
title: 'Clinical Views',
};
4 changes: 2 additions & 2 deletions packages/esm-covid-app/src/dashboard.meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export const covidVaccinationsDashboardMeta = {

// Clinical Dashboards
export const covidClinicalViewDashboardMeta: OhriDashboardMeta = {
menuTitle: 'COVID',
slot: 'ohri-covid-dashboard-slot',
config: { columns: 1, type: 'grid', icon: Coronavirus },
isFolder: true,
title: 'COVID',
};

export const covid19CasesDashboardMeta: OhriDashboardLinkMeta = {
name: 'covid-cases',
slot: 'covid-cases-dashboard-slot',
config: { columns: 1, type: 'grid', programme: 'covid', icon: Coronavirus },
config: { columns: 1, type: 'grid', programme: 'covid', dashboardTitle: 'Covid-19 Cases' },
title: 'COVID-19 Cases',
};
2 changes: 1 addition & 1 deletion packages/esm-hiv-app/src/dashboard.meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const hivFolderDashboardMeta: OhriDashboardMeta = {
slot: 'ohri-hiv-dashboard-slot',
config: { columns: 1, type: 'grid', icon: Home },
isFolder: true,
menuTitle: 'HIV',
title: 'HIV',
};

export const htsDashboardMeta: OhriDashboardLinkMeta = {
Expand Down
7 changes: 7 additions & 0 deletions packages/esm-ohri-core-app/src/dashboard.meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ export const serviceQueuesDashboardMeta = {
isLink: true,
title: 'Service Queues',
};

export const patientChartDivider_dashboardMeta = {
name: 'clinical-views-divider',
slot: 'patient-chart-sidenav-divider-slot',
config: { columns: 1, type: 'grid' },
title: 'Clinical Views',
};
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>
);
};
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;
5 changes: 5 additions & 0 deletions packages/esm-ohri-core-app/src/dashboard/dashboard-view.scss
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 packages/esm-ohri-core-app/src/dashboard/home.component.tsx
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>
);
}
43 changes: 43 additions & 0 deletions packages/esm-ohri-core-app/src/dashboard/routes.json
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
}
]
}
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;
17 changes: 7 additions & 10 deletions packages/esm-ohri-core-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineConfigSchema, getAsyncLifecycle, getSyncLifecycle, provide } from '@openmrs/esm-framework';
import {
createOHRIPatientChartSideNavLink,
patientChartDivider_dashboardMeta,
createOHRIDashboardLink,
PatientListTable,
} from '@ohri/openmrs-esm-ohri-commons-lib';
Expand All @@ -10,6 +9,7 @@ import {
homeDashboardMeta,
dispensingDashboardMeta,
serviceQueuesDashboardMeta,
patientChartDivider_dashboardMeta,
} from './dashboard.meta';

export const importTranslation = require.context('../translations', false, /.json$/, 'lazy');
Expand All @@ -36,25 +36,22 @@ export const patientList = getSyncLifecycle(PatientListTable, {

export const appointmentsLink = getSyncLifecycle(createOHRIDashboardLink(appointmentsDashboardMeta), options);
export const appointmentsDashboard = getAsyncLifecycle(
() => import('./ohri-dashboard/appointments/appointments-dashboard.component'),
() => import('./appointments/appointments-dashboard.component'),
{
featureName: 'appointments-dashboard',
moduleName,
},
);

export const dispensingLink = getSyncLifecycle(createOHRIDashboardLink(dispensingDashboardMeta), options);
export const dispensingDashboard = getAsyncLifecycle(
() => import('./ohri-dashboard/dispensing/dispensing-dashboard.component'),
{
featureName: 'dispensing-dashboard',
moduleName,
},
);
export const dispensingDashboard = getAsyncLifecycle(() => import('./dispensing/dispensing-dashboard.component'), {
featureName: 'dispensing-dashboard',
moduleName,
});

export const serviceQueuesLink = getSyncLifecycle(createOHRIDashboardLink(serviceQueuesDashboardMeta), options);
export const serviceQueuesDashboard = getAsyncLifecycle(
() => import('./ohri-dashboard/service-queues/service-queues-dashboard.component'),
() => import('./service-queues/service-queues-dashboard.component'),
{
featureName: 'service-queues-dashboard',
moduleName,
Expand Down
31 changes: 22 additions & 9 deletions packages/esm-ohri-core-app/src/root.tsx
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;
2 changes: 1 addition & 1 deletion packages/esm-ohri-pmtct-app/src/dashboard.meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const childVisitsDashboardMeta = {
export const motherChildDashboardMeta = {
name: 'mother-child-health',
slot: 'mother-child-health-dashboard-slot',
menuTitle: 'Maternal & Child Health',
title: 'Maternal & Child Health',
config: {
columns: 1,
type: 'grid',
Expand Down
Loading

0 comments on commit 70935fc

Please sign in to comment.