import type { ElementType, ReactNode } from 'react';
import React from 'react';
import cx from 'classnames';
import { Portal } from 'ariakit/portal';
import type { MetricRunInfo, ReportMetricRow, ReportMetricRun } from '@bundle-stats/utils';
import { METRIC_TYPE_CONFIGS, getMetricRunInfo } from '@bundle-stats/utils';
import { Box } from '../../layout/box';
import { FlexStack } from '../../layout/flex-stack';
import { Stack } from '../../layout/stack';
import { FileName } from '../../ui/file-name';
import { Button } from '../../ui/button';
import { Icon } from '../../ui/icon';
import { Table } from '../../ui/table';
import { RunInfo } from '../run-info';
import * as I18N from './entry-info.i18n';
import css from './entry-info.module.css';
import { CopyToClipboard, Tooltip } from '../../ui';
interface EntryInfoMetaLinkProps {
as?: ElementType;
}
export const EntryInfoMetaLink = (props: EntryInfoMetaLinkProps & React.ComponentProps<'a'>) => {
const { as: BaseComponent = 'a', className = '', ...restProps } = props;
return ;
};
interface EntryInfoMetaProps {
label: string;
tooltip?: ReactNode;
}
const EntryInfoMeta = ({
className = '',
label,
tooltip,
children,
}: EntryInfoMetaProps & React.ComponentProps<'p'>) => (
{label}
{tooltip && (
)}
{children}
);
function defaultRenderRunInfo(item: ReportMetricRow) {
const baselineRun = item.runs.length > 1 ? item.runs?.[item.runs.length - 1] : null;
// Get the metric run info to handle added/removed cases when there are more than 2 jobs
const metricRunInfo = getMetricRunInfo(
METRIC_TYPE_CONFIGS.METRIC_TYPE_FILE_SIZE,
item.runs?.[0]?.value || 0,
baselineRun?.value || 0,
) as MetricRunInfo;
return (
);
}
export type RenderRunNameProps = {
className?: string;
run: T;
runSelector: string;
};
interface EntryInfoProps {
itemTitle?: React.ReactNode;
item: ReportMetricRow;
labels: Array;
runNameSelector?: string;
runNameLabel?: string;
runSizeLabel?: string;
tags?: React.ReactNode;
onClose: () => void;
renderRunInfo?: (item: ReportMetricRow) => React.ReactNode;
RunName?: React.ElementType;
}
export const EntryInfo = (props: EntryInfoProps & React.ComponentProps<'div'>) => {
const {
className = '',
itemTitle = null,
item,
labels,
runNameSelector = 'name',
runNameLabel = I18N.PATH,
runSizeLabel = I18N.SIZE,
tags = null,
onClose,
renderRunInfo = defaultRenderRunInfo,
RunName = React.Fragment,
children,
} = props;
return (
{renderRunInfo(item)}
{tags && {tags}
}
{children}
{runNameLabel}
{runSizeLabel}
{item.runs.map((run, index) => {
const key = `info-${run?.name || index}-${index}`;
const rowRun = run as any;
return (
{labels[index]}
{rowRun?.[runNameSelector] ? (
) : (
'-'
)}
{typeof run?.value !== 'undefined' ? run.value : '-'}
);
})}
);
};
EntryInfo.Meta = EntryInfoMeta;