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

Minor fixups in active visits widget #21

Merged
merged 4 commits into from
Jul 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useEffect, useState } from 'react';
import React, { useMemo, useEffect, useState, useCallback } from 'react';
import DataTable, {
TableContainer,
Table,
@@ -74,11 +74,24 @@ const ActiveVisitsTable = (props) => {
const pageSizes = config?.activeVisits?.pageSizes ?? [10, 20, 50];
const [loading, setLoading] = useState(true);
const [activeVisits, setActiveVisits] = useState<ActiveVisitRow[]>([]);
const { goTo, currentPage } = usePagination(activeVisits, currentPageSize);
const [lowerBound, upperBound] = useMemo(
() => [(currentPage - 1) * currentPageSize, (currentPage + 0) * currentPageSize],
[currentPage, currentPageSize],
);
const [searchString, setSearchString] = useState('');

const searchResults = useMemo(() => {
if (searchString && searchString.trim() !== '') {
const search = searchString.toLowerCase();
return activeVisits.filter((activeVisitRow) =>
Object.keys(activeVisitRow).some((header) => {
if (header === 'patientUuid') {
return false;
}
return `${activeVisitRow[header]}`.toLowerCase().includes(search);
}),
);
} else {
return activeVisits;
}
}, [searchString, activeVisits]);
const { goTo, currentPage, results } = usePagination(searchResults, currentPageSize);

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

const handleSearch = useCallback((e) => setSearchString(e.target.value), []);

return !loading ? (
<div className={styles.activeVisitsContainer}>
<div className={styles.activeVisitsDetailHeaderContainer}>
<h4 className={styles.productiveHeading02}>{t('activeVisits', 'Active Visits')}</h4>
</div>
<DataTable rows={activeVisits} headers={headerData} isSortable>
{({ rows, headers, getHeaderProps, onInputChange, getTableProps, getBatchActionProps }) => (
<DataTable rows={results} headers={headerData} isSortable>
{({ rows, headers, getHeaderProps, getTableProps, getBatchActionProps }) => (
<TableContainer title="" className={styles.tableContainer}>
<TableToolbar>
<TableToolbarContent>
<Search
tabIndex={getBatchActionProps().shouldShowBatchActions ? -1 : 0}
placeHolderText="Filter table"
onChange={onInputChange}
placeholder="Filter table"
onChange={handleSearch}
/>
</TableToolbarContent>
</TableToolbar>
@@ -124,12 +139,12 @@ const ActiveVisitsTable = (props) => {
</TableRow>
</TableHead>
<TableBody>
{rows.slice(lowerBound, upperBound).map((row) => (
{rows.map((row, ind) => (
<TableRow key={row.id} style={{ height: desktopView ? '2rem' : '3rem' }}>
{row.cells.map((cell, ind) => (
{row.cells.map((cell) => (
<TableCell key={cell.id}>
{cell.info.header === 'name' ? (
<ConfigurableLink to={`\${openmrsSpaBase}/patient/${activeVisits[ind].patientUuid}/chart/`}>
<ConfigurableLink to={`\${openmrsSpaBase}/patient/${results[ind]?.patientUuid}/chart/`}>
{cell.value}
</ConfigurableLink>
) : (
@@ -149,10 +164,13 @@ const ActiveVisitsTable = (props) => {
</p>
)}
<Pagination
forwardText=""
backwardText=""
page={currentPage}
pageSize={currentPageSize}
pageSizes={pageSizes}
totalItems={rows.length}
totalItems={searchResults.length}
className={styles.pagination}
onChange={({ pageSize, page }) => {
if (pageSize !== currentPageSize) {
setPageSize(pageSize);
@@ -167,7 +185,7 @@ const ActiveVisitsTable = (props) => {
</DataTable>
</div>
) : (
<DataTableSkeleton className={styles.tableSkeleton} />
<DataTableSkeleton />
);
};

Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@

.activeVisitsContainer {
background-color: $ui-background;
max-width: 48rem;
border: 1px solid #e0e0e0;
width: 100%;
margin: 0 auto;
}

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

.tableContainer a {
color: inherit;
text-decoration: none;
}

.pagination {
overflow: hidden;
}

.emptyRow {
padding: 0 1rem;
display: flex;
align-items: center;
}

.tableSkeleton {
max-width: 48rem;
}