@ampath/esm-reports-app 1.0.0-next.55 → 1.0.0-next.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/295.js +1 -1
- package/dist/410.js +1 -1
- package/dist/580.js +1 -0
- package/dist/580.js.map +1 -0
- package/dist/907.js +2 -1
- package/dist/907.js.map +1 -1
- package/dist/998.css +1 -0
- package/dist/998.css.map +1 -0
- package/dist/998.js +1 -0
- package/dist/998.js.map +1 -0
- package/dist/ampath-esm-reports-app.js +1 -1
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/common/daily-summary-table.tsx +55 -0
- package/src/common/linelist-table/index.ts +3 -0
- package/src/common/linelist-table/linelist-columns.ts +48 -0
- package/src/common/linelist-table/linelist-table.component.tsx +442 -0
- package/src/common/linelist-table/linelist-table.scss +306 -0
- package/src/common/linelist-table/linelist-table.test.tsx +120 -0
- package/src/common/linelist-table/use-all-rows.ts +93 -0
- package/src/common/linelist-table/use-column-layout.ts +123 -0
- package/src/common/report-filters/report-filters.component.tsx +11 -5
- package/src/common/report-filters/report-filters.scss +63 -7
- package/src/common/report-page/use-page-scale.ts +27 -17
- package/src/common/report-placeholder/index.ts +1 -0
- package/src/common/report-placeholder/report-placeholder.component.tsx +57 -32
- package/src/common/report-placeholder/report-placeholder.scss +2 -0
- package/src/common/report-placeholder/use-generated-location.ts +62 -0
- package/src/common/report-register/index.ts +1 -0
- package/src/common/report-register/register-layout.component.tsx +26 -4
- package/src/common/report-register/register-layout.scss +10 -0
- package/src/common/report-register/use-location-name.ts +54 -0
- package/src/reports/moh-505/moh-505.component.tsx +9 -3
- package/src/reports/moh-705B/moh-204b-register.component.tsx +11 -2
- package/src/reports/moh-705B/moh-705b.component.tsx +533 -418
- package/src/reports/moh-705B/moh-705b.scss +44 -2
- package/src/reports/moh-705a/moh-705a.component.tsx +533 -421
- package/src/reports/moh-705a/moh-705a.scss +44 -2
- package/src/reports/moh-705a/registers/moh-204a-register.component.tsx +12 -3
- package/src/reports/moh-706/moh-706.component.tsx +9 -3
- package/src/reports/moh-710/moh-710.component.tsx +9 -3
- package/src/reports/moh-711/moh-711.component.tsx +9 -3
- package/src/reports/moh-717/moh-717.component.tsx +12 -3
- package/src/reports/moh-731/linelist/moh-731-indicators.ts +1040 -0
- package/src/reports/moh-731/linelist/moh-731-linelist-sections.ts +423 -0
- package/src/reports/moh-731/linelist/moh-731-linelist.component.tsx +102 -0
- package/src/reports/moh-731/linelist/use-open-moh-731-linelist.ts +50 -0
- package/src/reports/moh-731/moh-731.component.tsx +138 -85
- package/src/reports/moh-731/moh-731.scss +51 -4
- package/src/reports/moh-731/sections/hiv-and-tb-treatment.component.tsx +74 -77
- package/src/reports/moh-731/sections/hiv-testing-and-pre-exposure.component.tsx +84 -70
- package/src/reports/moh-731/sections/pmtct.component.tsx +43 -43
- package/src/reports/moh-731/summary/moh-731-summary.component.tsx +313 -0
- package/src/reports/moh-731/summary/moh-731-summary.config.ts +520 -0
- package/src/reports/moh-731/summary/moh-731-summary.scss +242 -0
- package/src/reports/moh-740/moh-740.component.scss +3 -1
- package/src/reports/moh-740/moh-740.component.tsx +14 -4
- package/src/reports/moh-745/moh-745.component.tsx +7 -3
- package/src/root.component.tsx +2 -0
- package/webpack.config.js +22 -1
- package/dist/427.js +0 -2
- package/dist/427.js.map +0 -1
- package/dist/441.js +0 -1
- package/dist/441.js.map +0 -1
- package/dist/907.css +0 -1
- package/dist/907.css.map +0 -1
- /package/dist/{427.js.LICENSE.txt → 907.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { Button, Checkbox, IconButton, Layer, Pagination, Search, Tag } from '@carbon/react';
|
|
4
|
+
import {
|
|
5
|
+
ArrowDown,
|
|
6
|
+
ArrowUp,
|
|
7
|
+
ArrowsVertical,
|
|
8
|
+
Column,
|
|
9
|
+
Download,
|
|
10
|
+
Draggable,
|
|
11
|
+
Filter,
|
|
12
|
+
FilterRemove,
|
|
13
|
+
Reset,
|
|
14
|
+
} from '@carbon/react/icons';
|
|
15
|
+
|
|
16
|
+
import { columnsToCsv, downloadCsv } from '../report-register';
|
|
17
|
+
import { cellValue, type LinelistColumn, toRegisterColumns } from './linelist-columns';
|
|
18
|
+
import { useColumnLayout } from './use-column-layout';
|
|
19
|
+
import styles from './linelist-table.scss';
|
|
20
|
+
|
|
21
|
+
interface LinelistTableProps {
|
|
22
|
+
rows: Array<Record<string, any>>;
|
|
23
|
+
columns: LinelistColumn[];
|
|
24
|
+
/** Identifies this linelist's saved column layout, e.g. `moh-731:hts` */
|
|
25
|
+
layoutKey: string;
|
|
26
|
+
/** Name of the exported file, without extension */
|
|
27
|
+
exportName: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type SortState = { header: string; direction: 'asc' | 'desc' } | null;
|
|
31
|
+
|
|
32
|
+
const PAGE_SIZES = [25, 50, 100, 250];
|
|
33
|
+
|
|
34
|
+
const asText = (value: unknown) => (value === null || value === undefined ? '' : String(value));
|
|
35
|
+
|
|
36
|
+
/** Blanks sort last in either direction; numbers sort as numbers, everything else naturally */
|
|
37
|
+
function compare(a: unknown, b: unknown): number {
|
|
38
|
+
const blankA = asText(a) === '';
|
|
39
|
+
const blankB = asText(b) === '';
|
|
40
|
+
if (blankA || blankB) {
|
|
41
|
+
return blankA === blankB ? 0 : blankA ? 1 : -1;
|
|
42
|
+
}
|
|
43
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
44
|
+
return a - b;
|
|
45
|
+
}
|
|
46
|
+
return asText(a).localeCompare(asText(b), undefined, { numeric: true, sensitivity: 'base' });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* An analytic table for a linelist: search, per-column filters, sorting, and
|
|
51
|
+
* columns the user can hide and reorder (by dragging a heading or from the
|
|
52
|
+
* Columns menu). The layout is remembered per linelist; the export follows
|
|
53
|
+
* what is on screen -- the visible columns in their order, every filtered and
|
|
54
|
+
* sorted row across all pages.
|
|
55
|
+
*/
|
|
56
|
+
const LinelistTable: React.FC<LinelistTableProps> = ({ rows, columns, layoutKey, exportName }) => {
|
|
57
|
+
const layout = useColumnLayout(columns, layoutKey);
|
|
58
|
+
const { visible } = layout;
|
|
59
|
+
|
|
60
|
+
const [search, setSearch] = useState('');
|
|
61
|
+
const [filters, setFilters] = useState<Record<string, string>>({});
|
|
62
|
+
const [showFilters, setShowFilters] = useState(false);
|
|
63
|
+
const [sort, setSort] = useState<SortState>(null);
|
|
64
|
+
const [page, setPage] = useState(1);
|
|
65
|
+
const [pageSize, setPageSize] = useState(50);
|
|
66
|
+
const [isColumnsOpen, setIsColumnsOpen] = useState(false);
|
|
67
|
+
const [panelPosition, setPanelPosition] = useState({ top: 0, left: 0 });
|
|
68
|
+
const toolbarRef = useRef<HTMLDivElement>(null);
|
|
69
|
+
const columnsButtonRef = useRef<HTMLButtonElement>(null);
|
|
70
|
+
const panelRef = useRef<HTMLDivElement>(null);
|
|
71
|
+
const [dragged, setDragged] = useState<string | null>(null);
|
|
72
|
+
const [dropTarget, setDropTarget] = useState<string | null>(null);
|
|
73
|
+
|
|
74
|
+
/* Only filters on visible columns apply: a hidden column's filter would
|
|
75
|
+
narrow the list with nothing on screen to say why. */
|
|
76
|
+
const activeFilters = visible.filter((column) => (filters[column.header] ?? '').trim() !== '');
|
|
77
|
+
|
|
78
|
+
const filtered = useMemo(() => {
|
|
79
|
+
const query = search.trim().toLowerCase();
|
|
80
|
+
|
|
81
|
+
return rows.filter((row) => {
|
|
82
|
+
const matchesSearch =
|
|
83
|
+
!query || visible.some((column) => asText(cellValue(column, row)).toLowerCase().includes(query));
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
matchesSearch &&
|
|
87
|
+
activeFilters.every((column) =>
|
|
88
|
+
asText(cellValue(column, row)).toLowerCase().includes(filters[column.header].trim().toLowerCase()),
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
}, [rows, visible, search, filters]);
|
|
94
|
+
|
|
95
|
+
const sorted = useMemo(() => {
|
|
96
|
+
const column = sort && visible.find((item) => item.header === sort.header);
|
|
97
|
+
if (!column) {
|
|
98
|
+
return filtered;
|
|
99
|
+
}
|
|
100
|
+
const key = (row: Record<string, any>) => (column.sortValue ? column.sortValue(row) : cellValue(column, row));
|
|
101
|
+
const direction = sort.direction === 'asc' ? 1 : -1;
|
|
102
|
+
return [...filtered].sort((a, b) => {
|
|
103
|
+
const result = compare(key(a), key(b));
|
|
104
|
+
/* blanks stay last whichever way the column is sorted */
|
|
105
|
+
return asText(key(a)) === '' || asText(key(b)) === '' ? result : result * direction;
|
|
106
|
+
});
|
|
107
|
+
}, [filtered, sort, visible]);
|
|
108
|
+
|
|
109
|
+
/* Back to the first page whenever the set of rows changes underneath */
|
|
110
|
+
useEffect(() => setPage(1), [search, filters, sort, rows]);
|
|
111
|
+
|
|
112
|
+
const offset = (page - 1) * pageSize;
|
|
113
|
+
const pageRows = sorted.slice(offset, offset + pageSize);
|
|
114
|
+
|
|
115
|
+
const cycleSort = (header: string) =>
|
|
116
|
+
setSort((current) =>
|
|
117
|
+
current?.header !== header
|
|
118
|
+
? { header, direction: 'asc' }
|
|
119
|
+
: current.direction === 'asc'
|
|
120
|
+
? { header, direction: 'desc' }
|
|
121
|
+
: null,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const clearFilters = () => {
|
|
125
|
+
setFilters({});
|
|
126
|
+
setSearch('');
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const exportCsv = () => {
|
|
130
|
+
const slug = exportName
|
|
131
|
+
.replace(/[^a-z0-9]+/gi, '-')
|
|
132
|
+
.replace(/^-|-$/g, '')
|
|
133
|
+
.toLowerCase();
|
|
134
|
+
downloadCsv(columnsToCsv(sorted, toRegisterColumns(visible)), `${slug}.csv`);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const isFiltered = search.trim() !== '' || activeFilters.length > 0;
|
|
138
|
+
|
|
139
|
+
/* The Columns panel opens under its button but is kept inside the toolbar's
|
|
140
|
+
width. A popover anchored to the button cannot fit on a phone, where the
|
|
141
|
+
button sits mid-screen and a 20rem panel overflows whichever way it opens. */
|
|
142
|
+
const placePanel = useCallback(() => {
|
|
143
|
+
const toolbar = toolbarRef.current?.getBoundingClientRect();
|
|
144
|
+
const button = columnsButtonRef.current?.getBoundingClientRect();
|
|
145
|
+
const panelWidth = panelRef.current?.offsetWidth ?? 0;
|
|
146
|
+
if (!toolbar || !button) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const preferred = button.right - toolbar.left - panelWidth;
|
|
150
|
+
setPanelPosition({
|
|
151
|
+
top: button.bottom - toolbar.top + 4,
|
|
152
|
+
left: Math.max(0, Math.min(preferred, toolbar.width - panelWidth)),
|
|
153
|
+
});
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
useLayoutEffect(() => {
|
|
157
|
+
if (!isColumnsOpen) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
placePanel();
|
|
161
|
+
|
|
162
|
+
const closeOnOutside = (event: PointerEvent) => {
|
|
163
|
+
const target = event.target as Node;
|
|
164
|
+
if (!panelRef.current?.contains(target) && !columnsButtonRef.current?.contains(target)) {
|
|
165
|
+
setIsColumnsOpen(false);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const closeOnEscape = (event: KeyboardEvent) => {
|
|
169
|
+
if (event.key === 'Escape') {
|
|
170
|
+
setIsColumnsOpen(false);
|
|
171
|
+
columnsButtonRef.current?.focus();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
window.addEventListener('resize', placePanel);
|
|
176
|
+
document.addEventListener('pointerdown', closeOnOutside);
|
|
177
|
+
document.addEventListener('keydown', closeOnEscape);
|
|
178
|
+
return () => {
|
|
179
|
+
window.removeEventListener('resize', placePanel);
|
|
180
|
+
document.removeEventListener('pointerdown', closeOnOutside);
|
|
181
|
+
document.removeEventListener('keydown', closeOnEscape);
|
|
182
|
+
};
|
|
183
|
+
}, [isColumnsOpen, placePanel]);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div className={styles.linelist}>
|
|
187
|
+
<div className={styles.toolbar} ref={toolbarRef}>
|
|
188
|
+
<Search
|
|
189
|
+
size="sm"
|
|
190
|
+
labelText="Search the linelist"
|
|
191
|
+
placeholder="Search all columns"
|
|
192
|
+
value={search}
|
|
193
|
+
onChange={(event) => setSearch(event.target.value)}
|
|
194
|
+
className={styles.search}
|
|
195
|
+
/>
|
|
196
|
+
<Button
|
|
197
|
+
kind={showFilters ? 'secondary' : 'ghost'}
|
|
198
|
+
size="sm"
|
|
199
|
+
renderIcon={Filter}
|
|
200
|
+
onClick={() => setShowFilters((current) => !current)}
|
|
201
|
+
aria-pressed={showFilters}
|
|
202
|
+
>
|
|
203
|
+
Filters{activeFilters.length > 0 ? ` (${activeFilters.length})` : ''}
|
|
204
|
+
</Button>
|
|
205
|
+
{isFiltered && (
|
|
206
|
+
<Button kind="ghost" size="sm" renderIcon={FilterRemove} onClick={clearFilters}>
|
|
207
|
+
Clear
|
|
208
|
+
</Button>
|
|
209
|
+
)}
|
|
210
|
+
|
|
211
|
+
<Button
|
|
212
|
+
ref={columnsButtonRef}
|
|
213
|
+
kind={isColumnsOpen ? 'secondary' : 'ghost'}
|
|
214
|
+
size="sm"
|
|
215
|
+
renderIcon={Column}
|
|
216
|
+
onClick={() => setIsColumnsOpen((current) => !current)}
|
|
217
|
+
aria-expanded={isColumnsOpen}
|
|
218
|
+
aria-controls={`${layoutKey}-columns`}
|
|
219
|
+
>
|
|
220
|
+
Columns ({visible.length}/{layout.ordered.length})
|
|
221
|
+
</Button>
|
|
222
|
+
{isColumnsOpen && (
|
|
223
|
+
<Layer
|
|
224
|
+
ref={panelRef}
|
|
225
|
+
id={`${layoutKey}-columns`}
|
|
226
|
+
role="dialog"
|
|
227
|
+
aria-label="Columns"
|
|
228
|
+
className={styles.columnsPanel}
|
|
229
|
+
style={panelPosition}
|
|
230
|
+
>
|
|
231
|
+
<p className={styles.columnsHint}>Show, hide or reorder columns. You can also drag a heading.</p>
|
|
232
|
+
<ul className={styles.columnsList}>
|
|
233
|
+
{layout.ordered.map((column, index) => (
|
|
234
|
+
<li key={column.header} className={styles.columnsItem}>
|
|
235
|
+
<Draggable size={16} className={styles.dragHandle} aria-hidden />
|
|
236
|
+
<Checkbox
|
|
237
|
+
id={`${layoutKey}-column-${index}`}
|
|
238
|
+
labelText={column.header}
|
|
239
|
+
checked={layout.isVisible(column.header)}
|
|
240
|
+
onChange={() => layout.toggle(column.header)}
|
|
241
|
+
/>
|
|
242
|
+
<span className={styles.columnsMove}>
|
|
243
|
+
<IconButton
|
|
244
|
+
kind="ghost"
|
|
245
|
+
size="sm"
|
|
246
|
+
label="Move left"
|
|
247
|
+
disabled={index === 0}
|
|
248
|
+
onClick={() => layout.shift(column.header, -1)}
|
|
249
|
+
>
|
|
250
|
+
<ArrowUp size={16} />
|
|
251
|
+
</IconButton>
|
|
252
|
+
<IconButton
|
|
253
|
+
kind="ghost"
|
|
254
|
+
size="sm"
|
|
255
|
+
label="Move right"
|
|
256
|
+
disabled={index === layout.ordered.length - 1}
|
|
257
|
+
onClick={() => layout.shift(column.header, 1)}
|
|
258
|
+
>
|
|
259
|
+
<ArrowDown size={16} />
|
|
260
|
+
</IconButton>
|
|
261
|
+
</span>
|
|
262
|
+
</li>
|
|
263
|
+
))}
|
|
264
|
+
</ul>
|
|
265
|
+
<Button
|
|
266
|
+
kind="ghost"
|
|
267
|
+
size="sm"
|
|
268
|
+
renderIcon={Reset}
|
|
269
|
+
onClick={layout.reset}
|
|
270
|
+
disabled={!layout.isCustomised}
|
|
271
|
+
className={styles.columnsReset}
|
|
272
|
+
>
|
|
273
|
+
Reset columns
|
|
274
|
+
</Button>
|
|
275
|
+
</Layer>
|
|
276
|
+
)}
|
|
277
|
+
|
|
278
|
+
<span className={styles.count}>
|
|
279
|
+
{isFiltered
|
|
280
|
+
? `${sorted.length.toLocaleString()} of ${rows.length.toLocaleString()} records`
|
|
281
|
+
: `${rows.length.toLocaleString()} records`}
|
|
282
|
+
</span>
|
|
283
|
+
<Button
|
|
284
|
+
kind="tertiary"
|
|
285
|
+
size="sm"
|
|
286
|
+
renderIcon={Download}
|
|
287
|
+
onClick={exportCsv}
|
|
288
|
+
disabled={sorted.length === 0 || visible.length === 0}
|
|
289
|
+
>
|
|
290
|
+
Export CSV
|
|
291
|
+
</Button>
|
|
292
|
+
</div>
|
|
293
|
+
|
|
294
|
+
{activeFilters.length > 0 && !showFilters && (
|
|
295
|
+
<div className={styles.activeFilters}>
|
|
296
|
+
{activeFilters.map((column) => (
|
|
297
|
+
<Tag
|
|
298
|
+
key={column.header}
|
|
299
|
+
type="blue"
|
|
300
|
+
size="sm"
|
|
301
|
+
filter
|
|
302
|
+
onClose={() => setFilters(({ [column.header]: _removed, ...rest }) => rest)}
|
|
303
|
+
>
|
|
304
|
+
{column.header}: {filters[column.header]}
|
|
305
|
+
</Tag>
|
|
306
|
+
))}
|
|
307
|
+
</div>
|
|
308
|
+
)}
|
|
309
|
+
|
|
310
|
+
<div className={styles.scroll}>
|
|
311
|
+
<table className={styles.table}>
|
|
312
|
+
<thead>
|
|
313
|
+
<tr>
|
|
314
|
+
<th className={styles.rowNumber} scope="col">
|
|
315
|
+
#
|
|
316
|
+
</th>
|
|
317
|
+
{visible.map((column) => {
|
|
318
|
+
const direction = sort?.header === column.header ? sort.direction : null;
|
|
319
|
+
return (
|
|
320
|
+
<th
|
|
321
|
+
key={column.header}
|
|
322
|
+
scope="col"
|
|
323
|
+
draggable
|
|
324
|
+
aria-sort={direction === 'asc' ? 'ascending' : direction === 'desc' ? 'descending' : 'none'}
|
|
325
|
+
className={classNames({
|
|
326
|
+
[styles.dragging]: dragged === column.header,
|
|
327
|
+
[styles.dropTarget]: dropTarget === column.header && dragged !== column.header,
|
|
328
|
+
})}
|
|
329
|
+
onDragStart={(event) => {
|
|
330
|
+
setDragged(column.header);
|
|
331
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
332
|
+
}}
|
|
333
|
+
onDragOver={(event) => {
|
|
334
|
+
if (dragged) {
|
|
335
|
+
event.preventDefault();
|
|
336
|
+
setDropTarget(column.header);
|
|
337
|
+
}
|
|
338
|
+
}}
|
|
339
|
+
onDragLeave={() => setDropTarget((current) => (current === column.header ? null : current))}
|
|
340
|
+
onDrop={(event) => {
|
|
341
|
+
event.preventDefault();
|
|
342
|
+
if (dragged) {
|
|
343
|
+
layout.move(dragged, column.header);
|
|
344
|
+
}
|
|
345
|
+
setDragged(null);
|
|
346
|
+
setDropTarget(null);
|
|
347
|
+
}}
|
|
348
|
+
onDragEnd={() => {
|
|
349
|
+
setDragged(null);
|
|
350
|
+
setDropTarget(null);
|
|
351
|
+
}}
|
|
352
|
+
>
|
|
353
|
+
<button
|
|
354
|
+
type="button"
|
|
355
|
+
className={styles.sortButton}
|
|
356
|
+
onClick={() => cycleSort(column.header)}
|
|
357
|
+
title="Sort, or drag to move the column"
|
|
358
|
+
>
|
|
359
|
+
<span>{column.header}</span>
|
|
360
|
+
{direction === 'asc' ? (
|
|
361
|
+
<ArrowUp size={14} className={styles.sortActive} />
|
|
362
|
+
) : direction === 'desc' ? (
|
|
363
|
+
<ArrowDown size={14} className={styles.sortActive} />
|
|
364
|
+
) : (
|
|
365
|
+
<ArrowsVertical size={14} className={styles.sortIdle} />
|
|
366
|
+
)}
|
|
367
|
+
</button>
|
|
368
|
+
</th>
|
|
369
|
+
);
|
|
370
|
+
})}
|
|
371
|
+
</tr>
|
|
372
|
+
{showFilters && (
|
|
373
|
+
<tr className={styles.filterRow}>
|
|
374
|
+
<th className={styles.rowNumber} />
|
|
375
|
+
{visible.map((column) => (
|
|
376
|
+
<th key={column.header}>
|
|
377
|
+
<input
|
|
378
|
+
type="search"
|
|
379
|
+
className={styles.filterInput}
|
|
380
|
+
placeholder="Filter"
|
|
381
|
+
aria-label={`Filter ${column.header}`}
|
|
382
|
+
value={filters[column.header] ?? ''}
|
|
383
|
+
onChange={(event) =>
|
|
384
|
+
setFilters((current) => ({ ...current, [column.header]: event.target.value }))
|
|
385
|
+
}
|
|
386
|
+
/>
|
|
387
|
+
</th>
|
|
388
|
+
))}
|
|
389
|
+
</tr>
|
|
390
|
+
)}
|
|
391
|
+
</thead>
|
|
392
|
+
<tbody>
|
|
393
|
+
{pageRows.map((row, index) => (
|
|
394
|
+
<tr key={offset + index}>
|
|
395
|
+
<td className={styles.rowNumber}>{offset + index + 1}</td>
|
|
396
|
+
{visible.map((column) => {
|
|
397
|
+
const text = asText(cellValue(column, row));
|
|
398
|
+
return (
|
|
399
|
+
<td key={column.header} className={column.wrap ? styles.wrap : undefined} title={text}>
|
|
400
|
+
{text}
|
|
401
|
+
</td>
|
|
402
|
+
);
|
|
403
|
+
})}
|
|
404
|
+
</tr>
|
|
405
|
+
))}
|
|
406
|
+
{pageRows.length === 0 && (
|
|
407
|
+
<tr>
|
|
408
|
+
<td className={styles.noMatches} colSpan={visible.length + 1}>
|
|
409
|
+
{visible.length === 0 ? 'Every column is hidden.' : 'No records match the search and filters.'}{' '}
|
|
410
|
+
<button
|
|
411
|
+
type="button"
|
|
412
|
+
className={styles.linkButton}
|
|
413
|
+
onClick={visible.length === 0 ? layout.reset : clearFilters}
|
|
414
|
+
>
|
|
415
|
+
{visible.length === 0 ? 'Reset columns' : 'Clear filters'}
|
|
416
|
+
</button>
|
|
417
|
+
</td>
|
|
418
|
+
</tr>
|
|
419
|
+
)}
|
|
420
|
+
</tbody>
|
|
421
|
+
</table>
|
|
422
|
+
</div>
|
|
423
|
+
|
|
424
|
+
{sorted.length > PAGE_SIZES[0] && (
|
|
425
|
+
<Pagination
|
|
426
|
+
className={styles.pagination}
|
|
427
|
+
page={page}
|
|
428
|
+
pageSize={pageSize}
|
|
429
|
+
pageSizes={PAGE_SIZES}
|
|
430
|
+
totalItems={sorted.length}
|
|
431
|
+
size="sm"
|
|
432
|
+
onChange={({ page: nextPage, pageSize: nextSize }) => {
|
|
433
|
+
setPage(nextPage);
|
|
434
|
+
setPageSize(nextSize);
|
|
435
|
+
}}
|
|
436
|
+
/>
|
|
437
|
+
)}
|
|
438
|
+
</div>
|
|
439
|
+
);
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export default LinelistTable;
|