Skip to content

Commit 92a66ba

Browse files
authored
Merge pull request #176 from trycompai/COM-20-Updated-Table
Com 20 updated table
2 parents eb9df88 + 3a95960 commit 92a66ba

File tree

29 files changed

+1240
-727
lines changed

29 files changed

+1240
-727
lines changed

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/tests/all/[testId]/components/TestDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function TestDetails({ testId, users }: CloudTestDetailsProps) {
6666
// Format the test provider for display
6767
const providerLabel = cloudTest.provider === "aws"
6868
? "Amazon Web Services"
69-
: cloudTest.provider === "AZURE"
69+
: cloudTest.provider === "azure"
7070
? "Microsoft Azure"
7171
: "Google Cloud Platform";
7272

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/tests/all/actions/getTests.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ export const getTests = authActionClient
1414
},
1515
})
1616
.action(async ({ parsedInput, ctx }) => {
17-
const { search, provider, status, page = 1, per_page = 10 } = parsedInput;
17+
const { search, severity, status, page = 1, pageSize = 10 } = parsedInput;
1818
const { user } = ctx;
1919

20+
console.log("--------------------------------");
21+
console.log("search", search);
22+
console.log("severity", severity);
23+
console.log("status", status);
24+
console.log("page", page);
25+
console.log("pageSize", pageSize);
26+
console.log("--------------------------------");
27+
2028
if (!user.organizationId) {
2129
return {
2230
success: false,
@@ -25,7 +33,7 @@ export const getTests = authActionClient
2533
}
2634

2735
try {
28-
const skip = (page - 1) * per_page;
36+
const skip = (page - 1) * pageSize;
2937

3038
// Use the prisma client with correct model
3139
const [integrationResults, total] = await Promise.all([
@@ -50,12 +58,8 @@ export const getTests = authActionClient
5058
},
5159
],
5260
} : {}),
53-
...(provider ? {
54-
organizationIntegration: {
55-
integration_id: provider,
56-
},
57-
} : {}),
58-
...(status ? { label: status } : {}),
61+
...(status ? { status: { equals: status, mode: "insensitive" } } : {}),
62+
...(severity ? { label: { equals: severity, mode: "insensitive" } } : {}),
5963
},
6064
include: {
6165
organizationIntegration: {
@@ -75,7 +79,7 @@ export const getTests = authActionClient
7579
},
7680
},
7781
skip,
78-
take: per_page,
82+
take: pageSize,
7983
orderBy: { completedAt: "desc" },
8084
}),
8185
db.organizationIntegrationResults.count({
@@ -99,12 +103,8 @@ export const getTests = authActionClient
99103
},
100104
],
101105
} : {}),
102-
...(provider ? {
103-
organizationIntegration: {
104-
integration_id: provider,
105-
},
106-
} : {}),
107-
...(status ? { label: status } : {}),
106+
...(status ? { status: { equals: status, mode: "insensitive" } } : {}),
107+
...(severity ? { label: { equals: severity, mode: "insensitive" } } : {}),
108108
},
109109
}),
110110
]);
Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,43 @@
11
"use client";
22

3-
import { DataTable } from "@/components/tables/tests/data-table";
4-
import {
5-
NoResults,
6-
NoTests,
7-
} from "@/components/tables/tests/empty-states";
8-
import { FilterToolbar } from "@/components/tables/tests/filter-toolbar";
9-
import { Loading } from "@/components/tables/tests/loading";
3+
import { NoTests } from "./table/empty-states";
4+
import { Loading } from "./table/loading";
105
import { useTests } from "../hooks/useTests";
11-
import { useSearchParams } from "next/navigation";
12-
import type { TestType } from "@/components/tables/tests/columns";
13-
import { TestsListSkeleton } from "./TestsListSkeleton";
6+
import { TestsTable } from "./table/TestsTable";
7+
import { TestsTableProvider } from "../hooks/useTestsTableContext";
148

