Skip to content

Commit

Permalink
feat: link to microsoft docs for error
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Sep 5, 2024
1 parent 19a8ae5 commit a1dbfc2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
36 changes: 36 additions & 0 deletions components/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
)

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
)
}

export { Badge, badgeVariants }
31 changes: 29 additions & 2 deletions components/workspace/format-errors.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { badgeVariants, Badge } from "@/components/ui/badge";
import Link from "next/link";

export function FormatErrors({ inputString }: { inputString: string }) {
// Detect and remove the dynamic path
const cleanedString = inputString.replace(
Expand Down Expand Up @@ -27,7 +30,7 @@ export function FormatErrors({ inputString }: { inputString: string }) {
</table>
);
} else {
return null;
return <p>No errors or warnings.</p>;
}
}

Expand All @@ -37,8 +40,32 @@ function ErrorMessage({ message }: { message: string }) {
return (
<tr className="border border-black">
<td className="p-2">{path}</td>
<td className="p-2">{type}</td>
<td className="p-2">
<ErrorTypeLink type={type} />
</td>
<td className="p-2">{description.join(" ")}</td>
</tr>
);
}

function ErrorTypeLink({ type }: { type: string }) {
const [kind, code] = type.split(" ");

if (kind === "warning") return <Badge variant="secondary">warning</Badge>;

if (kind === "error" && code.startsWith("CS"))
return (
<Link
className={badgeVariants({
variant: "destructive",
})}
href={`https://learn.microsoft.com/en-us/dotnet/csharp/misc/${code.toLowerCase()}`}
target="_blank"
rel="noopener noreferrer"
>
<span className="text-white">{code}</span>
</Link>
);

return null;
}

0 comments on commit a1dbfc2

Please sign in to comment.