import React from 'react';
// @ts-expect-error FIXME: update react-table
import ReactTable from 'react-table';
import round from 'lodash/round';
import { withTranslation, Trans } from 'react-i18next';
import { TFunction } from 'i18next';
import Card from '../ui/Card';
import DomainCell from './DomainCell';
import { DASHBOARD_TABLES_DEFAULT_PAGE_SIZE, TABLES_MIN_ROWS } from '../../helpers/constants';
import { formatNumber } from '../../helpers/helpers';
interface TimeCellProps {
value?: string | number;
}
const TimeCell = ({ value }: TimeCellProps) => {
if (!value) {
return '–';
}
const valueInMilliseconds = formatNumber(round(Number(value) * 1000));
return (
{valueInMilliseconds} ms
);
};
interface UpstreamAvgTimeProps {
topUpstreamsAvgTime: { name: string; count: number }[];
refreshButton: React.ReactNode;
subtitle: string;
t: TFunction;
}
const UpstreamAvgTime = ({ t, refreshButton, topUpstreamsAvgTime, subtitle }: UpstreamAvgTimeProps) => (
({
domain,
count,
}))}
columns={[
{
Header: upstream,
accessor: 'domain',
Cell: DomainCell,
},
{
Header: response_time,
accessor: 'count',
maxWidth: 190,
Cell: TimeCell,
},
]}
showPagination={false}
noDataText={t('no_upstreams_data_found')}
minRows={TABLES_MIN_ROWS}
defaultPageSize={DASHBOARD_TABLES_DEFAULT_PAGE_SIZE}
className="-highlight card-table-overflow--limited stats__table"
/>
);
export default withTranslation()(UpstreamAvgTime);