diff --git a/packages/apps/esm-offline-tools-app/src/createDashboardLink.tsx b/packages/apps/esm-offline-tools-app/src/createDashboardLink.tsx index 53e664779..98dd4a974 100644 --- a/packages/apps/esm-offline-tools-app/src/createDashboardLink.tsx +++ b/packages/apps/esm-offline-tools-app/src/createDashboardLink.tsx @@ -1,15 +1,16 @@ -import React, { useMemo } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import last from "lodash-es/last"; import { BrowserRouter, useLocation } from "react-router-dom"; import { ConfigurableLink } from "@openmrs/esm-framework"; -import styles from "./dashboard-link.scss"; - interface DashboardLinkConfig { - title: string; + basePath?: string; + path: string; + title: string | (() => string | Promise); } -const DashboardLink: React.FC<{ basePath: string; title: string }> = ({ +const DashboardLink: React.FC = ({ basePath, + path, title, }) => { const location = useLocation(); @@ -17,26 +18,44 @@ const DashboardLink: React.FC<{ basePath: string; title: string }> = ({ () => decodeURIComponent(last(location.pathname.split("/"))), [location.pathname] ); + const [resolvedTitle, setResolvedTitle] = useState(); + + useEffect(() => { + if (typeof title === "function") { + Promise.resolve(title()) + .then((resolvedValue) => { + setResolvedTitle(resolvedValue); + }) + .catch((e: Error) => { + throw e; + }); + } else { + setResolvedTitle(title); + } + }, [title]); const activeClassName = - title === navLink ? "active-left-nav-link" : "non-active"; + path === navLink ? "active-left-nav-link" : "non-active"; return ( -
- - {title} - -
+ title && + resolvedTitle && ( +
+ + {resolvedTitle} + +
+ ) ); }; export const createDashboardLink = (db: DashboardLinkConfig) => { return ({ basePath }: { basePath: string }) => ( - + ); }; diff --git a/packages/apps/esm-offline-tools-app/src/dashboard-link.scss b/packages/apps/esm-offline-tools-app/src/dashboard-link.scss deleted file mode 100644 index 0f0fe971c..000000000 --- a/packages/apps/esm-offline-tools-app/src/dashboard-link.scss +++ /dev/null @@ -1 +0,0 @@ -@import "~@openmrs/esm-styleguide/src/vars"; diff --git a/packages/apps/esm-offline-tools-app/src/dashboard.meta.ts b/packages/apps/esm-offline-tools-app/src/dashboard.meta.ts index 748e58eff..ecbe26133 100644 --- a/packages/apps/esm-offline-tools-app/src/dashboard.meta.ts +++ b/packages/apps/esm-offline-tools-app/src/dashboard.meta.ts @@ -1,5 +1,6 @@ export const dashboardMeta = { slot: "patient-chart-offline-actions-dashboard-slot", columns: 1, + path: "Offline Actions", title: "Offline Actions", }; diff --git a/packages/apps/esm-offline-tools-app/src/index.ts b/packages/apps/esm-offline-tools-app/src/index.ts index 6b936ff9f..a3960c462 100644 --- a/packages/apps/esm-offline-tools-app/src/index.ts +++ b/packages/apps/esm-offline-tools-app/src/index.ts @@ -89,7 +89,17 @@ export const offlineToolsPatientChartActionsDashboard = getAsyncLifecycle( ); export const offlineToolsPatientChartActionsDashboardLink = getSyncLifecycle( - createDashboardLink(dashboardMeta), + createDashboardLink({ + ...dashboardMeta, + // t('offline_actions_link', 'Offline Actions') + title: () => + Promise.resolve( + window.i18next?.t("offline_actions_link", { + defaultValue: "Offline Actions", + ns: moduleName, + }) ?? "Offline Actions" + ), + }), options ); diff --git a/packages/apps/esm-offline-tools-app/src/nav/offline-tools-nav-link.component.tsx b/packages/apps/esm-offline-tools-app/src/nav/offline-tools-nav-link.component.tsx index 5cb4a0041..5410e5292 100644 --- a/packages/apps/esm-offline-tools-app/src/nav/offline-tools-nav-link.component.tsx +++ b/packages/apps/esm-offline-tools-app/src/nav/offline-tools-nav-link.component.tsx @@ -1,5 +1,5 @@ -import { ConfigurableLink } from "@openmrs/esm-framework"; import React from "react"; +import { ConfigurableLink } from "@openmrs/esm-framework"; import { routes } from "../constants"; interface OfflineToolsNavLinkProps {