Skip to content

Commit 959ac1e

Browse files
committedJul 19, 2021
Misc code refinements
1 parent 8d13686 commit 959ac1e

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed
 

‎packages/esm-patient-list-app/src/PatientTable/patient-table.component.tsx

+61-61
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import styles from './patient-table.component.scss';
1919
const PatientTable: React.FC<PatientTableProps> = ({ patients, columns, search, pagination, isLoading, autoFocus }) => {
2020
const rows: Array<any> = useMemo(
2121
() =>
22-
patients.map((patient) => {
23-
const row = {};
22+
patients.map((patient, index) => {
23+
const row = {
24+
id: index,
25+
};
2426
columns.forEach((column) => {
25-
row['id'] = patient['id'] || patient['uuid'];
2627
const value = column.getValue ? column.getValue(patient) : patient[column.key];
2728
row[column.key] = column.link ? (
2829
<Link
@@ -42,67 +43,66 @@ const PatientTable: React.FC<PatientTableProps> = ({ patients, columns, search,
4243
);
4344
const handleSearch = React.useMemo(() => debounce((searchTerm) => search.onSearch(searchTerm), 300), []);
4445

46+
if (isLoading) {
47+
return (
48+
<DataTableSkeleton
49+
style={{ backgroundColor: 'transparent', padding: '0rem', margin: '1rem' }}
50+
rowCount={5}
51+
columnCount={5}
52+
zebra
53+
/>
54+
);
55+
}
4556
return (
4657
<>
47-
{!isLoading ? (
48-
<>
49-
<div id="table-tool-bar" style={{ display: 'flex', flexDirection: 'row-reverse' }}>
50-
<Search
51-
id="patient-list-search"
52-
labelText=""
53-
placeholder={search.placeHolder}
54-
onChange={(evnt) => handleSearch(evnt.target.value)}
55-
className={styles.searchOverrides}
56-
value={search.currentSearchTerm}
57-
autoFocus={autoFocus}
58-
/>
59-
</div>
60-
<DataTable rows={rows} headers={columns} isSortable={true} size="normal" useZebraStyles={true}>
61-
{({ rows, headers, getHeaderProps, getTableProps }) => (
62-
<TableContainer>
63-
<Table {...getTableProps()}>
64-
<TableHead>
65-
<TableRow>
66-
{headers.map((header) => (
67-
<TableHeader
68-
{...getHeaderProps({
69-
header,
70-
isSortable: header.isSortable,
71-
})}>
72-
{header.header?.content ?? header.header}
73-
</TableHeader>
74-
))}
75-
</TableRow>
76-
</TableHead>
77-
<TableBody>
78-
{rows.map((row) => (
79-
<TableRow key={row.id}>
80-
{row.cells.map((cell) => (
81-
<TableCell key={cell.id}>{cell.value?.content ?? cell.value}</TableCell>
82-
))}
83-
</TableRow>
58+
<div id="table-tool-bar" style={{ display: 'flex', flexDirection: 'row-reverse' }}>
59+
<Search
60+
id="patient-list-search"
61+
labelText=""
62+
placeholder={search.placeHolder}
63+
onChange={(evnt) => handleSearch(evnt.target.value)}
64+
className={styles.searchOverrides}
65+
value={search.currentSearchTerm}
66+
autoFocus={autoFocus}
67+
/>
68+
</div>
69+
<DataTable rows={rows} headers={columns} isSortable={true} size="normal" useZebraStyles={true}>
70+
{({ rows, headers, getHeaderProps, getTableProps }) => (
71+
<TableContainer>
72+
<Table {...getTableProps()}>
73+
<TableHead>
74+
<TableRow>
75+
{headers.map((header) => (
76+
<TableHeader
77+
{...getHeaderProps({
78+
header,
79+
isSortable: header.isSortable,
80+
})}>
81+
{header.header?.content ?? header.header}
82+
</TableHeader>
83+
))}
84+
</TableRow>
85+
</TableHead>
86+
<TableBody>
87+
{rows.map((row) => (
88+
<TableRow key={row.id}>
89+
{row.cells.map((cell) => (
90+
<TableCell key={cell.id}>{cell.value?.content ?? cell.value}</TableCell>
8491
))}
85-
</TableBody>
86-
</Table>
87-
</TableContainer>
88-
)}
89-
</DataTable>
90-
{pagination.usePagination && (
91-
<Pagination
92-
page={pagination.currentPage}
93-
pageSize={pagination.pageSize}
94-
pageSizes={[10, 20, 30, 40, 50]}
95-
totalItems={pagination.totalItems}
96-
onChange={pagination.onChange}
97-
/>
98-
)}
99-
</>
100-
) : (
101-
<DataTableSkeleton
102-
style={{ backgroundColor: 'transparent', padding: '0rem', margin: '1rem' }}
103-
rowCount={5}
104-
columnCount={5}
105-
zebra
92+
</TableRow>
93+
))}
94+
</TableBody>
95+
</Table>
96+
</TableContainer>
97+
)}
98+
</DataTable>
99+
{pagination.usePagination && (
100+
<Pagination
101+
page={pagination.currentPage}
102+
pageSize={pagination.pageSize}
103+
pageSizes={[10, 20, 30, 40, 50]}
104+
totalItems={pagination.totalItems}
105+
onChange={pagination.onChange}
106106
/>
107107
)}
108108
</>

0 commit comments

Comments
 (0)
Failed to load comments.