diff --git a/ui/src/components/table/groupings-table.tsx b/ui/src/components/table/groupings-table.tsx index cb3df24b..b63ccea1 100644 --- a/ui/src/components/table/groupings-table.tsx +++ b/ui/src/components/table/groupings-table.tsx @@ -1,5 +1,4 @@ 'use client'; - import { useReactTable, flexRender, @@ -12,17 +11,14 @@ import { } from '@tanstack/react-table'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import ColumnSettings from '@/components/table/table-element/column-settings'; -import GroupingsTableColumns from '@/components/table/table-element/groupings-table-columns'; + import PaginationBar from '@/components/table/table-element/pagination-bar'; import GlobalFilter from '@/components/table/table-element/global-filter'; import SortArrow from '@/components/table/table-element/sort-arrow'; import { useState } from 'react'; -import { SquarePen } from 'lucide-react'; -import GroupingPathCell from '@/components/table/table-element/grouping-path-cell'; -import Link from 'next/link'; import { useLocalStorage } from 'usehooks-ts'; import { GroupingPath } from '@/lib/types'; -import TooltipOnTruncate from '@/components/table/table-element/tooltip-on-truncate'; +import GroupingsTableColumns from '@/components/table/table-element/groupings-table-columns'; const pageSize = parseInt(process.env.NEXT_PUBLIC_PAGE_SIZE as string); @@ -49,8 +45,6 @@ const GroupingsTable = ({ groupingPaths }: { groupingPaths: GroupingPath[] }) => enableMultiSort: true }); - const columnCount = table.getHeaderGroups()[0].headers.length; - return ( <>
@@ -66,13 +60,14 @@ const GroupingsTable = ({ groupingPaths }: { groupingPaths: GroupingPath[] }) => {table.getHeaderGroups().map((headerGroup) => ( - {headerGroup.headers.map((header, index) => ( + {headerGroup.headers.map((header) => ( 0 ? 'w-2/3' : ''} + ${header.column.getIndex() > 0 ? 'hidden sm:table-cell' : 'w-2/5 md:w-1/3'} + `} >
{flexRender(header.column.columnDef.header, header.getContext())} @@ -90,41 +85,9 @@ const GroupingsTable = ({ groupingPaths }: { groupingPaths: GroupingPath[] }) =>
-
- {cell.column.id === 'name' && ( - -
- -
- {flexRender(cell.column.columnDef.cell, cell.getContext())} -
-
- - )} -
- {cell.column.id === 'description' && ( - -
- {flexRender(cell.column.columnDef.cell, cell.getContext())} -
-
- )} - {cell.column.id === 'path' && ( - - )} + {flexRender(cell.column.columnDef.cell, cell.getContext())}
))} diff --git a/ui/src/components/table/table-element/ grouping-description-cell.tsx b/ui/src/components/table/table-element/ grouping-description-cell.tsx new file mode 100644 index 00000000..a49c79c6 --- /dev/null +++ b/ui/src/components/table/table-element/ grouping-description-cell.tsx @@ -0,0 +1,11 @@ +import TooltipOnTruncate from '@/components/table/table-element/tooltip-on-truncate'; + +const GroupingDescriptionCell = ({ description }: { description: string }) => { + return ( + +
{description}
+
+ ); +}; + +export default GroupingDescriptionCell; diff --git a/ui/src/components/table/table-element/ grouping-name-cell.tsx b/ui/src/components/table/table-element/ grouping-name-cell.tsx new file mode 100644 index 00000000..caa0be3c --- /dev/null +++ b/ui/src/components/table/table-element/ grouping-name-cell.tsx @@ -0,0 +1,17 @@ +import Link from 'next/link'; +import { SquarePen } from 'lucide-react'; + +const GroupingNameCell = ({ path, name }: { path: string; name: string }) => { + return ( +
+ +
+ +
{name}
+
+ +
+ ); +}; + +export default GroupingNameCell; diff --git a/ui/src/components/table/table-element/grouping-path-cell.tsx b/ui/src/components/table/table-element/grouping-path-cell.tsx index b3ce74ef..7967f688 100644 --- a/ui/src/components/table/table-element/grouping-path-cell.tsx +++ b/ui/src/components/table/table-element/grouping-path-cell.tsx @@ -1,3 +1,4 @@ +'use client'; import { ClipboardIcon } from 'lucide-react'; import { Input } from '@/components/ui/input'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; @@ -22,14 +23,14 @@ const GroupingPathCell = ({ path }: { path: string }) => { }; return ( -
+
diff --git a/ui/src/components/table/table-element/groupings-table-columns.tsx b/ui/src/components/table/table-element/groupings-table-columns.tsx index 5f77abbb..1a5905e5 100644 --- a/ui/src/components/table/table-element/groupings-table-columns.tsx +++ b/ui/src/components/table/table-element/groupings-table-columns.tsx @@ -1,18 +1,29 @@ -const GroupingsTableColumns = [ +import { ColumnDef } from '@tanstack/react-table'; +import { GroupingPath } from '@/lib/types'; +import GroupingPathCell from '@/components/table/table-element/grouping-path-cell'; +import GroupingDescriptionCell from '@/components/table/table-element/ grouping-description-cell'; +import GroupingNameCell from '@/components/table/table-element/ grouping-name-cell'; +const GroupingsTableColumns: ColumnDef[] = [ { header: 'Grouping Name', accessorKey: 'name', enableHiding: false, - sortDescFirst: true + sortDescFirst: true, + cell: ({ row }) => ( + + ) }, { header: 'Description', - accessorKey: 'description' + accessorKey: 'description', + cell: ({ row }) => ( + + ) }, { header: 'Grouping Path', - accessorKey: 'path' + accessorKey: 'path', + cell: ({ row }) => } ]; - export default GroupingsTableColumns; diff --git a/ui/src/components/table/table-element/tooltip-on-truncate.tsx b/ui/src/components/table/table-element/tooltip-on-truncate.tsx index a4104546..5def3abf 100644 --- a/ui/src/components/table/table-element/tooltip-on-truncate.tsx +++ b/ui/src/components/table/table-element/tooltip-on-truncate.tsx @@ -24,7 +24,10 @@ const TooltipOnTruncate = ({ children, value }: { children: React.ReactNode; val {children} {isTruncated && ( - +

{value}

)} diff --git a/ui/tests/components/table/groupings-table.test.tsx b/ui/tests/components/table/groupings-table.test.tsx index 02ac6b03..164630ba 100644 --- a/ui/tests/components/table/groupings-table.test.tsx +++ b/ui/tests/components/table/groupings-table.test.tsx @@ -158,24 +158,4 @@ describe('GroupingsTable', () => { await checkPageContent('Last', mockData.length - pageSize, mockData.length - 1); await checkPageContent('Previous', mockData.length - pageSize * 2, mockData.length - pageSize - 1); }); - it('should show tooltip if description content is truncated', async () => { - Object.defineProperties(HTMLElement.prototype, { - scrollWidth: { get: () => 500, configurable: true }, - clientWidth: { get: () => 30, configurable: true } - }); - render(); - const firstButton = screen.getByText('First'); - - fireEvent.click(firstButton); - - const description = screen.getByText('Test Description 0'); - await waitFor(async () => { - await userEvent.hover(description); - }); - - // Wait for the tooltip to appear - await waitFor(() => { - expect(screen.getAllByTestId('tooltip-on-truncate')[0]).toBeInTheDocument(); - }); - }); }); diff --git a/ui/tests/components/table/table-element/ grouping-description-cell.test.tsx b/ui/tests/components/table/table-element/ grouping-description-cell.test.tsx new file mode 100644 index 00000000..9209162d --- /dev/null +++ b/ui/tests/components/table/table-element/ grouping-description-cell.test.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { render, screen, waitFor } from '@testing-library/react'; + +import userEvent from '@testing-library/user-event'; +import GroupingDescriptionCell from '@/components/table/table-element/ grouping-description-cell'; + +describe('GroupingDescriptionCell', () => { + it('renders the description inside TooltipOnTruncate', () => { + const description = 'This is a test description'; + render(); + expect(screen.getByText(description)).toBeInTheDocument(); + }); + + it('should show tooltip if description content is truncated', async () => { + Object.defineProperties(HTMLElement.prototype, { + scrollWidth: { get: () => 500, configurable: true }, + clientWidth: { get: () => 30, configurable: true } + }); + + const description = 'This is a test description'; + render(); + + const descriptionComponent = screen.getByText(description); + await userEvent.hover(descriptionComponent); + + await waitFor(() => { + expect(screen.getAllByTestId('tooltip-on-truncate')[0]).toBeInTheDocument(); + }); + }); +}); diff --git a/ui/tests/components/table/table-element/ grouping-name-cell.test.tsx b/ui/tests/components/table/table-element/ grouping-name-cell.test.tsx new file mode 100644 index 00000000..9ded794c --- /dev/null +++ b/ui/tests/components/table/table-element/ grouping-name-cell.test.tsx @@ -0,0 +1,13 @@ +import { render, screen} from '@testing-library/react'; +import GroupingNameCell from '@/components/table/table-element/ grouping-name-cell'; + +describe('GroupingNameCell', () => { + it('renders the link with the correct path and displays the name', () => { + const path = 'test-path'; + const name = 'Test Name'; + render(); + expect(screen.getByText(name)).toBeInTheDocument(); + expect(screen.getByTestId('square-pen-icon')).toBeInTheDocument(); + expect(screen.getByRole('link')).toHaveAttribute('href', `/groupings/${path}`) + }); +});