Skip to content

Commit 6b24abb

Browse files
remotesynthHarshCasper
authored andcommitted
Functional table
It works! Sorting and filtering
1 parent 96cfff5 commit 6b24abb

File tree

1 file changed

+64
-36
lines changed

1 file changed

+64
-36
lines changed

src/components/feature-coverage/FeatureCoverage.tsx

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,65 +20,93 @@ import type { SortingState, ColumnDef, ColumnFiltersState } from "@tanstack/reac
2020

2121
const columns: ColumnDef<any>[] = [
2222
{
23-
accessorKey: "full_name",
24-
header: () => "Service",
25-
cell: ({ row }) => (
26-
<a href={`/aws/${row.original.service}`}>{row.original.full_name}</a>
23+
id: "operation",
24+
accessorFn: (row) => (
25+
Object.keys(row)[0]
2726
),
27+
header: () => "Operation",
2828
enableColumnFilter: true,
2929
filterFn: (row, columnId, filterValue) => {
30-
return row.original.full_name
30+
let operation = Object.keys(row.original)[0];
31+
return operation
3132
.toLowerCase()
3233
.includes((filterValue ?? "").toLowerCase());
3334
},
3435
meta: { className: "w-1/3" },
3536
},
3637
{
37-
accessorKey: "support",
38-
header: () => "Supported",
39-
cell: ({ row }) =>
40-
row.original.support === "supported" ||
41-
row.original.support === "supported with limitations"
42-
? "✔️"
43-
: "",
38+
id: "implemented",
39+
accessorFn: row => row[Object.keys(row)[0]].implemented,
40+
header: () => "Implemented",
41+
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
4442
meta: { className: "w-1/6" },
4543
enableSorting: true,
46-
sortingFn: (rowA, rowB) => {
47-
// Sort supported to the top
48-
const a = rowA.original.support;
49-
const b = rowB.original.support;
50-
if (a === b) return 0;
51-
if (a === "supported") return -1;
52-
if (b === "supported") return 1;
53-
if (a === "supported with limitations") return -1;
54-
if (b === "supported with limitations") return 1;
55-
return a.localeCompare(b);
56-
},
5744
},
5845
{
59-
accessorKey: "test_suite",
60-
header: () => "Persistence Test Suite",
61-
cell: ({ row }) => (row.original.test_suite ? "✔️" : ""),
46+
id: "image",
47+
accessorFn: row => row[Object.keys(row)[0]].availability,
48+
header: () => "Image",
49+
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
6250
meta: { className: "w-1/6" },
63-
enableSorting: true,
51+
enableSorting: false,
52+
},
53+
{
54+
id: "internal_test_suite",
55+
accessorFn: row => row[Object.keys(row)[0]].internal_test_suite,
56+
header: () => "Internal Test Suite",
57+
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
58+
enableSorting: false,
59+
meta: { className: "whitespace-normal" },
60+
},
61+
{
62+
id: "external_test_suite",
63+
accessorFn: row => row[Object.keys(row)[0]].external_test_suite,
64+
header: () => "External Test Suite",
65+
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
66+
enableSorting: false,
67+
meta: { className: "whitespace-normal" },
68+
},
69+
{
70+
id: "terraform_test_suite",
71+
accessorFn: row => row[Object.keys(row)[0]].terraform_test_suite,
72+
header: () => "Terraform Validated",
73+
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
74+
enableSorting: false,
75+
meta: { className: "whitespace-normal" },
6476
},
6577
{
66-
accessorKey: "limitations",
67-
header: () => "Limitations",
68-
cell: ({ row }) => row.original.limitations,
78+
id: "aws_validated",
79+
accessorFn: row => row[Object.keys(row)[0]].aws_validated,
80+
header: () => "AWS Validated",
81+
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
82+
enableSorting: false,
83+
meta: { className: "whitespace-normal" },
84+
},
85+
{
86+
id: "snapshot_tested",
87+
accessorFn: row => row[Object.keys(row)[0]].snapshot_tested,
88+
header: () => "Snapshot Tested",
89+
cell: ({ getValue }) => (getValue() ? "✔️" : ""),
6990
enableSorting: false,
7091
meta: { className: "whitespace-normal" },
7192
},
7293
];
7394

7495
export default function PersistenceCoverage({service}: {service: string}) {
75-
const data = jsonData[`/src/data/coverage/${service}.json`];
76-
const coverage = Object.values(data);
96+
const [coverage, setCoverage] = React.useState<any[]>([]);
7797
const [sorting, setSorting] = React.useState<SortingState>([
78-
{ id: "full_name", desc: false },
98+
{ id: "operation", desc: false },
7999
]);
80100
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([]);
81101

102+
React.useEffect(() => {
103+
const loadData = async () => {
104+
const moduleData = await jsonData[`/src/data/coverage/${service}.json`]() as { default: Record<string, any> };
105+
setCoverage(moduleData.default.operations);
106+
};
107+
loadData();
108+
}, [service]);
109+
82110
const table = useReactTable({
83111
data: coverage,
84112
columns,
@@ -99,12 +127,12 @@ export default function PersistenceCoverage({service}: {service: string}) {
99127
<div style={{ marginBottom: 12, marginTop: 12 }}>
100128
<input
101129
type="text"
102-
placeholder="Filter by service name..."
130+
placeholder="Filter by operation name..."
103131
value={
104-
table.getColumn("full_name")?.getFilterValue() as string || ""
132+
table.getColumn("operation")?.getFilterValue() as string || ""
105133
}
106134
onChange={e =>
107-
table.getColumn("full_name")?.setFilterValue(e.target.value)
135+
table.getColumn("operation")?.setFilterValue(e.target.value)
108136
}
109137
className="border rounded px-2 py-1 w-full max-w-xs"
110138
/>

0 commit comments

Comments
 (0)