-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathFeatureCoverage.tsx
More file actions
171 lines (166 loc) · 5.45 KB
/
FeatureCoverage.tsx
File metadata and controls
171 lines (166 loc) · 5.45 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
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, columnId, filterValue) => {
let operation = Object.keys(row.original)[0];
return operation
.toLowerCase()
.includes((filterValue ?? "").toLowerCase());
},
meta: { className: "w-1/3" },
},
{
id: "implemented",
accessorFn: row => row[Object.keys(row)[0]].implemented,
header: () => "Implemented",
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
meta: { className: "w-1/6" },
enableSorting: true,
},
{
id: "image",
accessorFn: row => row[Object.keys(row)[0]].availability,
header: () => "Image",
meta: { className: "w-1/6" },
enableSorting: 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">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
const canSort = header.column.getCanSort();
const meta = header.column.columnDef.meta as { className?: string } | undefined;
return (
<TableHead
key={header.id}
onClick={canSort ? header.column.getToggleSortingHandler() : undefined}
className={
(meta?.className || "") +
(canSort ? " cursor-pointer select-none" : "")
}
>
{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) => {
const meta = cell.column.columnDef.meta as { className?: string } | undefined;
return (
<TableCell
key={cell.id}
className={meta?.className || undefined}
>
{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>
);
}