import { Box, Pagination, Skeleton, Table, Flex, Tile, Scrollable } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import React, { useMemo, useState, useEffect, useCallback, forwardRef } from 'react';
import flattenChildren from 'react-keyed-flatten-children';
import { useTranslation } from '../contexts/TranslationContext';
function SortIcon({ direction }) {
return
;
}
export function Th({ children, active, direction, sort, onClick, align, ...props }) {
const fn = useMemo(() => () => onClick && onClick(sort), [sort, onClick]);
return
{children}{sort && }
;
}
const LoadingRow = ({ cols }) =>
{ Array.from({ length: cols - 1 }, (_, i) =>
)}
;
export const GenericTable = forwardRef(function GenericTable({
children,
results,
total,
renderRow: RenderRow,
header,
setParams = () => { },
params: paramsDefault = '',
FilterComponent = () => null,
}, ref) {
const t = useTranslation();
const [filter, setFilter] = useState(paramsDefault);
const [itemsPerPage, setItemsPerPage] = useState(25);
const [current, setCurrent] = useState(0);
const params = useDebouncedValue(filter, 500);
useEffect(() => {
setParams({ ...params, current, itemsPerPage });
}, [params, current, itemsPerPage, setParams]);
const Loading = useCallback(() => {
const headerCells = flattenChildren(header);
return Array.from({ length: 10 }, (_, i) => );
}, [header]);
const showingResultsLabel = useCallback(({ count, current, itemsPerPage }) => t('Showing results %s - %s of %s', current + 1, Math.min(current + itemsPerPage, count), count), [t]);
const itemsPerPageLabel = useCallback(() => t('Items_per_page:'), [t]);
return <>
{results && !results.length
?
{t('No_data_found')}
: <>
{header &&
{header}
}
{RenderRow && (
results
? results.map((props, index) => )
:
)}
{children && (results ? results.map(children) : )}
>
}
>;
});
export default Object.assign(GenericTable, {
HeaderCell: Th,
});