import React from 'react';
import DataTable from '@gravity-ui/react-data-table';
import {Button, Flex, HelpMark, Label, Progress, Text} from '@gravity-ui/uikit';
import {EntityName} from '../../../../components/EntityName/EntityName';
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
import type {StorageUsageGroupRow} from '../../../../store/reducers/storageUsage/StorageUsage';
import {cn} from '../../../../utils/cn';
import {TENANT_OVERVIEW_TABLES_SETTINGS} from '../../../../utils/constants';
import {formatNumber} from '../../../../utils/dataFormatters/dataFormatters';
import type {Column} from '../../../../utils/tableUtils/types';
import {StatsWrapper} from '../TenantOverview/StatsWrapper/StatsWrapper';
import i18n from '../i18n';
import {
STORAGE_USAGE_INITIAL_ROWS_COUNT,
formatMetricBytes,
formatShare,
getSharePercent,
} from './storageUsageFormatters';
import './StorageUsageTable.scss';
const b = cn('ydb-storage-usage-table');
const STORAGE_USAGE_COLUMN_WIDTHS = {
groupId: 152,
used: 130,
limit: 130,
share: 200,
} as const;
const STORAGE_USAGE_COLUMNS_IDS = {
groupId: 'groupId',
used: 'used',
limit: 'limit',
share: 'share',
} as const;
interface StorageUsageTableProps {
getStorageGroupPath: (groupId: string) => string;
hasMultipleMediaTypes: boolean;
hiddenRowsCount: number;
onShowMore: () => void;
rows: StorageUsageGroupRow[];
storageGroupsCount?: number;
visibleRows: StorageUsageGroupRow[];
}
function HeaderWithHelp({text, note}: {text: string; note?: string}) {
return (
{text}
{note ? {note} : null}
);
}
function renderStorageGroupName(name?: string) {
return (
{name ?? ''}
);
}
function getFixedColumnStyle(width: number) {
return {
width,
minWidth: width,
maxWidth: width,
};
}
function StorageGroupCell({
groupId,
erasure,
hasMultipleMediaTypes,
mediaType,
getStorageGroupPath,
}: Pick & {
getStorageGroupPath: (groupId: string) => string;
hasMultipleMediaTypes: boolean;
}) {
return (
{hasMultipleMediaTypes && mediaType ? (
) : null}
{erasure ? (
{erasure}
) : null}
);
}
function ShareCell({share}: Pick) {
const sharePercent = getSharePercent(share);
return (
{formatShare(share)}
);
}
export function StorageUsageTable({
getStorageGroupPath,
hasMultipleMediaTypes,
hiddenRowsCount,
onShowMore,
rows,
storageGroupsCount,
visibleRows,
}: StorageUsageTableProps) {
const columns = React.useMemo[]>(() => {
return [
{
name: STORAGE_USAGE_COLUMNS_IDS.groupId,
header: i18n('field_storage-usage-group'),
width: STORAGE_USAGE_COLUMN_WIDTHS.groupId,
customStyle: () => getFixedColumnStyle(STORAGE_USAGE_COLUMN_WIDTHS.groupId),
align: DataTable.LEFT,
resizeable: false,
render: ({row}) => (
),
},
{
name: STORAGE_USAGE_COLUMNS_IDS.used,
header: (
),
width: STORAGE_USAGE_COLUMN_WIDTHS.used,
customStyle: () => getFixedColumnStyle(STORAGE_USAGE_COLUMN_WIDTHS.used),
align: DataTable.LEFT,
resizeable: false,
render: ({row}) => (
{formatMetricBytes(row.used)}
),
},
{
name: STORAGE_USAGE_COLUMNS_IDS.limit,
header: (
),
width: STORAGE_USAGE_COLUMN_WIDTHS.limit,
customStyle: () => getFixedColumnStyle(STORAGE_USAGE_COLUMN_WIDTHS.limit),
align: DataTable.LEFT,
resizeable: false,
render: ({row}) => (
{formatMetricBytes(row.limit)}
),
},
{
name: STORAGE_USAGE_COLUMNS_IDS.share,
header: (
),
width: STORAGE_USAGE_COLUMN_WIDTHS.share,
customStyle: () => getFixedColumnStyle(STORAGE_USAGE_COLUMN_WIDTHS.share),
align: DataTable.LEFT,
resizeable: false,
render: ({row}) => ,
},
];
}, [getStorageGroupPath, hasMultipleMediaTypes]);
if (rows.length === 0) {
return null;
}
return (
{i18n('title_storage-usage-storage-groups-usage')}
{formatNumber(storageGroupsCount) || '0'}
{hiddenRowsCount > 0 ? (
) : null}
);
}