"use client"; import { Badge } from "@kandev/ui/badge"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@kandev/ui/dialog"; import { Separator } from "@kandev/ui/separator"; import type { AzureDevOpsPullRequestFeedback } from "@/lib/types/azure-devops"; import { useTranslation } from "react-i18next"; /** `vote` is Azure DevOps' numeric vote; only the catalog key is copy. */ function voteLabelKey(vote: number): string { if (vote >= 10) return "azuredevops:voteApproved"; if (vote >= 5) return "azuredevops:voteApprovedWithSuggestions"; if (vote <= -10) return "azuredevops:voteRejected"; if (vote <= -5) return "azuredevops:voteWaitingForAuthor"; return "azuredevops:voteNone"; } function Summary({ feedback }: { feedback: AzureDevOpsPullRequestFeedback }) { const { t } = useTranslation(); return (
{t("azuredevops:reviewLabelled", { state: feedback.reviewState || t("azuredevops:pending"), })} {t("azuredevops:policiesLabelled", { state: feedback.policyState || t("azuredevops:none"), })} {t("azuredevops:linkedItemsCount", { count: feedback.linkedWorkItems.length })}
); } function Reviewers({ feedback }: { feedback: AzureDevOpsPullRequestFeedback }) { const { t } = useTranslation(); return (

{t("azuredevops:reviewers")}

{feedback.reviewers.length === 0 ? (

{t("azuredevops:noReviewers")}

) : (
{feedback.reviewers.map((reviewer) => (
{reviewer.displayName} {t(voteLabelKey(reviewer.vote))}
))}
)}
); } function Policies({ feedback }: { feedback: AzureDevOpsPullRequestFeedback }) { const { t } = useTranslation(); return (

{t("azuredevops:branchPolicies")}

{feedback.policies.length === 0 ? (

{t("azuredevops:noPolicyEvaluations")}

) : (
{feedback.policies.map((policy) => (
{policy.name} {policy.status}
))}
)}
); } function Threads({ feedback }: { feedback: AzureDevOpsPullRequestFeedback }) { const { t } = useTranslation(); const comments = feedback.threads.flatMap((thread) => thread.comments.map((comment) => ({ ...comment, threadId: thread.id })), ); return (

{t("azuredevops:discussion")}

{comments.length === 0 ? (

{t("azuredevops:noComments")}

) : (
{comments.map((comment) => (
{comment.author.displayName}

{comment.content}

))}
)}
); } export function AzureDevOpsFeedbackDialog({ open, loading, error, feedback, onOpenChange, }: { open: boolean; loading: boolean; error: string | null; feedback: AzureDevOpsPullRequestFeedback | null; onOpenChange: (open: boolean) => void; }) { const { t } = useTranslation(); return ( {feedback?.pullRequest.title ?? t("azuredevops:pullRequestFeedback")} {feedback ? // The repository name and id are provider data; the `PR` label // and the separator around them are not, so this is a message // with the data interpolated rather than a bare template. t("azuredevops:pullRequestSubtitle", { repository: feedback.pullRequest.repositoryName, id: feedback.pullRequest.id, }) : t("azuredevops:azureDevopsReviewAndPolicyState")} {loading && (

{t("azuredevops:loadingFeedback")}

)} {error && (

{error}

)} {feedback && (
)}
); }