optimize table config

This commit is contained in:
jeffvli
2025-11-14 00:58:48 -08:00
parent e82c1d3a20
commit 6d6caa0406
@@ -12,7 +12,7 @@ import { disableNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/elem
import { useDebouncedState } from '@mantine/hooks'; import { useDebouncedState } from '@mantine/hooks';
import clsx from 'clsx'; import clsx from 'clsx';
import Fuse from 'fuse.js'; import Fuse from 'fuse.js';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import styles from './table-config.module.css'; import styles from './table-config.module.css';
@@ -498,28 +498,22 @@ const TableColumnConfig = ({
}; };
const DragHandle = ({ dragHandleRef }: { dragHandleRef: React.RefObject<HTMLButtonElement> }) => { const DragHandle = ({ dragHandleRef }: { dragHandleRef: React.RefObject<HTMLButtonElement> }) => {
const { t } = useTranslation();
return ( return (
<ActionIcon <ActionIcon
icon="dragVertical" icon="dragHorizontal"
iconProps={{ iconProps={{
size: 'md', size: 'md',
}} }}
ref={dragHandleRef} ref={dragHandleRef}
size="xs" size="xs"
style={{ cursor: 'grab' }} style={{ cursor: 'grab' }}
tooltip={{
label: t('table.config.general.dragToReorder', {
postProcess: 'sentenceCase',
}),
}}
variant="transparent" variant="transparent"
/> />
); );
}; };
const TableColumnItem = ({ const TableColumnItem = memo(
({
handleAlignCenter, handleAlignCenter,
handleAlignLeft, handleAlignLeft,
handleAlignRight, handleAlignRight,
@@ -586,7 +580,9 @@ const TableColumnItem = ({
canDrop: (args) => { canDrop: (args) => {
const data = args.source.data as unknown as DragData; const data = args.source.data as unknown as DragData;
const isSelf = (args.source.data.id as string[])[0] === item.id; const isSelf = (args.source.data.id as string[])[0] === item.id;
return dndUtils.isDropTarget(data.type, [DragTarget.TABLE_COLUMN]) && !isSelf; return (
dndUtils.isDropTarget(data.type, [DragTarget.TABLE_COLUMN]) && !isSelf
);
}, },
element: ref.current, element: ref.current,
getData: ({ element, input }) => { getData: ({ element, input }) => {
@@ -762,10 +758,26 @@ const TableColumnItem = ({
onChange={(value) => handleRowWidth(item, value)} onChange={(value) => handleRowWidth(item, value)}
size="xs" size="xs"
step={10} step={10}
stepHoldDelay={300}
stepHoldInterval={100}
value={item.width} value={item.width}
variant="subtle" variant="subtle"
/> />
</Group> </Group>
</div> </div>
); );
}; },
(prevProps, nextProps) => {
// Custom comparison function for better memoization
return (
prevProps.item.id === nextProps.item.id &&
prevProps.item.isEnabled === nextProps.item.isEnabled &&
prevProps.item.autoSize === nextProps.item.autoSize &&
prevProps.item.width === nextProps.item.width &&
prevProps.item.pinned === nextProps.item.pinned &&
prevProps.item.align === nextProps.item.align &&
prevProps.label === nextProps.label &&
prevProps.matches === nextProps.matches
);
},
);