Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panel:Add an extensionSlot for lab tab panels #28

Merged
merged 11 commits into from
Jan 16, 2024
20 changes: 20 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ export const rejectOrderDialog = getAsyncLifecycle(
options
);

export const reviewComponent = getAsyncLifecycle(
() => import("./lab-tabs/review-tab.component"),
options
);

export const approvedComponent = getAsyncLifecycle(
() => import("./lab-tabs/approved-tab.component"),
options
);

export const referredTestComponent = getAsyncLifecycle(
() => import("./lab-tabs/referred-tab.component"),
options
);

export const worklistComponent = getAsyncLifecycle(
() => import("./lab-tabs/work-list-tab.component"),
options
);

export const pickLabRequestButton = getAsyncLifecycle(
() => import("./queue-list/pick-lab-request-menu.component"),
options
Expand Down
14 changes: 14 additions & 0 deletions src/lab-tabs/approved-tab.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import CompletedList from "../completed-list/completed-list.component";
import styles from "../queue-list/laboratory-queue.scss";

const ApprovedComponent = () => {
return (
<div>
<div className={styles.headerBtnContainer}></div>
<CompletedList fulfillerStatus={"COMPLETED"} />
</div>
);
};

export default ApprovedComponent;
18 changes: 18 additions & 0 deletions src/lab-tabs/referred-tab.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import { EmptyState } from "@openmrs/esm-patient-common-lib";
import styles from "../queue-list/laboratory-queue.scss";

const ReferredComponent = () => {
return (
<div>
<div className={styles.headerBtnContainer}></div>

<EmptyState
displayText={"referred tests"}
headerTitle={"Referred tests"}
/>
</div>
);
};

export default ReferredComponent;
14 changes: 14 additions & 0 deletions src/lab-tabs/review-tab.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import ReviewList from "../review-list/review-list.component";
import styles from "../queue-list/laboratory-queue.scss";

const ReviewComponent = () => {
return (
<div>
<div className={styles.headerBtnContainer}></div>
<ReviewList fulfillerStatus={"IN_PROGRESS"} />
</div>
);
};

export default ReviewComponent;
14 changes: 14 additions & 0 deletions src/lab-tabs/work-list-tab.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import WorkList from "../work-list/work-list.component";
import styles from "../queue-list/laboratory-queue.scss";

const WorkListComponent = () => {
return (
<div>
<div className={styles.headerBtnContainer}></div>
<WorkList fulfillerStatus={"IN_PROGRESS"} />
</div>
);
};

export default WorkListComponent;
112 changes: 80 additions & 32 deletions src/queue-list/laboratory-tabs.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";
import {
type AssignedExtension,
Extension,
ExtensionSlot,
useConnectedExtensions,
attach,
detachAll,
} from "@openmrs/esm-framework";
import { Tab, Tabs, TabList, TabPanels, TabPanel, Search } from "@carbon/react";
import { useTranslation } from "react-i18next";
import styles from "./laboratory-queue.scss";
Expand All @@ -15,9 +23,57 @@
ALL,
}

const labPanelSlot = "lab-panels-slot";

