1 import { memo, useEffect } from 'react';
3 import { DragMoveContainer, TableRow } from '@proton/components';
4 import { isEquivalent } from '@proton/shared/lib/helpers/object';
5 import clsx from '@proton/utils/clsx';
6 import shallowEqual from '@proton/utils/shallowEqual';
8 import useDragAndDrop from '../hooks/useDragAndDrop';
9 import useFileBrowserItem from '../hooks/useFileBrowserItem';
10 import type { DragMoveControls, FileBrowserBaseItem } from '../interface';
12 interface ListItemProps<T extends FileBrowserBaseItem> {
13 Cells: React.FC<{ item: any }>[];
15 style?: React.CSSProperties;
17 isMultiSelectionDisabled?: boolean;
19 onItemContextMenu?: (e: any) => void;
20 onItemOpen?: (id: string) => void;
21 onItemRender?: (item: any) => void;
23 dragMoveControls?: DragMoveControls;
26 const ItemRow = <T extends FileBrowserBaseItem>({
31 isMultiSelectionDisabled,
37 }: ListItemProps<T>) => {
38 const { isSelected, itemHandlers } = useFileBrowserItem({
40 isItemLocked: item.isLocked,
42 onItemContextMenu: onItemContextMenu,
43 isMultiSelectionDisabled,
45 const dragnDropControls = useDragAndDrop({
50 const { draggable, dragMoveItems } = dragnDropControls;
51 const { dragging, DragMoveContent } = dragnDropControls.dragMove;
59 {draggable && dragMoveControls && (
60 <DragMoveContent dragging={dragging} data={dragMoveItems}>
61 <DragMoveContainer>{dragnDropControls.moveText}</DragMoveContainer>
65 style={{ ...style, ...item.itemRowStyle }}
70 'file-browser-list-item flex user-select-none group-hover-opacity-container',
71 (isSelected || dragMoveControls?.isActiveDropTarget || item.isLocked) && 'bg-strong',
72 (dragging || item.isLocked) && 'opacity-50',
73 item.isInvitation && 'file-browser-list-item--invitation',
75 aria-disabled={item.isLocked}
77 {...dragnDropControls.itemHandlers}
79 {Cells.map((Cell, index) => (
80 <Cell key={item.id + index} item={item} />
87 export default memo(ItemRow, (a, b) => {
88 if (isEquivalent(a, b)) {
93 !isEquivalent(a.style || {}, b.style || {}) ||
94 !isEquivalent(a.item, b.item) ||
95 !shallowEqual(a.Cells, b.Cells)
100 const dragControlsEqual =
101 a.dragMoveControls?.dragging === b.dragMoveControls?.dragging &&
102 a.dragMoveControls?.isActiveDropTarget === b.dragMoveControls?.isActiveDropTarget &&
103 a.dragMoveControls?.selectedItems === b.dragMoveControls?.selectedItems;
105 return dragControlsEqual;