Skip to content

Commit fc83afb

Browse files
authoredJul 14, 2021
Minor fixups in active visits widget (#21)
* Fixup in the patient chart link * Changed link color to blue * Added custom filtering in table * Review changes
1 parent 73fbbb4 commit fc83afb

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed
 

‎packages/esm-active-visits-app/src/active-visits-widget/active-visits.component.tsx

+33-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useEffect, useState } from 'react';
1+
import React, { useMemo, useEffect, useState, useCallback } from 'react';
22
import DataTable, {
33
TableContainer,
44
Table,
@@ -74,11 +74,24 @@ const ActiveVisitsTable = (props) => {
7474
const pageSizes = config?.activeVisits?.pageSizes ?? [10, 20, 50];
7575
const [loading, setLoading] = useState(true);
7676
const [activeVisits, setActiveVisits] = useState<ActiveVisitRow[]>([]);
77-
const { goTo, currentPage } = usePagination(activeVisits, currentPageSize);
78-
const [lowerBound, upperBound] = useMemo(
79-
() => [(currentPage - 1) * currentPageSize, (currentPage + 0) * currentPageSize],
80-
[currentPage, currentPageSize],
81-
);
77+
const [searchString, setSearchString] = useState('');
78+
79+
const searchResults = useMemo(() => {
80+
if (searchString && searchString.trim() !== '') {
81+
const search = searchString.toLowerCase();
82+
return activeVisits.filter((activeVisitRow) =>
83+
Object.keys(activeVisitRow).some((header) => {
84+
if (header === 'patientUuid') {
85+
return false;
86+
}
87+
return `${activeVisitRow[header]}`.toLowerCase().includes(search);
88+
}),
89+
);
90+
} else {
91+
return activeVisits;
92+
}
93+
}, [searchString, activeVisits]);
94+
const { goTo, currentPage, results } = usePagination(searchResults, currentPageSize);
8295

8396
useEffect(() => {
8497
const activeVisits = fetchActiveVisits().subscribe((data) => {
@@ -98,20 +111,22 @@ const ActiveVisitsTable = (props) => {
98111
return () => activeVisits.unsubscribe();
99112
}, []);
100113

114+
const handleSearch = useCallback((e) => setSearchString(e.target.value), []);
115+
101116
return !loading ? (
102117
<div className={styles.activeVisitsContainer}>
103118
<div className={styles.activeVisitsDetailHeaderContainer}>
104119
<h4 className={styles.productiveHeading02}>{t('activeVisits', 'Active Visits')}</h4>
105120
</div>
106-
<DataTable rows={activeVisits} headers={headerData} isSortable>
107-
{({ rows, headers, getHeaderProps, onInputChange, getTableProps, getBatchActionProps }) => (
121+
<DataTable rows={results} headers={headerData} isSortable>
122+
{({ rows, headers, getHeaderProps, getTableProps, getBatchActionProps }) => (
108123
<TableContainer title="" className={styles.tableContainer}>
109124
<TableToolbar>
110125
<TableToolbarContent>
111126
<Search
112127
tabIndex={getBatchActionProps().shouldShowBatchActions ? -1 : 0}
113-
placeHolderText="Filter table"
114-
onChange={onInputChange}
128+
placeholder="Filter table"
129+
onChange={handleSearch}
115130
/>
116131
</TableToolbarContent>
117132
</TableToolbar>
@@ -124,12 +139,12 @@ const ActiveVisitsTable = (props) => {
124139
</TableRow>
125140
</TableHead>
126141
<TableBody>
127-
{rows.slice(lowerBound, upperBound).map((row) => (
142+
{rows.map((row, ind) => (
128143
<TableRow key={row.id} style={{ height: desktopView ? '2rem' : '3rem' }}>
129-
{row.cells.map((cell, ind) => (
144+
{row.cells.map((cell) => (
130145
<TableCell key={cell.id}>
131146
{cell.info.header === 'name' ? (
132-
<ConfigurableLink to={`\${openmrsSpaBase}/patient/${activeVisits[ind].patientUuid}/chart/`}>
147+
<ConfigurableLink to={`\${openmrsSpaBase}/patient/${results[ind]?.patientUuid}/chart/`}>
133148
{cell.value}
134149
</ConfigurableLink>
135150
) : (
@@ -149,10 +164,13 @@ const ActiveVisitsTable = (props) => {
149164
</p>
150165
)}
151166
<Pagination
167+
forwardText=""
168+
backwardText=""
152169
page={currentPage}
153170
pageSize={currentPageSize}
154171
pageSizes={pageSizes}
155-
totalItems={rows.length}
172+
totalItems={searchResults.length}
173+
className={styles.pagination}
156174
onChange={({ pageSize, page }) => {
157175
if (pageSize !== currentPageSize) {
158176
setPageSize(pageSize);
@@ -167,7 +185,7 @@ const ActiveVisitsTable = (props) => {
167185
</DataTable>
168186
</div>
169187
) : (
170-
<DataTableSkeleton className={styles.tableSkeleton} />
188+
<DataTableSkeleton />
171189
);
172190
};
173191

‎packages/esm-active-visits-app/src/active-visits-widget/active-visits.scss

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
.activeVisitsContainer {
44
background-color: $ui-background;
5-
max-width: 48rem;
65
border: 1px solid #e0e0e0;
6+
width: 100%;
7+
margin: 0 auto;
78
}
89

910
.activeVisitsDetailHeaderContainer {
@@ -27,16 +28,15 @@
2728
}
2829

2930
.tableContainer a {
30-
color: inherit;
3131
text-decoration: none;
3232
}
3333

34+
.pagination {
35+
overflow: hidden;
36+
}
37+
3438
.emptyRow {
3539
padding: 0 1rem;
3640
display: flex;
3741
align-items: center;
38-
}
39-
40-
.tableSkeleton {
41-
max-width: 48rem;
4242
}

0 commit comments

Comments
 (0)
Failed to load comments.