Skip to content

Commit

Permalink
(fix) Fix dashboard link (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen authored Nov 28, 2023
1 parent 98c3cfa commit d9088de
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
6 changes: 0 additions & 6 deletions packages/esm-billing-app/src/dashboard.meta.ts

This file was deleted.

13 changes: 9 additions & 4 deletions packages/esm-billing-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { getAsyncLifecycle, defineConfigSchema, registerBreadcrumbs, getSyncLifecycle } from '@openmrs/esm-framework';
import { defineConfigSchema, getSyncLifecycle } from '@openmrs/esm-framework';
import { configSchema } from './config-schema';
import { dashboardMeta } from './dashboard.meta';
import { createDashboardLink, registerWorkspace } from '@openmrs/esm-patient-common-lib';

import rootComponent from './root.component';
import { createLeftPanelLink } from './left-panel-link.component';

const moduleName = '@kenyaemr/esm-billing-app';

Expand All @@ -13,7 +12,13 @@ const options = {
};

// t('billing', 'Billing')
export const billingDashboardLink = getSyncLifecycle(createDashboardLink({ ...dashboardMeta, moduleName }), options);
export const billingDashboardLink = getSyncLifecycle(
createLeftPanelLink({
name: 'billing',
title: 'Billing',
}),
options,
);

export const importTranslation = require.context('../translations', false, /.json$/, 'lazy');

Expand Down
32 changes: 32 additions & 0 deletions packages/esm-billing-app/src/left-panel-link.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useMemo } from 'react';
import last from 'lodash-es/last';
import { BrowserRouter, useLocation } from 'react-router-dom';
import { ConfigurableLink } from '@openmrs/esm-framework';

export interface LinkConfig {
name: string;
title: string;
}

function LinkExtension({ config }: { config: LinkConfig }) {
const { name, title } = config;
const location = useLocation();
const spaBasePath = window.getOpenmrsSpaBase() + 'home';

const urlSegment = useMemo(() => decodeURIComponent(last(location.pathname.split('/'))), [location.pathname]);

return (
<ConfigurableLink
to={spaBasePath + '/' + name}
className={`cds--side-nav__link ${name === urlSegment && 'active-left-nav-link'}`}>
{title}
</ConfigurableLink>
);
}

export const createLeftPanelLink = (config: LinkConfig) => () =>
(
<BrowserRouter>
<LinkExtension config={config} />
</BrowserRouter>
);

0 comments on commit d9088de

Please sign in to comment.