Skip to content

Commit 92cf8e0

Browse files
Fix table sorting function to not sort based on date time string (e2b-dev#37)
Currently the table date time columns sorted based on their date time string representations. This pr fixes this, along with disabling multiple sortings at once, since this behavior was confusing users.
1 parent ea8911e commit 92cf8e0

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

src/features/dashboard/sandboxes/table-config.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,18 @@ export const COLUMNS: ColumnDef<Sandbox>[] = [
317317
},
318318
{
319319
id: 'startedAt',
320-
accessorFn: (row) => new Date(row.startedAt).toUTCString(),
320+
accessorKey: 'startedAt',
321321
header: 'Started At',
322322
cell: ({ row, getValue }) => {
323-
const dateTimeString = getValue() as string
324-
// Split the date and time parts
325-
const [day, date, month, year, time, timezone] = dateTimeString.split(' ')
323+
const dateValue = getValue() as string;
324+
325+
const dateTimeString = useMemo(() => {
326+
return new Date(dateValue).toUTCString();
327+
}, [dateValue]);
328+
329+
const [day, date, month, year, time, timezone] = useMemo(() => {
330+
return dateTimeString.split(' ');
331+
}, [dateTimeString]);
326332

327333
return (
328334
<div className={cn('h-full truncate font-mono text-xs')}>
@@ -337,5 +343,8 @@ export const COLUMNS: ColumnDef<Sandbox>[] = [
337343
// @ts-expect-error dateRange is not a valid filterFn
338344
filterFn: 'dateRange',
339345
enableColumnFilter: true,
346+
sortingFn: (rowA, rowB) => {
347+
return rowA.original.startedAt.localeCompare(rowB.original.startedAt);
348+
},
340349
},
341350
]

src/features/dashboard/sandboxes/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export default function SandboxesTable({
171171
getFilteredRowModel: getFilteredRowModel(),
172172
getSortedRowModel: getSortedRowModel(),
173173
enableSorting: true,
174-
enableMultiSort: true,
174+
enableMultiSort: false,
175175
columnResizeMode: 'onChange' as const,
176176
enableColumnResizing: true,
177177
keepPinnedRows: true,

src/features/dashboard/templates/table-config.tsx

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,30 +294,64 @@ export const useColumns = (deps: unknown[]) => {
294294
filterFn: 'equals',
295295
},
296296
{
297-
accessorFn: (row) => new Date(row.createdAt).toUTCString(),
297+
accessorKey: 'createdAt',
298298
enableGlobalFilter: true,
299299
id: 'createdAt',
300300
header: 'Created At',
301301
size: 250,
302302
minSize: 140,
303-
cell: ({ getValue }) => (
304-
<div className="text-fg-500 truncate font-mono text-xs">
305-
{getValue() as string}
306-
</div>
307-
),
303+
cell: ({ row, getValue }) => {
304+
const dateValue = getValue() as string;
305+
306+
const dateTimeString = useMemo(() => {
307+
return new Date(dateValue).toUTCString();
308+
}, [dateValue]);
309+
310+
const [day, date, month, year, time, timezone] = useMemo(() => {
311+
return dateTimeString.split(' ');
312+
}, [dateTimeString]);
313+
314+
return (
315+
<div className={cn('h-full truncate font-mono text-xs')}>
316+
<span className="text-fg-500">{`${day} ${date} ${month} ${year}`}</span>{' '}
317+
<span className="text-fg">{time}</span>{' '}
318+
<span className="text-fg-500">{timezone}</span>
319+
</div>
320+
)
321+
},
322+
sortingFn: (rowA, rowB) => {
323+
return rowA.original.createdAt.localeCompare(rowB.original.createdAt);
324+
},
308325
},
309326
{
310-
accessorFn: (row) => new Date(row.updatedAt).toUTCString(),
327+
accessorKey: 'updatedAt',
311328
id: 'updatedAt',
312329
header: 'Updated At',
313330
size: 250,
314331
minSize: 140,
315332
enableGlobalFilter: true,
316-
cell: ({ getValue }) => (
317-
<div className="text-fg-500 truncate font-mono text-xs">
318-
{getValue() as string}
319-
</div>
320-
),
333+
cell: ({ row, getValue }) => {
334+
const dateValue = getValue() as string;
335+
336+
const dateTimeString = useMemo(() => {
337+
return new Date(dateValue).toUTCString();
338+
}, [dateValue]);
339+
340+
const [day, date, month, year, time, timezone] = useMemo(() => {
341+
return dateTimeString.split(' ');
342+
}, [dateTimeString]);
343+
344+
return (
345+
<div className={cn('h-full truncate font-mono text-xs')}>
346+
<span className="text-fg-500">{`${day} ${date} ${month} ${year}`}</span>{' '}
347+
<span className="text-fg">{time}</span>{' '}
348+
<span className="text-fg-500">{timezone}</span>
349+
</div>
350+
)
351+
},
352+
sortingFn: (rowA, rowB) => {
353+
return rowA.original.updatedAt.localeCompare(rowB.original.updatedAt);
354+
},
321355
},
322356
{
323357
accessorKey: 'public',
@@ -351,7 +385,7 @@ export const templatesTableConfig: Partial<
351385
getFilteredRowModel: getFilteredRowModel(),
352386
getSortedRowModel: getSortedRowModel(),
353387
enableSorting: true,
354-
enableMultiSort: true,
388+
enableMultiSort: false,
355389
columnResizeMode: 'onChange',
356390
enableColumnResizing: true,
357391
enableGlobalFilter: true,

0 commit comments

Comments
 (0)