47 行
1.8 KiB
TypeScript
47 行
1.8 KiB
TypeScript
import type { ComponentPropsWithoutRef } from "react";
|
|
import {
|
|
ATTACHMENT_TYPE_LABEL,
|
|
GOVERNANCE_STATUS_LABEL,
|
|
SENSITIVITY_LEVEL_LABEL,
|
|
attachmentRequiresDownloadReason,
|
|
type AttachmentGovernanceFields,
|
|
} from "../../lib/attachmentGovernance";
|
|
import { cn } from "../../lib/utils";
|
|
|
|
function governanceStatusClass(value: string) {
|
|
if (value === "approved" || value === "archived") return "badge-success";
|
|
if (value === "pending_review" || value === "under_approval" || value === "returned") return "badge-warning";
|
|
if (value === "rejected" || value === "quarantined") return "badge-error";
|
|
return "badge-neutral";
|
|
}
|
|
|
|
function sensitivityClass(value: string) {
|
|
if (value === "restricted") return "badge-error";
|
|
if (value === "confidential") return "badge-warning";
|
|
if (value === "index_only") return "badge-neutral";
|
|
return "badge-neutral";
|
|
}
|
|
|
|
export function AttachmentGovernanceBadges({
|
|
attachment,
|
|
className,
|
|
...props
|
|
}: ComponentPropsWithoutRef<"div"> & {
|
|
attachment: Pick<AttachmentGovernanceFields, "governanceStatus" | "sensitivityLevel" | "attachmentType" | "downloadPolicy">;
|
|
}) {
|
|
return (
|
|
<div className={cn("flex flex-wrap items-center gap-1.5", className)} {...props}>
|
|
<span className={governanceStatusClass(attachment.governanceStatus)}>
|
|
{GOVERNANCE_STATUS_LABEL[attachment.governanceStatus] ?? attachment.governanceStatus}
|
|
</span>
|
|
<span className="badge-neutral">
|
|
{ATTACHMENT_TYPE_LABEL[attachment.attachmentType] ?? attachment.attachmentType}
|
|
</span>
|
|
<span className={sensitivityClass(attachment.sensitivityLevel)}>
|
|
{SENSITIVITY_LEVEL_LABEL[attachment.sensitivityLevel] ?? attachment.sensitivityLevel}
|
|
</span>
|
|
{attachmentRequiresDownloadReason(attachment) ? <span className="badge-warning">下载需说明用途</span> : null}
|
|
</div>
|
|
);
|
|
}
|