15-
interface TestsListProps {
16-
columnHeaders: {
17-
severity: string;
18-
result: string;
19-
title: string;
20-
provider: string;
21-
createdAt: string;
22-
assignedUser: string;
23-
};
24-
}
25-
26-
export function TestsList({ columnHeaders }: TestsListProps) {
27-
const searchParams = useSearchParams();
28-
const search = searchParams.get("search");
29-
const provider = searchParams.get("provider");
30-
const status = searchParams.get("status");
31-
const per_page = Number(searchParams.get("per_page")) || 10;
32-
const page = Number(searchParams.get("page")) || 1;
33-
34-
const { tests, total, isLoading, error } = useTests();
9+
export function TestsList() {
10+
const { tests, isLoading, error } = useTests('');
3511

3612
if (isLoading) {
37-
return <TestsListSkeleton />;
13+
return <Loading isEmpty={false} />;
3814
}
3915

4016
if (error) {
4117
return (
42-
<div className="relative">
43-
<FilterToolbar isEmpty={true} />
44-
<NoResults hasFilters={false} />
18+
<div className="space-y-4">
19+
<h2 className="text-xl font-semibold">Tests</h2>
20+
<div className="border p-4 rounded-md bg-red-50 text-red-800">
21+
Error loading tests: {error.message}
22+
</div>
4523
</div>
4624
);
4725
}
4826

49-
const hasFilters = !!(search || provider || status);
50-
51-
if (tests.length === 0 && !hasFilters) {
27+
if (tests.length === 0) {
5228
return (
5329
<div className="relative overflow-hidden">
54-
<FilterToolbar isEmpty={true} />
5530
<NoTests />
5631
<Loading isEmpty />
5732
</div>
5833
);
5934
}
6035

6136
return (
62-
<div className="relative">
63-
<FilterToolbar isEmpty={tests.length === 0} />
64-
{tests.length > 0 ? (
65-
<DataTable
66-
columnHeaders={columnHeaders}
67-
data={tests as TestType[]}
68-
pageCount={Math.ceil(total / per_page)}
69-
currentPage={page}
70-
/>
71-
) : (
72-
<NoResults hasFilters={hasFilters} />
73-
)}
74-
</div>
37+
<TestsTableProvider>
38+
<div className="relative">
39+
<TestsTable />
40+
</div>
41+
</TestsTableProvider>
7542
);
7643
}

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/tests/all/components/TestsListSkeleton.tsx

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"use client";
2+
3+
import { DataTable } from "@/components/ui/data-table";
4+
import { useParams, useRouter } from "next/navigation";
5+
import { getFilterCategories } from "./filterCategories";
6+
import { getColumns } from "./columns";
7+
import { useTestsTable } from "../../hooks/useTestsTableContext";
8+
import { RefreshCcw } from "lucide-react";
9+
import { refreshTestsAction } from "../../actions/refreshTests";
10+
import { useAction } from "next-safe-action/hooks";
11+
import { toast } from "sonner";
12+
import { useI18n } from "@/locales/client";
13+
14+
export function TestsTable() {
15+
const router = useRouter();
16+
const { orgId } = useParams<{ orgId: string }>();
17+
const t = useI18n();
18+
19+
const {
20+
page,
21+
setPage,
22+
pageSize,
23+
setPageSize,
24+
tests,
25+
total,
26+
search,
27+
setSearch,
28+
status,
29+
setStatus,
30+
severity,
31+
setSeverity,
32+
hasActiveFilters,
33+
clearFilters,
34+
isLoading,
35+
isSearching,
36+
} = useTestsTable();
37+
38+
const refreshTests = useAction(refreshTestsAction, {
39+
onSuccess: () => {
40+
toast.success(t("tests.actions.refresh_success"));
41+
window.location.reload();
42+
},
43+
onError: () => {
44+
toast.error(t("tests.actions.refresh_error"));
45+
},
46+
});
47+
48+
const handleRowClick = (testId: string) => {
49+
router.replace(`/${orgId}/tests/all/${testId}`);
50+
};
51+
52+
const activeFilterCount = [status, severity].filter(Boolean).length;
53+
54+
const filterCategories = getFilterCategories({
55+
status,
56+
setStatus,
57+
severity: severity,
58+
setSeverity: setSeverity,
59+
setPage,
60+
});
61+
62+
// Calculate pagination values only when total is defined
63+
const pagination =
64+
total !== undefined
65+
? {
66+
page: Number(page),
67+
pageSize: Number(pageSize),
68+
totalCount: total,
69+
totalPages: Math.ceil(total / Number(pageSize)),
70+
hasNextPage: Number(page) * Number(pageSize) < total,
71+
hasPreviousPage: Number(page) > 1,
72+
}
73+
: undefined;
74+
75+
return (
76+
<DataTable
77+
data={tests || []}
78+
columns={getColumns(handleRowClick)}
79+
onRowClick={(row) => handleRowClick(row.id)}
80+
emptyMessage="No tests found."
81+
isLoading={isLoading || isSearching}
82+
pagination={pagination}
83+
onPageChange={(page) => setPage(page.toString())}
84+
onPageSizeChange={(pageSize) => setPageSize(pageSize.toString())}
85+
search={{
86+
value: search || "",
87+
onChange: setSearch,
88+
placeholder: "Search tests...",
89+
}}
90+
filters={{
91+
categories: filterCategories,
92+
hasActiveFilters,
93+
onClearFilters: clearFilters,
94+
activeFilterCount,
95+
}}
96+
ctaButton={{
97+
label: "Refresh Tests",
98+
onClick: () => refreshTests.execute(),
99+
icon: <RefreshCcw className="h-4 w-4" />,
100+
}}
101+
/>
102+
);
103+
}

0 commit comments

Comments
 (0)