@ampath/esm-reports-app 1.0.0-next.7 → 1.0.0-next.71
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/197.js +1 -1
- package/dist/282.js +1 -1
- package/dist/282.js.map +1 -1
- package/dist/295.css +1 -0
- package/dist/295.css.map +1 -0
- package/dist/295.js +1 -0
- package/dist/295.js.map +1 -0
- package/dist/299.js +2 -0
- package/dist/299.js.LICENSE.txt +3 -0
- package/dist/299.js.map +1 -0
- package/dist/300.js +1 -1
- package/dist/311.js +1 -1
- package/dist/311.js.map +1 -1
- package/dist/335.js +1 -1
- package/dist/353.js +1 -1
- package/dist/353.js.map +1 -1
- package/dist/354.js +2 -0
- package/dist/354.js.LICENSE.txt +20 -0
- package/dist/354.js.map +1 -0
- package/dist/410.js +1 -0
- package/dist/410.js.map +1 -0
- package/dist/457.js +2 -0
- package/dist/457.js.LICENSE.txt +261 -0
- package/dist/457.js.map +1 -0
- package/dist/478.js +1 -1
- package/dist/478.js.map +1 -1
- package/dist/480.js +1 -0
- package/dist/540.js +1 -1
- package/dist/540.js.map +1 -1
- package/dist/55.js +1 -1
- package/dist/580.js +1 -0
- package/dist/580.js.map +1 -0
- package/dist/600.js +2 -0
- package/dist/600.js.LICENSE.txt +35 -0
- package/dist/600.js.map +1 -0
- package/dist/652.js +1 -1
- package/dist/781.js +1 -0
- package/dist/781.js.map +1 -0
- package/dist/919.css +1 -0
- package/dist/919.css.map +1 -0
- package/dist/919.js +1 -0
- package/dist/919.js.map +1 -0
- package/dist/961.js +1 -1
- package/dist/961.js.map +1 -1
- package/dist/99.js +1 -1
- package/dist/99.js.map +1 -0
- package/dist/ampath-esm-reports-app.js +1 -1
- package/dist/ampath-esm-reports-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +4 -2
- 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-error/index.ts +1 -0
- package/src/common/report-error/show-report-error.ts +25 -0
- package/src/common/report-filters/date-range.ts +137 -0
- package/src/common/report-filters/index.ts +4 -0
- package/src/common/report-filters/report-filters.component.tsx +317 -99
- package/src/common/report-filters/report-filters.scss +255 -32
- package/src/common/report-filters/types.ts +79 -0
- package/src/common/report-filters/use-restore-period.ts +43 -0
- package/src/common/report-header/index.ts +1 -0
- package/src/common/report-header/use-location-details.ts +58 -0
- package/src/common/report-page/download-sheet-pdf.ts +59 -0
- package/src/common/report-page/index.ts +3 -0
- package/src/common/report-page/report-page.component.tsx +32 -0
- package/src/common/report-page/report-page.scss +45 -0
- package/src/common/report-page/use-page-scale.ts +60 -0
- package/src/common/report-placeholder/has-report-data.ts +15 -0
- package/src/common/report-placeholder/index.ts +3 -0
- package/src/common/report-placeholder/report-placeholder.component.tsx +81 -0
- package/src/common/report-placeholder/report-placeholder.scss +48 -0
- package/src/common/report-placeholder/use-generated-location.ts +62 -0
- package/src/common/report-register/index.ts +6 -0
- package/src/common/report-register/register-columns.ts +46 -0
- package/src/common/report-register/register-layout.component.tsx +265 -0
- package/src/common/report-register/register-layout.scss +150 -0
- package/src/common/report-register/register-table.scss +71 -0
- package/src/common/report-register/report-parents.ts +27 -0
- package/src/common/report-register/rows-to-csv.ts +89 -0
- package/src/common/report-register/use-location-name.ts +54 -0
- package/src/common/report-register/use-patient-list.ts +92 -0
- package/src/common/report-skeleton/index.ts +1 -0
- package/src/common/report-skeleton/report-skeleton.component.tsx +46 -0
- package/src/common/report-skeleton/report-skeleton.scss +29 -0
- package/src/config-schema.ts +9 -1
- package/src/dashboard/report-catalog.ts +173 -0
- package/src/dashboard/reports-dasboard.tsx +189 -18
- package/src/dashboard/reports-dashboard.module.scss +357 -14
- package/src/index.ts +13 -1
- package/src/registers/moh-240/moh-240-register.scss +41 -0
- package/src/registers/moh-240/moh-240.component.test.tsx +166 -0
- package/src/registers/moh-240/moh-240.component.tsx +164 -0
- package/src/registers/moh-362/moh-362-lab-register.component.tsx +392 -0
- package/src/registers/moh-362/moh-362-linkage-register.component.tsx +120 -0
- package/src/registers/moh-362/moh-362-register.scss +222 -0
- package/src/registers/moh-362/moh-362.component.tsx +99 -0
- package/src/registers/moh-362/moh-362.scss +11 -0
- package/src/registers/moh-362/moh-362.types.ts +97 -0
- package/src/registers/register-catalog.ts +96 -0
- package/src/registers/tb-lab-register/tb-lab-register-table.component.tsx +116 -0
- package/src/registers/tb-lab-register/tb-lab-register-table.scss +123 -0
- package/src/registers/tb-lab-register/tb-lab-register.columns.ts +164 -0
- package/src/registers/tb-lab-register/tb-lab-register.component.test.tsx +232 -0
- package/src/registers/tb-lab-register/tb-lab-register.component.tsx +153 -0
- package/src/reports/datatable-wrapper/datatable-wrapper.component.tsx +63 -48
- package/src/reports/moh-240/moh-240-header.component.tsx +62 -0
- package/src/reports/moh-240/moh-240.columns.ts +113 -0
- package/src/reports/moh-240/moh-240.component.tsx +72 -9
- package/src/reports/moh-240/moh-240.scss +40 -0
- package/src/reports/moh-240/sub-reports/moh-240-register.component.tsx +31 -37
- package/src/reports/moh-240/sub-reports/page-summary.component.tsx +143 -106
- package/src/reports/moh-505/moh-505-header.component.tsx +67 -0
- package/src/reports/moh-505/moh-505.component.tsx +441 -0
- package/src/reports/moh-505/moh-505.scss +117 -0
- package/src/reports/moh-705B/moh-204b-register.component.tsx +244 -0
- package/src/reports/moh-705B/moh-204b.columns.ts +39 -0
- package/src/reports/moh-705B/moh-705b.component.tsx +659 -0
- package/src/reports/moh-705B/moh-705b.scss +172 -0
- package/src/reports/moh-705a/moh-705a.component.tsx +661 -0
- package/src/reports/moh-705a/moh-705a.scss +172 -0
- package/src/reports/moh-705a/registers/moh-204a-register.component.tsx +329 -0
- package/src/reports/moh-705a/registers/moh-204a.columns.ts +57 -0
- package/src/reports/moh-705a/type.ts +6 -0
- package/src/reports/moh-706/moh-706-header.component.tsx +66 -0
- package/src/reports/moh-706/moh-706.component.tsx +150 -24
- package/src/reports/moh-706/moh-706.scss +119 -11
- package/src/reports/moh-706/sub-reports/bacteriology/bacteriology.component.tsx +54 -62
- package/src/reports/moh-706/sub-reports/blood-chemistry/blood-chemistry.component.tsx +228 -317
- package/src/reports/moh-706/sub-reports/drug-susceptibility-testing/drug-susceptibility-testing.component.tsx +31 -46
- package/src/reports/moh-706/sub-reports/haematology/haematology.component.tsx +47 -55
- package/src/reports/moh-706/sub-reports/histology-and-cytology/histology-and-cytology.component.tsx +43 -58
- package/src/reports/moh-706/sub-reports/parasitology/parasitology.component.tsx +31 -39
- package/src/reports/moh-706/sub-reports/serology/serology.component.tsx +26 -34
- package/src/reports/moh-706/sub-reports/specimen-referral-to-higher-levels/specimen-referral-to-higher-levels.component.tsx +9 -24
- package/src/reports/moh-706/sub-reports/urine-analysis/urine-analysis.component.tsx +43 -51
- package/src/reports/moh-710/moh-710.component.tsx +799 -632
- package/src/reports/moh-710/moh-710.scss +142 -21
- package/src/reports/moh-710/registers/moh-510/moh-510.columns.ts +40 -0
- package/src/reports/moh-710/registers/moh-510/moh-510.component.tsx +144 -0
- package/src/reports/moh-710/registers/moh-510/moh-510.scss +130 -0
- package/src/reports/moh-710/registers/moh-511-710-register.component.tsx +268 -0
- package/src/reports/moh-710/registers/moh-511-710.columns.ts +52 -0
- package/src/reports/moh-710/registers/type.ts +31 -0
- package/src/reports/moh-711/moh-711.component.tsx +138 -1269
- package/src/reports/moh-711/moh711.scss +135 -20
- package/src/reports/moh-711/registers/moh-333-register.component.tsx +637 -0
- package/src/reports/moh-711/registers/moh-333.columns.ts +119 -0
- package/src/reports/moh-711/registers/moh-405-register.component.tsx +520 -0
- package/src/reports/moh-711/registers/moh-405.columns.ts +120 -0
- package/src/reports/moh-711/registers/moh-406-register.component.tsx +530 -0
- package/src/reports/moh-711/registers/moh-406.columns.ts +133 -0
- package/src/reports/moh-711/registers/moh-510-register.component.tsx +55 -0
- package/src/reports/moh-711/registers/moh-511-register.component.tsx +270 -0
- package/src/reports/moh-711/registers/moh-511.columns.ts +59 -0
- package/src/reports/moh-711/registers/type.ts +192 -0
- package/src/reports/moh-711/sections/anc.component.tsx +159 -0
- package/src/reports/moh-711/sections/cervical-cancer.component.tsx +148 -0
- package/src/reports/moh-711/sections/chanis.component.tsx +366 -0
- package/src/reports/moh-711/sections/family-planning.component.tsx +221 -0
- package/src/reports/moh-711/sections/gbv.component.tsx +115 -0
- package/src/reports/moh-711/sections/maternity.component.tsx +321 -0
- package/src/reports/moh-711/sections/medical-social-work.component.tsx +73 -0
- package/src/reports/moh-711/sections/other.component.tsx +47 -0
- package/src/reports/moh-711/sections/physiotherapy.component.tsx +61 -0
- package/src/reports/moh-711/sections/pnc.component.tsx +127 -0
- package/src/reports/moh-711/sections/post-abortion.component.tsx +42 -0
- package/src/reports/moh-711/sections/rehabilitation.component.tsx +57 -0
- package/src/reports/moh-711/sections/report-compiled-by.component.tsx +50 -0
- package/src/reports/moh-711/sections/tb-screening.component.tsx +57 -0
- package/src/reports/moh-717/moh-717.component.tsx +149 -985
- package/src/reports/moh-717/moh717.scss +217 -21
- package/src/reports/moh-717/registers/nutrition-register.component.tsx +48 -0
- package/src/reports/moh-717/sections/finance.component.tsx +42 -0
- package/src/reports/moh-717/sections/inpatient.component.tsx +374 -0
- package/src/reports/moh-717/sections/maternity.component.tsx +126 -0
- package/src/reports/moh-717/sections/medical-records.component.tsx +35 -0
- package/src/reports/moh-717/sections/mortuary.component.tsx +43 -0
- package/src/reports/moh-717/sections/operations.component.tsx +53 -0
- package/src/reports/moh-717/sections/orthopaedic-trauma.component.tsx +98 -0
- package/src/reports/moh-717/sections/outpatient.component.tsx +597 -0
- package/src/reports/moh-717/sections/pharmacy.component.tsx +43 -0
- package/src/reports/moh-717/sections/preparedby.component.tsx +52 -0
- package/src/reports/moh-717/sections/special-services.component.tsx +114 -0
- package/src/reports/moh-731/linelist/moh-731-indicators.ts +1122 -0
- package/src/reports/moh-731/linelist/moh-731-linelist-sections.ts +472 -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 +266 -0
- package/src/reports/moh-731/moh-731.scss +499 -0
- package/src/reports/moh-731/registers/moh-366.columns.ts +38 -0
- package/src/reports/moh-731/registers/moh-366.component.tsx +471 -0
- package/src/reports/moh-731/registers/prep-register.component.tsx +284 -0
- package/src/reports/moh-731/registers/prep.columns.ts +34 -0
- package/src/reports/moh-731/sections/hiv-and-tb-treatment.component.tsx +1206 -0
- package/src/reports/moh-731/sections/hiv-testing-and-pre-exposure.component.tsx +727 -0
- package/src/reports/moh-731/sections/pmtct.component.tsx +572 -0
- package/src/reports/moh-731/summary/moh-731-summary.component.tsx +313 -0
- package/src/reports/moh-731/summary/moh-731-summary.config.ts +529 -0
- package/src/reports/moh-731/summary/moh-731-summary.scss +242 -0
- package/src/reports/moh-740/moh-740.component.scss +202 -0
- package/src/reports/moh-740/moh-740.component.tsx +1332 -0
- package/src/reports/moh-740/moh-740.resource.ts +54 -0
- package/src/reports/moh-740/registers/moh-222-daily-register/moh-222-daily-register.tsx +149 -0
- package/src/reports/moh-740/registers/moh-270-permanent-register/moh-270-permanent-register.tsx +123 -0
- package/src/reports/moh-740/registers/moh-740-patient-list.scss +0 -0
- package/src/reports/moh-740/registers/moh-740-patient-list.tsx +60 -0
- package/src/reports/moh-740/registers/moh-740.columns.ts +54 -0
- package/src/reports/moh-740/shared/data-cell/data-cell.scss +6 -0
- package/src/reports/moh-740/shared/data-cell/data-cell.tsx +23 -0
- package/src/reports/moh-740/shared/utils/indicator-register-map.ts +159 -0
- package/src/reports/moh-740/types/index.ts +223 -0
- package/src/reports/moh-745/moh-745.component.tsx +1021 -0
- package/src/reports/moh-745/moh-745.scss +132 -0
- package/src/reports/moh-745/registers/moh-412-register.component.tsx +249 -0
- package/src/reports/moh-745/registers/moh-412.columns.ts +52 -0
- package/src/reports/moh-745/registers/type.ts +181 -0
- package/src/reports/table-wrapper/table-row-mapper.component.tsx +57 -0
- package/src/reports/table-wrapper/table-wrapper.component.tsx +23 -14
- package/src/reports/table-wrapper/table-wrapper.scss +1 -16
- package/src/resources/moh-362.resource.ts +27 -0
- package/src/resources/moh-505.resource.ts +69 -0
- package/src/resources/moh-705.resource.ts +106 -0
- package/src/resources/moh-706.resource.ts +80 -0
- package/src/resources/moh-710.resource.ts +32 -9
- package/src/resources/moh-711.resource.ts +137 -9
- package/src/resources/moh-717.resource.ts +26 -9
- package/src/resources/moh-731.resource.ts +90 -0
- package/src/resources/moh-745.resource.ts +76 -0
- package/src/resources/patient-list-page.ts +65 -0
- package/src/root.component.tsx +59 -8
- package/src/root.scss +36 -0
- package/src/routes.json +3 -1
- package/src/utils/format-indicator.ts +39 -0
- package/src/utils/get-base-url.ts +39 -7
- package/src/utils/utils.ts +36 -0
- package/tsconfig.json +1 -1
- package/webpack.config.js +22 -1
- package/dist/138.js +0 -2
- package/dist/138.js.LICENSE.txt +0 -20
- package/dist/138.js.map +0 -1
- package/dist/184.js +0 -2
- package/dist/184.js.LICENSE.txt +0 -14
- package/dist/184.js.map +0 -1
- package/dist/205.js +0 -1
- package/dist/205.js.map +0 -1
- package/dist/711.js +0 -1
- package/dist/711.js.map +0 -1
- package/dist/812.js +0 -1
- package/dist/812.js.map +0 -1
- package/dist/ampath-esm-reports-app.js.buildmanifest.json +0 -539
- package/dist/main.js +0 -1
- package/dist/main.js.map +0 -1
|
@@ -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, 500, 1000];
|
|
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;
|