onColumnResize update

This commit is contained in:
Nate Kelley 2025-02-19 22:26:53 -07:00
parent 4373fbb664
commit def3863d58
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 27 additions and 24 deletions

View File

@ -1,8 +1,9 @@
'use client';
import DataGrid from 'react-data-grid';
import { DataGrid } from 'react-data-grid';
import type {
Column,
CalculatedColumn,
CopyEvent,
RenderCellProps,
RenderHeaderCellProps,
@ -204,27 +205,30 @@ export const AppDataGrid: React.FC<AppDataGridProps> = React.memo(
}
});
const onColumnResize = useMemoizedFn((index: number, size: number) => {
const newSizes = columns.reduce<Record<string, number>>((acc, column, i) => {
if (!column.key) return acc;
const onColumnResize = useMemoizedFn(
(column: CalculatedColumn<Row, unknown>, width: number) => {
const index = columns.findIndex((c) => c.key === column.key);
const newSizes = columns.reduce<Record<string, number>>((acc, column, i) => {
if (!column.key) return acc;
acc[column.key] = i === index ? round(size) : (column.width as number);
return acc;
}, {});
const columnArray = columns
.map((column) => ({
key: column.key,
size: newSizes[column.key]
}))
.sort(
(a, b) =>
columnsOrder.indexOf(columns.findIndex((c) => c.key === a.key)) -
columnsOrder.indexOf(columns.findIndex((c) => c.key === b.key))
);
acc[column.key] = i === index ? round(width) : (column.width as number);
return acc;
}, {});
const columnArray = columns
.map((column) => ({
key: column.key,
size: newSizes[column.key]
}))
.sort(
(a, b) =>
columnsOrder.indexOf(columns.findIndex((c) => c.key === a.key)) -
columnsOrder.indexOf(columns.findIndex((c) => c.key === b.key))
);
onResizeColumnsDebounce(columnArray);
onColumnResizeDebounce();
});
onResizeColumnsDebounce(columnArray);
onColumnResizeDebounce();
}
);
const { run: onResizeColumnsDebounce } = useDebounceFn(
(columnArray: { key: string; size: number }[]) => {
@ -356,6 +360,7 @@ export const AppDataGrid: React.FC<AppDataGridProps> = React.memo(
enableVirtualization={rows.length > 60}
onCopy={handleCopy}
onColumnResize={onColumnResize}
// onColumnResize={onColumnResize}
onColumnsReorder={onColumnsReorder}
defaultColumnOptions={DEFAULT_COLUMN_WIDTH}
direction={'ltr'}

View File

@ -6,9 +6,7 @@ import { SaveDashboardToCollectionButton } from '@/components/features/Buttons/S
import { HideButtonContainer } from './HideButtonContainer';
import { useChatLayoutContextSelector } from '../../ChatLayoutContext';
import { CreateChatButton } from './CreateChatButtont';
import { ShareDashboardButton } from '../../../../components/features/Buttons/ShareDashboardButton';
import { BackButton } from '@/components/ui/buttons/BackButton';
import { FileIndeterminateLoader as Testing123 } from '@/components/features';
import { ShareDashboardButton } from '@/components/features/Buttons/ShareDashboardButton';
import { Button, Dropdown } from 'antd';
import { AppMaterialIcons } from '@/components/ui';
import { MenuProps } from 'antd/lib';

View File

@ -21,7 +21,7 @@
"paths": {
"@/*": ["./src/*"],
"@utils/*": ["./src/utils/*"],
"@/components/features/*": ["./src/app/app/_components/*"],
"@components/*": ["./src/components/*"],
"@layouts/*": ["./src/layouts/*"],
"@controllers/*": ["./src/controllers/*"],
"@chatLayout/*": ["./src/layouts/ChatLayout/*"]