import prettierBytes from '@transloadit/prettier-bytes' import type { UppyFile } from '@uppy/core' import type { I18n } from '@uppy/utils' import { truncateString } from '@uppy/utils' import type { DashboardState } from '../../../Dashboard.js' import MetaErrorMessage from '../MetaErrorMessage.js' const renderFileName = (props: { file: UppyFile isSingleFile: boolean containerHeight: number containerWidth: number }) => { const { author, name } = props.file.meta function getMaxNameLength() { if (props.isSingleFile && props.containerHeight >= 350) { return 90 } if (props.containerWidth <= 352) { return 35 } if (props.containerWidth <= 576) { return 60 } // When `author` is present, we want to make sure // the file name fits on one line so we can place // the author on the second line. return author ? 20 : 30 } return (
{truncateString(name, getMaxNameLength())}
) } const renderAuthor = (props: { file: UppyFile }) => { const { author } = props.file.meta const providerName = 'remote' in props.file ? props.file.remote?.providerName : undefined const dot = `\u00B7` if (!author) { return null } return (
{truncateString(author.name, 13)} {providerName ? ( <> {` ${dot} `} {providerName} {` ${dot} `} ) : null}
) } const renderFileSize = (props: { file: UppyFile }) => props.file.size && (
{prettierBytes(props.file.size)}
) const ReSelectButton = (props: { file: UppyFile toggleAddFilesPanel: (show: boolean) => void i18n: I18n }) => props.file.isGhost && ( {' \u2022 '} ) const ErrorButton = ({ file, onClick, }: { file: UppyFile onClick: () => void }) => { if (file.error) { return ( ) } return null } type FileInfoProps = { file: UppyFile containerWidth: number containerHeight: number i18n: I18n toggleAddFilesPanel: (show: boolean) => void toggleFileCard: (show: boolean, fileId: string) => void metaFields: DashboardState['metaFields'] isSingleFile: boolean } export default function FileInfo(props: FileInfoProps) { const { file, i18n, toggleFileCard, metaFields, toggleAddFilesPanel, isSingleFile, containerHeight, containerWidth, } = props return (
{renderFileName({ file, isSingleFile, containerHeight, containerWidth, })} {} alert(file.error)} />
{renderAuthor({ file })} {renderFileSize({ file })} {ReSelectButton({ file, toggleAddFilesPanel, i18n })}
) }