Skip to content

Commit 77de141

Browse files
committed
temporarily clean up table
1 parent 46ac75d commit 77de141

File tree

5 files changed

+50
-273
lines changed

5 files changed

+50
-273
lines changed

apps/dashboard/components/table/data-table.tsx

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import {
22
type ColumnDef,
33
getCoreRowModel,
4-
getFilteredRowModel,
5-
getSortedRowModel,
6-
type SortingState,
74
useReactTable,
85
} from '@tanstack/react-table';
96
import type React from 'react';
10-
import { useMemo, useState } from 'react';
7+
import { useState } from 'react';
118
import ReactDOM from 'react-dom';
129
import { Skeleton } from '@/components/ui/skeleton';
1310
import { cn } from '@/lib/utils';
@@ -50,7 +47,6 @@ interface DataTableProps<TData extends { name: string | number }, TValue> {
5047
index: number
5148
) => React.ReactNode;
5249
expandable?: boolean;
53-
showSearch?: boolean;
5450
}
5551

5652
const EnhancedSkeleton = ({ minHeight }: { minHeight: string | number }) => (
@@ -100,11 +96,8 @@ export function DataTable<TData extends { name: string | number }, TValue>({
10096
expandable = false,
10197
onAddFilter,
10298
onRowAction,
103-
showSearch = true,
10499
}: DataTableProps<TData, TValue>) {
105100
const [activeTab, setActiveTab] = useState(tabs?.[0]?.id || '');
106-
const [sorting, setSorting] = useState<SortingState>([]);
107-
const [globalFilter, setGlobalFilter] = useState('');
108101

109102
const { fullScreen, setFullScreen, hasMounted, modalRef } = useFullScreen();
110103

@@ -115,30 +108,13 @@ export function DataTable<TData extends { name: string | number }, TValue>({
115108
const table = useReactTable({
116109
data: tableData,
117110
columns: tableColumns,
118-
enableSorting: true,
119-
getRowId: (row, index) => {
120-
if ((row as any)._uniqueKey) {
121-
return (row as any)._uniqueKey;
122-
}
123-
return activeTab ? `${activeTab}-${index}` : `row-${index}`;
124-
},
125-
state: {
126-
sorting,
127-
globalFilter,
128-
},
129-
onSortingChange: setSorting,
130-
onGlobalFilterChange: setGlobalFilter,
111+
getRowId: (_row, index) => `${activeTab || 'row'}-${index}`,
131112
getCoreRowModel: getCoreRowModel(),
132-
getFilteredRowModel: getFilteredRowModel(),
133-
getSortedRowModel: getSortedRowModel(),
134-
globalFilterFn: 'includesString',
135113
});
136114

137115
const handleTabChange = (tabId: string) => {
138116
if (tabId === activeTab) return;
139117
setActiveTab(tabId);
140-
setSorting([]);
141-
setGlobalFilter('');
142118
};
143119

144120
if (isLoading) {
@@ -186,9 +162,6 @@ export function DataTable<TData extends { name: string | number }, TValue>({
186162
<TableToolbar
187163
description={description}
188164
onFullScreenToggle={() => setFullScreen(true)}
189-
onSearchChange={setGlobalFilter}
190-
searchValue={globalFilter}
191-
showSearch={showSearch}
192165
title={title}
193166
/>
194167

@@ -246,10 +219,8 @@ export function DataTable<TData extends { name: string | number }, TValue>({
246219
onClose={() => setFullScreen(false)}
247220
onRowAction={onRowAction}
248221
onRowClick={onRowClick}
249-
onSearchChange={setGlobalFilter}
250222
onTabChange={handleTabChange}
251223
renderSubRow={renderSubRow}
252-
searchValue={globalFilter}
253224
tabs={tabs}
254225
title={title}
255226
/>

apps/dashboard/components/table/fullscreen-modal.tsx

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import { MagnifyingGlassIcon, XIcon } from '@phosphor-icons/react';
1+
import { XIcon } from '@phosphor-icons/react';
22
import {
33
type ColumnDef,
44
getCoreRowModel,
5-
getFilteredRowModel,
6-
getSortedRowModel,
7-
type SortingState,
85
useReactTable,
96
} from '@tanstack/react-table';
10-
import { useMemo, useState } from 'react';
11-
import { Input } from '@/components/ui/input';
127
import { TableContent } from './table-content';
138
import { TableTabs } from './table-tabs';
149

@@ -39,8 +34,6 @@ interface FullScreenModalProps<TData extends { name: string | number }> {
3934
onAddFilter?: (field: string, value: string, tableTitle?: string) => void;
4035
onRowAction?: (row: TData) => void;
4136
onRowClick?: (field: string, value: string | number) => void;
42-
searchValue?: string;
43-
onSearchChange?: (value: string) => void;
4437
}
4538

4639
export function FullScreenModal<TData extends { name: string | number }>({
@@ -52,66 +45,27 @@ export function FullScreenModal<TData extends { name: string | number }>({
5245
tabs,
5346
activeTab,
5447
onTabChange,
55-
searchValue,
56-
onSearchChange,
5748
expandable = false,
5849
getSubRows,
5950
renderSubRow,
6051
onAddFilter,
6152
onRowAction,
6253
onRowClick,
6354
}: FullScreenModalProps<TData>) {
64-
const [sorting, setSorting] = useState<SortingState>([]);
65-
const [globalFilter, setGlobalFilter] = useState(searchValue || '');
66-
67-
// Update global filter when searchValue prop changes
68-
useMemo(() => {
69-
setGlobalFilter(searchValue || '');
70-
}, [searchValue]);
7155

7256
const currentTabData = tabs?.find((tab) => tab.id === activeTab);
73-
const tableData = useMemo(
74-
() => currentTabData?.data || data || [],
75-
[currentTabData?.data, data]
76-
);
77-
const tableColumns = useMemo(
78-
() => currentTabData?.columns || columns || [],
79-
[currentTabData?.columns, columns]
80-
);
57+
const tableData = currentTabData?.data || data || [];
58+
const tableColumns = currentTabData?.columns || columns || [];
8159

8260
const table = useReactTable({
8361
data: tableData,
8462
columns: tableColumns,
85-
enableSorting: true,
86-
getRowId: (row, index) => {
87-
if ((row as any)._uniqueKey) {
88-
return (row as any)._uniqueKey;
89-
}
90-
return activeTab ? `${activeTab}-${index}` : `row-${index}`;
91-
},
92-
state: {
93-
sorting,
94-
globalFilter,
95-
},
96-
onSortingChange: setSorting,
97-
onGlobalFilterChange: (value) => {
98-
setGlobalFilter(value);
99-
onSearchChange?.(value);
100-
},
63+
getRowId: (_row, index) => `${activeTab || 'row'}-${index}`,
10164
getCoreRowModel: getCoreRowModel(),
102-
getFilteredRowModel: getFilteredRowModel(),
103-
getSortedRowModel: getSortedRowModel(),
104-
globalFilterFn: 'includesString',
10565
});
10666

10767
const handleTabChange = (tabId: string) => {
108-
if (tabId === activeTab) {
109-
return;
110-
}
111-
112-
setSorting([]);
113-
setGlobalFilter('');
114-
onSearchChange?.('');
68+
if (tabId === activeTab) return;
11569
onTabChange?.(tabId);
11670
};
11771
return (
@@ -130,21 +84,6 @@ export function FullScreenModal<TData extends { name: string | number }>({
13084
)}
13185
</div>
13286
<div className="flex items-center gap-2">
133-
{onSearchChange && (
134-
<div className="relative">
135-
<MagnifyingGlassIcon className="-translate-y-1/2 absolute top-1/2 left-2.5 h-4 w-4 text-muted-foreground" />
136-
<Input
137-
className="h-8 w-64 pl-8 text-sm"
138-
onChange={(e) => {
139-
setGlobalFilter(e.target.value);
140-
onSearchChange(e.target.value);
141-
}}
142-
placeholder="Search..."
143-
type="search"
144-
value={globalFilter}
145-
/>
146-
</div>
147-
)}
14887
<button
14988
aria-label="Close full screen"
15089
className="ml-2 flex items-center justify-center rounded bg-sidebar-accent/60 p-2 text-sidebar-foreground transition-colors hover:bg-sidebar-accent"
@@ -162,7 +101,7 @@ export function FullScreenModal<TData extends { name: string | number }>({
162101
{tabs && tabs.length > 1 && (
163102
<div className="mt-2">
164103
<TableTabs
165-
activeTab={activeTab || ''}
104+
activeTab={activeTab ?? ''}
166105
onTabChange={handleTabChange}
167106
tabs={tabs}
168107
/>

apps/dashboard/components/table/rows/page-time-row.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export function createPageTimeColumns(): ColumnDef<PageTimeEntry>[] {
3535
id: 'name',
3636
accessorKey: 'name',
3737
header: 'Page',
38-
enableSorting: true,
3938
cell: (info: CellContext<PageTimeEntry, any>) => {
4039
const name = (info.getValue() as string) || '';
4140
return (
@@ -49,7 +48,6 @@ export function createPageTimeColumns(): ColumnDef<PageTimeEntry>[] {
4948
id: 'median_time_on_page',
5049
accessorKey: 'median_time_on_page',
5150
header: 'Avg Time',
52-
enableSorting: true,
5351
cell: (info: CellContext<PageTimeEntry, any>) => {
5452
const seconds = (info.getValue() as number) ?? 0;
5553
return (
@@ -65,7 +63,6 @@ export function createPageTimeColumns(): ColumnDef<PageTimeEntry>[] {
6563
id: 'sessions_with_time',
6664
accessorKey: 'sessions_with_time',
6765
header: 'Sessions',
68-
enableSorting: true,
6966
cell: (info: CellContext<PageTimeEntry, any>) => (
7067
<span className="font-medium">{formatNumber(info.getValue())}</span>
7168
),
@@ -74,7 +71,6 @@ export function createPageTimeColumns(): ColumnDef<PageTimeEntry>[] {
7471
id: 'visitors',
7572
accessorKey: 'visitors',
7673
header: 'Visitors',
77-
enableSorting: true,
7874
cell: (info: CellContext<PageTimeEntry, any>) => (
7975
<span className="font-medium">{formatNumber(info.getValue())}</span>
8076
),
@@ -83,7 +79,6 @@ export function createPageTimeColumns(): ColumnDef<PageTimeEntry>[] {
8379
id: 'percentage',
8480
accessorKey: 'percentage',
8581
header: 'Share',
86-
enableSorting: true,
8782
cell: (info: CellContext<PageTimeEntry, any>) => {
8883
const percentage = info.getValue() as number;
8984
return <PercentageBadge percentage={percentage} />;

0 commit comments

Comments
 (0)