Skip to content

Commit

Permalink
O3 2777: Dispensing: Only have Prescription Tabs load when selected (#98
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mogoodrich authored Jan 29, 2024
1 parent 910fd1a commit ab74fa0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/prescriptions/prescription-tab-lists.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@ import { useConfig } from "@openmrs/esm-framework";
import { PharmacyConfig } from "../config-schema";
import { SimpleLocation } from "../types";

enum TabTypes {
STARRED,
SYSTEM,
USER,
ALL,
}

const PrescriptionTabLists: React.FC = () => {
const { t } = useTranslation();
const config = useConfig() as PharmacyConfig;
const { filterLocations, isLoading: isFilterLocationsLoading } =
useLocationForFiltering(config);
const [selectedTab, setSelectedTab] = useState(TabTypes.STARRED);
const [searchTermUserInput, setSearchTermUserInput] = useState(""); // we have a separate "searchTermUserInput" and "searchTerm" in order to debounce
const [searchTerm, setSearchTerm] = useState("");
const [location, setLocation] = useState("");
const [selectedTab, setSelectedTab] = useState(0);

const tabs = [
{
Expand All @@ -47,14 +40,19 @@ const PrescriptionTabLists: React.FC = () => {
return () => clearTimeout(debounceFn);
}, [searchTermUserInput]);

// we use this to only render the tab panel that is currently selected, see O3-2777
const handleTabChange = (event) => {
setSelectedTab(event.selectedIndex);
};

return (
<main className={`omrs-main-content ${styles.prescriptionListContainer}`}>
<section className={styles.prescriptionTabsContainer}>
<Tabs
className={styles.prescriptionTabs}
onChange={handleTabChange}
type="container"
tabContentClassName={styles.hiddenTabsContent}
onSelectionChange={setSelectedTab}
>
<TabList
aria-label={t("tabList", "Tab List")}
Expand Down Expand Up @@ -118,12 +116,14 @@ const PrescriptionTabLists: React.FC = () => {
</div>
<TabPanels>
{tabs.map((tab, index) => {
return (
return index === selectedTab ? (
<PrescriptionTabPanel
location={location}
searchTerm={searchTerm}
status={tab.status}
/>
) : (
<></>
);
})}
</TabPanels>
Expand Down

0 comments on commit ab74fa0

Please sign in to comment.