import type { IRoom, Serialized } from '@rocket.chat/core-typings'; import { Box, CheckBox } from '@rocket.chat/fuselage'; import { GenericTable, GenericTableHeaderCell, GenericTableHeader, GenericTableBody, useSort } from '@rocket.chat/ui-client'; import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import ChannelDesertionTableRow from './ChannelDesertionTableRow'; export type ChannelDesertionTableProps = { lastOwnerWarning?: string; rooms?: (Serialized & { isLastOwner?: boolean })[]; eligibleRoomsLength: number | undefined; onChangeRoomSelection: (room: Serialized) => void; selectedRooms: { [key: string]: Serialized }; onToggleAllRooms: () => void; }; const ChannelDesertionTable = ({ rooms, eligibleRoomsLength, onChangeRoomSelection, selectedRooms, onToggleAllRooms, lastOwnerWarning, }: ChannelDesertionTableProps) => { const { sortBy, sortDirection, setSort } = useSort<'name' | 'ts'>('name'); const { t } = useTranslation(); const selectedRoomsLength = Object.values(selectedRooms).filter(Boolean).length; const checked = eligibleRoomsLength === selectedRoomsLength; const indeterminate = eligibleRoomsLength && eligibleRoomsLength > selectedRoomsLength ? selectedRoomsLength > 0 : false; const results = useMemo(() => { if (!rooms) { return []; } const direction = sortDirection === 'asc' ? 1 : -1; return rooms.toSorted((a, b) => { const aValue = a[sortBy] ?? ''; const bValue = b[sortBy] ?? ''; if (!aValue && !bValue) { return 0; } if (!aValue) { return 1; } if (!bValue) { return -1; } return aValue.localeCompare(bValue) * direction; }); }, [rooms, sortBy, sortDirection]); return ( {t('Channel_name')} {t('Joined_at')} {results?.map((room, key) => ( ))} ); }; export default ChannelDesertionTable;