import { TableHead, TableRow } from '@mui/material'; import type { ListingVariant } from '@centreon/ui-context'; import { closestCenter, type DraggableSyntheticListeners } from '@dnd-kit/core'; import { horizontalListSortingStrategy } from '@dnd-kit/sortable'; import { equals, find, map, pick, propEq } from 'ramda'; import { memo, useCallback } from 'react'; import SortableItems from '../../SortableItems'; import { getVisibleColumns, type Props as ListingProps } from '..'; import type { Column } from '../models'; import ListingHeaderCell from './Cell/ListingHeaderCell'; import { SelectActionListingHeaderCell, type SelectActionListingHeaderCellProps } from './Cell/SelectActionListingHeaderCell'; type Props = Pick< ListingProps, | 'sortField' | 'sortOrder' | 'onSort' | 'columns' | 'checkable' | 'onSelectColumns' | 'columnConfiguration' | 'totalRows' > & { areColumnsEditable: boolean; listingVariant?: ListingVariant; memoProps: Array; rowCount: number; } & SelectActionListingHeaderCellProps; interface ContentProps extends Pick { attributes: Record; id: string; isDragging: boolean; isInDragOverlay?: boolean; itemRef: React.RefObject; listeners: DraggableSyntheticListeners; style: React.CSSProperties; } const ListingHeader = ({ sortOrder, sortField, rowCount, columns, columnConfiguration, onSort, onSelectColumns, checkable, memoProps, areColumnsEditable, listingVariant, onSelectAllClick, selectedRowCount, predefinedRowsSelection, onSelectRowsWithCondition }: Props): JSX.Element => { const visibleColumns = getVisibleColumns({ columnConfiguration, columns }); const getColumnById = useCallback( (id: string): Column => { return find(propEq(id, 'id'), columns) as Column; }, [columns] ); const Content = useCallback( ({ isInDragOverlay, listeners, attributes, style, isDragging, itemRef, id }: ContentProps): JSX.Element => { return ( ); }, [ columnConfiguration, sortField, sortOrder, areColumnsEditable, getColumnById, listingVariant, onSort ] ); return ( {checkable && ( )} { onSelectColumns?.(items); }} sortingStrategy={horizontalListSortingStrategy} updateSortableItemsOnItemsChange /> ); }; const columnMemoProps = [ 'id', 'label', 'rowMemoProps', 'sortField', 'sortOrder', 'sortable', 'type' ]; const MemoizedListingHeader = memo( ListingHeader, (prevProps, nextProps) => equals(prevProps.sortOrder, nextProps.sortOrder) && equals(prevProps.sortField, nextProps.sortField) && equals(prevProps.selectedRowCount, nextProps.selectedRowCount) && equals(prevProps.rowCount, nextProps.rowCount) && equals( map(pick(columnMemoProps as Array), prevProps.columns), map(pick(columnMemoProps as Array), nextProps.columns) ) && equals(prevProps.checkable, nextProps.checkable) && equals(prevProps.columnConfiguration, nextProps.columnConfiguration) && equals(prevProps.memoProps, nextProps.memoProps) && equals(prevProps.areColumnsEditable, nextProps.areColumnsEditable) && equals(prevProps.listingVariant, nextProps.listingVariant) ); export { MemoizedListingHeader as ListingHeader };