Skip to content

Commit

Permalink
Default discontinued prescriptions to collapsed view
Browse files Browse the repository at this point in the history
  • Loading branch information
bodhish committed May 8, 2024
1 parent ff6b787 commit 8892f56
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Components/Medicine/PrescriptionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ export default function PrescriptionsTable({
? DISCHARGE_PRN_TKEYS
: DISCHARGE_NORMAL_TKEYS;

// Implementing collapsible view for each prescription entry
const [collapsedPrescriptions, setCollapsedPrescriptions] = useState<string[]>([]);

Check failure on line 59 in src/Components/Medicine/PrescriptionsTable.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `string[]` with `⏎····string[]⏎··`

const toggleCollapse = (id: string) => {
setCollapsedPrescriptions((prev) => {
if (prev.includes(id)) {
return prev.filter((prescriptionId) => prescriptionId !== id);
} else {
return [...prev, id];
}
});
};

// Default the view of discontinued prescriptions to collapsed
const discontinuedPrescriptions = data?.results.filter((prescription) => prescription.discontinued).map((prescription) => prescription.id) || [];

Check failure on line 72 in src/Components/Medicine/PrescriptionsTable.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `·data?.results.filter((prescription)·=>·prescription.discontinued)` with `⏎····data?.results⏎······.filter((prescription)·=>·prescription.discontinued)⏎······`
useState(() => {
setCollapsedPrescriptions(discontinuedPrescriptions);
});

return (
<div>
{data?.results && (
Expand Down Expand Up @@ -205,6 +224,19 @@ export default function PrescriptionsTable({
) : (
"never"
),
// Adding a toggle button to expand/collapse the prescription details
actions: (
<button
onClick={() => toggleCollapse(obj.id)}
className="text-primary-600 hover:text-primary-900"
>
{collapsedPrescriptions.includes(obj.id) ? (
<CareIcon icon="l-angle-down" />
) : (
<CareIcon icon="l-angle-up" />
)}
</button>
),
})) || []
}
objectKeys={Object.values(tkeys)}
Expand Down

0 comments on commit 8892f56

Please sign in to comment.