import { ShareAssetType, VerificationStatus, BusterMetricListItem } from '@/api/asset_interfaces'; import { makeHumanReadble, formatDate } from '@/lib'; import React, { memo, useMemo, useRef, useState } from 'react'; import { StatusBadgeIndicator, getShareStatus } from '@/components/features/Lists'; import { BusterUserAvatar, Text } from '@/components/ui'; import { BusterRoutes, createBusterRoute } from '@/routes'; import { useMemoizedFn } from 'ahooks'; import { BusterListColumn, BusterListRow } from '@/components/ui/list'; import { MetricSelectedOptionPopup } from './MetricItemsSelectedPopup'; import { BusterList, ListEmptyStateWithButton } from '@/components/ui/list'; import { FavoriteStar } from '@/components/features/Lists'; import { useCreateListByDate } from '@/components/ui/list/useCreateListByDate'; export const MetricItemsContainer: React.FC<{ metrics: BusterMetricListItem[]; className?: string; openNewMetricModal: () => void; type: 'logs' | 'metrics'; loading: boolean; }> = ({ type, metrics = [], className = '', loading, openNewMetricModal }) => { const [selectedRowKeys, setSelectedRowKeys] = useState([]); const renderedDates = useRef>({}); const renderedOwners = useRef>({}); const tableContainerRef = useRef(null); const onSelectChange = useMemoizedFn((selectedRowKeys: string[]) => { setSelectedRowKeys(selectedRowKeys); }); const hasSelected = selectedRowKeys.length > 0; const logsRecord = useCreateListByDate({ data: metrics }); const metricsByDate: BusterListRow[] = useMemo(() => { return Object.entries(logsRecord).flatMap(([key, metrics]) => { const records = metrics.map((metric) => ({ id: metric.id, data: metric, link: createBusterRoute({ route: BusterRoutes.APP_METRIC_ID, metricId: metric.id }) })); const hasRecords = records.length > 0; if (!hasRecords) { return []; } return [ { id: key, data: {}, rowSection: { title: makeHumanReadble(key), secondaryTitle: String(records.length) } }, ...records ]; }); }, [logsRecord]); const columns: BusterListColumn[] = useMemo( () => [ { dataIndex: 'title', title: 'Title', render: (title, record) => ( ) }, { dataIndex: 'last_edited', title: 'Last updated', width: 132, render: (v) => { if (renderedDates.current[v]) { return renderedDates.current[v]; } const date = formatDate({ date: v, format: 'lll' }); renderedDates.current[v] = date; return date; } }, { dataIndex: 'dataset_name', title: 'Dataset', width: 115 }, { dataIndex: 'is_shared', title: 'Sharing', width: 65, render: (v) => getShareStatus({ is_shared: v }) }, { dataIndex: 'created_by_name', title: 'Owner', width: 45, render: (name, record) => { if (renderedOwners.current[name]) { return renderedOwners.current[name]; } const avatarCell = ( ); renderedOwners.current[name] = avatarCell; return avatarCell; } } ], [] ); return (
} />
); }; const EmptyState: React.FC<{ loading: boolean; type: 'logs' | 'metrics'; openNewMetricModal: () => void; }> = React.memo(({ loading, type, openNewMetricModal }) => { if (loading) { return <>; } return ; }); EmptyState.displayName = 'EmptyState'; const MetricsEmptyState: React.FC<{ openNewMetricModal: () => void; type: 'logs' | 'metrics'; }> = ({ openNewMetricModal, type }) => { if (type === 'logs') { return ( ); } return ( ); }; const TitleCell = React.memo<{ title: string; status: VerificationStatus; metricId: string }>( ({ title, status, metricId }) => { const onFavoriteDivClick = useMemoizedFn((e: React.MouseEvent) => { e.stopPropagation(); }); return (
{title}
); } ); TitleCell.displayName = 'TitleCell'; const OwnerCell = memo<{ name: string; image: string | null | undefined }>(({ name, image }) => (
)); OwnerCell.displayName = 'OwnerCell';