@@ -19,10 +19,11 @@ import styles from './patient-table.component.scss';
19
19
const PatientTable : React . FC < PatientTableProps > = ( { patients, columns, search, pagination, isLoading, autoFocus } ) => {
20
20
const rows : Array < any > = useMemo (
21
21
( ) =>
22
- patients . map ( ( patient ) => {
23
- const row = { } ;
22
+ patients . map ( ( patient , index ) => {
23
+ const row = {
24
+ id : index ,
25
+ } ;
24
26
columns . forEach ( ( column ) => {
25
- row [ 'id' ] = patient [ 'id' ] || patient [ 'uuid' ] ;
26
27
const value = column . getValue ? column . getValue ( patient ) : patient [ column . key ] ;
27
28
row [ column . key ] = column . link ? (
28
29
< Link
@@ -42,67 +43,66 @@ const PatientTable: React.FC<PatientTableProps> = ({ patients, columns, search,
42
43
) ;
43
44
const handleSearch = React . useMemo ( ( ) => debounce ( ( searchTerm ) => search . onSearch ( searchTerm ) , 300 ) , [ ] ) ;
44
45
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
+ }
45
56
return (
46
57
< >
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 >
84
91
) ) }
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 }
106
106
/>
107
107
) }
108
108
</ >
0 commit comments