Skip to content

Commit 8f2ccc3

Browse files
committed
Add tooltips to history table
1 parent 50aaddc commit 8f2ccc3

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

frontend/src/app/(user)/dashboard/components/DashboardDataTable.tsx

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
useReactTable,
1111
} from "@tanstack/react-table";
1212

13-
import { format } from 'date-fns';
13+
import { format } from "date-fns";
1414

1515
import { Button } from "@/components/ui/button";
1616
import {
@@ -31,11 +31,17 @@ import VerificationSymbol from "@/app/common/VerificationSymbol";
3131
const Cell = ({
3232
className,
3333
children,
34+
tooltipText,
3435
}: {
3536
className?: string;
3637
children: React.ReactNode;
38+
tooltipText?: string;
3739
}) => {
38-
return <div className={cn("text-center", className)}>{children}</div>;
40+
return (
41+
<div className={cn("text-center", className)} title={tooltipText}>
42+
{children}
43+
</div>
44+
);
3945
};
4046

4147
export const columns: ColumnDef<TCombinedSession>[] = [
@@ -47,7 +53,7 @@ export const columns: ColumnDef<TCombinedSession>[] = [
4753
const peerData = await getUser(peer);
4854

4955
return (
50-
<Cell className="capitalize">
56+
<Cell className="capitalize" tooltipText={peerData.data.username}>
5157
<Link
5258
className="group text-center p-2 rounded-xl hover:bg-white hover:text-primary-900 underline"
5359
href={`/user/${peerData.data.username}`}
@@ -62,32 +68,38 @@ export const columns: ColumnDef<TCombinedSession>[] = [
6268
{
6369
accessorKey: "title",
6470
header: () => <Cell>Question Name</Cell>,
65-
cell: ({ row }) => <Cell>{row.getValue("title")}</Cell>,
71+
cell: ({ row }) => {
72+
const title: string = row.getValue("title");
73+
74+
return <Cell tooltipText={title}>{title}</Cell>;
75+
},
6676
},
6777
{
6878
accessorKey: "language",
6979
header: () => <Cell>Matched Language</Cell>,
7080
cell: ({ row }) => {
7181
const language = row.getValue("language") as string;
72-
return (
73-
<Cell>{language.charAt(0).toUpperCase() + language.slice(1)}</Cell>
74-
);
82+
const languageFormatted =
83+
language.charAt(0).toUpperCase() + language.slice(1);
84+
return <Cell tooltipText={languageFormatted}>{languageFormatted}</Cell>;
7585
},
7686
},
7787
{
7888
accessorKey: "complexity",
7989
header: () => <Cell>Complexity</Cell>,
8090
cell: ({ row }) => {
81-
return <Cell>{row.getValue("complexity")}</Cell>;
91+
const complexity: string = row.getValue("complexity");
92+
return <Cell tooltipText={complexity}>{complexity}</Cell>;
8293
},
8394
},
8495
{
8596
accessorKey: "category",
8697
header: () => <Cell>Category</Cell>,
8798
cell: ({ row }) => {
8899
const categories: string[] = row.getValue("category");
100+
const combinedCategories: string = categories.join(", ");
89101
return (
90-
<Cell>
102+
<Cell tooltipText={combinedCategories}>
91103
{categories.slice(0, 3).join(", ")}
92104
{categories.length > 3 ? "..." : ""}
93105
</Cell>
@@ -101,8 +113,8 @@ export const columns: ColumnDef<TCombinedSession>[] = [
101113
const date: Date = row.getValue("createdAt");
102114

103115
return (
104-
<Cell>
105-
{format(date, 'dd-MM-yyyy HH:mm:ss')}
116+
<Cell tooltipText={format(date, "dd-MM-yyyy HH:mm:ss")}>
117+
{format(date, "dd-MM-yyyy HH:mm:ss")}
106118
</Cell>
107119
);
108120
},
@@ -214,9 +226,11 @@ export function DashboardDataTable({ data }: { data: TCombinedSession[] }) {
214226
Prev
215227
</Button>
216228
<div>
217-
Page {table.getPageCount() == 0 ? 0 : table.getState().pagination.pageIndex + 1}
218-
/
219-
{table.getPageCount()}
229+
Page{" "}
230+
{table.getPageCount() == 0
231+
? 0
232+
: table.getState().pagination.pageIndex + 1}
233+
/{table.getPageCount()}
220234
</div>
221235
<Button
222236
variant="outline"

0 commit comments

Comments
 (0)