const LaboratoryQueueTabs: React.FC = () => {
const { t } = useTranslation();
const [selectedTab, setSelectedTab] = useState(0);
const tabExtensions = useConnectedExtensions(
labPanelSlot
) as AssignedExtension[];

const [derivedSlots, setDerivedSlots] = useState<
{ slot: string; extension: string }[]
>([]);

const extraPanels = useMemo(() => {
const filteredExtensions = tabExtensions.filter(
(extension) => Object.keys(extension.meta).length > 0
);
const derivedSlotsBuffer = [];
return filteredExtensions.map((extension, index) => {
const slotName = `${labPanelSlot}-${index}`;
derivedSlotsBuffer.push({
slot: slotName,
extension: extension.name,
});
if (filteredExtensions.length === index + 1) {
setDerivedSlots(derivedSlotsBuffer);
}

return (
<TabPanel key={extension.meta.name} style={{ padding: 0 }}>
<div>
<div className={styles.headerBtnContainer}></div>
<ExtensionSlot name={slotName} />
</div>
</TabPanel>
);
});
}, [tabExtensions?.length]);

Check warning on line 63 in src/queue-list/laboratory-tabs.component.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useMemo has a missing dependency: 'tabExtensions'. Either include it or remove the dependency array

useEffect(() => {
derivedSlots.forEach(({ slot, extension }) => {
attach(slot, extension);
});

return () => {
derivedSlots.forEach(({ slot }) => {
detachAll(slot);
});
};
}, [derivedSlots]);

return (
<main className={`omrs-main-content`}>
<section className={styles.orderTabsContainer}>
Expand All @@ -32,10 +88,28 @@
contained
>
<Tab>{t("testedOrders", "Tests ordered")}</Tab>
<Tab>{t("worklist", "Worklist")}</Tab>
<Tab>{t("referredTests", "Referred tests")}</Tab>
<Tab>{t("reviewList", "Review")}</Tab>
<Tab>{t("approveList", "Approved")}</Tab>
{tabExtensions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the check here as well. Refer to previous comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @pirupius i added a check that makes sure that the title and name values of the extension.meta object are truthy before rendering the Tab which is automatically mapped to the corresponding TabPanel .
Kindly see the updated screenshot

.filter((extension) => Object.keys(extension.meta).length > 0)
.map((extension, index) => {
const { name, title } = extension.meta;

if (name && title) {
return (
<Tab
key={index}
className={styles.tab}
id={`${title || index}-tab`}
>
{t(title, {
ns: extension.moduleName,
defaultValue: title,
})}
</Tab>
);
} else {
return null;
}
})}
</TabList>
<TabPanels>
<TabPanel style={{ padding: 0 }}>
Expand All @@ -44,33 +118,7 @@
<LaboratoryPatientList />
</div>
</TabPanel>
<TabPanel style={{ padding: 0 }}>
<div>
<div className={styles.headerBtnContainer}></div>
<WorkList fulfillerStatus={"IN_PROGRESS"} />
</div>
</TabPanel>
<TabPanel style={{ padding: 0 }}>
<div>
<div className={styles.headerBtnContainer}></div>
<EmptyState
displayText={"referred tests"}
headerTitle={"Referred tests"}
/>
</div>
</TabPanel>
<TabPanel style={{ padding: 0 }}>
<div>
<div className={styles.headerBtnContainer}></div>
<ReviewList fulfillerStatus={"IN_PROGRESS"} />
</div>
</TabPanel>
<TabPanel style={{ padding: 0 }}>
<div>
<div className={styles.headerBtnContainer}></div>
<CompletedList fulfillerStatus={"COMPLETED"} />
</div>
</TabPanel>
{extraPanels}
</TabPanels>
</Tabs>
</section>
Expand Down
36 changes: 36 additions & 0 deletions src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@
"name" : "reject-order-dialog",
"component": "rejectOrderDialog"
},
{
"name": "worklist-panel-component",
"slot": "lab-panels-slot",
"component": "worklistComponent",
"meta": {
"name": "worklistPanelSlot",
"title": "Worklist"
}
},
{
"name": "referred-panel-component",
"slot": "lab-panels-slot",
"component": "referredTestComponent",
"meta": {
"name": "referredPanleSlot",
"title": "Referred tests"
}
},
{
"name": "review-panel-component",
"slot": "lab-panels-slot",
"component": "reviewComponent",
"meta": {
"name": "reviewPanelSlot",
"title": "Review"
}
},
{
"name": "approved-panel-component",
"slot": "lab-panels-slot",
"component": "approvedComponent",
"meta": {
"name": "approvedPanelSlot",
"title": "Approved"
}
},
{
"name": "pick-lab-request-button",
"component": "pickLabRequestButton",
Expand Down
Loading