import { Box, Checkbox, IconButton, Link, Skeleton, TableCell, TableRow, Tooltip } from "@mui/material"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link as RouterLink } from "react-router-dom"; import { getEntityUrl } from "../../../api/api"; import { Entity } from "../../../api/dashboard"; import { EntityType } from "../../../api/explorer"; import { useAppDispatch } from "../../../redux/hooks"; import { sizeToString } from "../../../util"; import { NoWrapTableCell, NoWrapTypography, SquareChip } from "../../Common/StyledComponents"; import TimeBadge from "../../Common/TimeBadge"; import UserAvatar from "../../Common/User/UserAvatar"; import { cipherDisplayName } from "../../FileManager/Sidebar/BasicInfo"; import { EntityTypeText } from "../../FileManager/Sidebar/Data"; import Delete from "../../Icons/Delete"; import Download from "../../Icons/Download"; import ShieldLock from "../../Icons/ShieldLock"; export interface EntityRowProps { entity?: Entity; loading?: boolean; selected?: boolean; onDelete?: (id: number) => void; onSelect?: (id: number) => void; openEntityDialog?: (id: number) => void; openUserDialog?: (id: number) => void; } const EntityRow = ({ entity, loading, selected, onDelete, onSelect, openUserDialog, openEntityDialog, }: EntityRowProps) => { const { t } = useTranslation("dashboard"); const dispatch = useAppDispatch(); const [deleteLoading, setDeleteLoading] = useState(false); const [openLoading, setOpenLoading] = useState(false); const onSelectClick = (e: React.MouseEvent) => { e.stopPropagation(); e.preventDefault(); onSelect?.(entity?.id ?? 0); }; const onOpenClick = (e: React.MouseEvent) => { e.stopPropagation(); setOpenLoading(true); dispatch(getEntityUrl(entity?.id ?? 0)) .then((url) => { // 直接下载文件:使用a标签的download属性强制下载 const link = document.createElement("a"); link.href = url; link.download = `entity-${entity?.id}`; link.style.display = "none"; document.body.appendChild(link); link.click(); document.body.removeChild(link); }) .finally(() => { setOpenLoading(false); }) .catch((error) => { console.error("Failed to get entity URL:", error); }); }; const userClicked = (e: React.MouseEvent) => { e.stopPropagation(); e.preventDefault(); openUserDialog?.(entity?.edges?.user?.id ?? 0); }; const onDeleteClick = (e: React.MouseEvent) => { e.stopPropagation(); e.preventDefault(); onDelete?.(entity?.id ?? 0); }; if (loading) { return ( ); } return ( openEntityDialog?.(entity?.id ?? 0)} selected={selected} > {entity?.id} {t(EntityTypeText[entity?.type ?? EntityType.version])} {entity?.source || "-"} {!entity?.reference_count && } {entity?.props?.encrypt_metadata?.algorithm && ( theme.palette.success.main, }} /> )} {sizeToString(entity?.size ?? 0)} {entity?.edges?.storage_policy?.name || "-"} {entity?.reference_count ?? 0} {entity?.edges?.user?.nick || "-"} ); }; export default EntityRow;