import { NodeViewWrapper } from "@tiptap/react"; import { Avatar, Badge, Text } from "@mantine/core"; import { memo } from "react"; import { useTranslation } from "react-i18next"; import { getIntegrationIcon } from "@/features/integration/components/integration-icons"; import { useUnfurl } from "./use-unfurl"; import { badgeTextColor, toBadgeColor } from "./badge-color"; import classes from "./integration-link-view.module.css"; function shortUrl(url: string): string { try { const parsed = new URL(url); return `${parsed.host}${parsed.pathname}`; } catch { return url; } } function IntegrationMentionView(props: any) { const { node, updateAttributes } = props; const { url, provider, unfurlData, status } = node.attrs; const { t } = useTranslation(); useUnfurl(url, status, updateAttributes); const data = unfurlData; const meta = data?.metadata ?? {}; const isSlackMessage = provider === "slack" && (meta.type === "message" || (!meta.type && meta.ts)); const issueNumber = meta.iid ?? meta.number; const typeLabel = meta.type === "project" ? t("Project") : meta.type === "initiative" ? t("Initiative") : null; const statusBadge = data?.status ? ( {data.status} ) : null; let content; if (!data) { // pending / error / needs-connection: a compact link chip content = ( <> {getIntegrationIcon(provider, 14)} {shortUrl(url)} ); } else if (isSlackMessage) { content = ( <> {(data.author ?? "?").charAt(0)} {data.author && ( {data.author} )} {(data.description ?? "").split("\n")[0] || shortUrl(url)} {getIntegrationIcon("slack", 14)} {data.status && ( {data.status} )} ); } else if (meta.issueKey) { // Jira: type icon leads, provider icon trails. content = ( <> {meta.issueTypeIconUrl ? ( ) : ( getIntegrationIcon(provider, 14) )} {meta.issueKey} {data.title} {statusBadge} {meta.issueTypeIconUrl && getIntegrationIcon(provider, 14)} ); } else if (issueNumber) { content = ( <> {getIntegrationIcon(provider, 14)} #{issueNumber} {data.title} {statusBadge} ); } else if (typeLabel) { content = ( <> {getIntegrationIcon(provider, 14)} {typeLabel} {data.title} {statusBadge} ); } else { content = ( <> {getIntegrationIcon(provider, 14)} {data.title || shortUrl(url)} {statusBadge} ); } return ( {content} ); } export default memo(IntegrationMentionView);