-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathFeatureCoverage.tsx
More file actions
229 lines (221 loc) · 7.07 KB
/
FeatureCoverage.tsx
File metadata and controls
229 lines (221 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import React from 'react';
const jsonData = import.meta.glob('/src/data/coverage/*.json');
import {
Table,
TableHeader,
TableBody,
TableRow,
TableHead,
TableCell,
} from '@/components/ui/table';
import {
useReactTable,
getCoreRowModel,
getSortedRowModel,
flexRender,
getFilteredRowModel,
getPaginationRowModel,
} from '@tanstack/react-table';
import type {
SortingState,
ColumnDef,
ColumnFiltersState,
} from '@tanstack/react-table';
const columns: ColumnDef<any>[] = [
{
id: 'operation',
accessorFn: (row) => Object.keys(row)[0],
header: () => 'Operation',
enableColumnFilter: true,
filterFn: (row, _, filterValue) => {
let operation = Object.keys(row.original)[0];
return operation
.toLowerCase()
.includes((filterValue ?? '').toLowerCase());
},
enableResizing: false,
},
{
id: 'implemented',
accessorFn: (row) => row[Object.keys(row)[0]].implemented,
header: () => 'Implemented',
cell: ({ getValue }) => (getValue() ? '✔️' : ''),
enableSorting: true,
enableResizing: false,
},
{
id: 'image',
accessorFn: (row) => row[Object.keys(row)[0]].availability,
header: () => 'Image',
enableSorting: false,
enableResizing: false,
},
];
export default function PersistenceCoverage({ service }: { service: string }) {
const [coverage, setCoverage] = React.useState<any[]>([]);
const [sorting, setSorting] = React.useState<SortingState>([
{ id: 'operation', desc: false },
]);
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
[]
);
React.useEffect(() => {
const loadData = async () => {
const moduleData = (await jsonData[
`/src/data/coverage/${service}.json`
]()) as { default: Record<string, any> };
setCoverage(moduleData.default.operations);
};
loadData();
}, [service]);
const table = useReactTable({
data: coverage,
columns,
state: {
sorting,
columnFilters,
},
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getPaginationRowModel: getPaginationRowModel(),
debugTable: false,
initialState: { pagination: { pageSize: 10 } },
});
return (
<div className="w-full">
<div style={{ marginBottom: 12, marginTop: 12 }}>
<input
type="text"
placeholder="Filter by operation name..."
value={
(table.getColumn('operation')?.getFilterValue() as string) || ''
}
onChange={(e) =>
table.getColumn('operation')?.setFilterValue(e.target.value)
}
className="border rounded px-2 py-1 w-full max-w-xs"
/>
</div>
<div className="rounded-md border w-full overflow-hidden">
<Table
className="w-full"
style={{
width: '100%',
tableLayout: 'fixed',
}}
>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
const canSort = header.column.getCanSort();
// Calculate percentage-based widths: Operation 60%, others 20% each
const getColumnWidth = (columnId: string) => {
switch (columnId) {
case 'operation':
return '75%';
case 'implemented':
case 'image':
return '15%';
default:
return 'auto';
}
};
return (
<TableHead
key={header.id}
onClick={
canSort
? header.column.getToggleSortingHandler()
: undefined
}
className={canSort ? 'cursor-pointer select-none' : ''}
style={{
width: getColumnWidth(header.id),
textAlign: header.id === 'operation' ? 'left' : 'center',
}}
>
{flexRender(
header.column.columnDef.header,
header.getContext()
)}
{canSort && (
<span>
{header.column.getIsSorted() === 'asc'
? ' ▲'
: header.column.getIsSorted() === 'desc'
? ' ▼'
: ''}
</span>
)}
</TableHead>
);
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => {
// Same width calculation for cells
const getColumnWidth = (columnId: string) => {
switch (columnId) {
case 'operation':
return '60%';
case 'implemented':
case 'image':
return '20%';
default:
return 'auto';
}
};
return (
<TableCell
key={cell.id}
style={{
width: getColumnWidth(cell.column.id),
textAlign: cell.column.id === 'operation' ? 'left' : 'center',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: cell.column.id === 'operation' ? 'normal' : 'nowrap',
}}
>
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</TableCell>
);
})}
</TableRow>
))}
</TableBody>
</Table>
</div>
<div className="flex items-center justify-between mt-4">
<button
className="px-3 py-1 border rounded disabled:opacity-50"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
Previous
</button>
<span>
Page {table.getState().pagination.pageIndex + 1} of{' '}
{table.getPageCount()}
</span>
<button
className="px-3 py-1 border rounded disabled:opacity-50"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
Next
</button>
</div>
</div>
);
}