refactor(automations): replace error and notice displays with Alert components

This commit is contained in:
Anish Sarkar 2026-06-03 00:45:45 +05:30
parent c002f45c8e
commit eabbfb8c67
11 changed files with 88 additions and 72 deletions

View file

@ -53,7 +53,11 @@ export function RunDetailsPanel({
const isTerminal = liveStatus !== "pending" && liveStatus !== "running"; const isTerminal = liveStatus !== "pending" && liveStatus !== "running";
// Defer the REST round-trip until the run can actually carry heavy // Defer the REST round-trip until the run can actually carry heavy
// fields — output/artifacts/error are only written at terminal mark. // fields — output/artifacts/error are only written at terminal mark.
const { data: run, isLoading, error } = useAutomationRun(automationId, runId, { const {
data: run,
isLoading,
error,
} = useAutomationRun(automationId, runId, {
enabled: isTerminal, enabled: isTerminal,
}); });

View file

@ -4,6 +4,7 @@ import { AlertCircle, CalendarClock, Clock, Pencil, Save, Trash2 } from "lucide-
import { useState } from "react"; import { useState } from "react";
import { updateTriggerMutationAtom } from "@/atoms/automations/automations-mutation.atoms"; import { updateTriggerMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import { JsonView } from "@/components/json-view"; import { JsonView } from "@/components/json-view";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner"; import { Spinner } from "@/components/ui/spinner";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
@ -164,17 +165,19 @@ export function TriggerCard({ trigger, automationId, canUpdate, canDelete }: Tri
</div> </div>
{issues.length > 0 && ( {issues.length > 0 && (
<div className="rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2"> <Alert variant="destructive">
<div className="flex items-center gap-1.5 font-medium text-destructive mb-1"> <AlertCircle aria-hidden />
<AlertCircle className="h-3 w-3" aria-hidden /> <AlertTitle>
{issues.length === 1 ? "1 issue" : `${issues.length} issues`} {issues.length === 1 ? "1 issue" : `${issues.length} issues`}
</div> </AlertTitle>
<ul className="space-y-0.5 text-destructive list-disc list-inside"> <AlertDescription>
{issues.map((issue) => ( <ul className="list-inside list-disc">
<li key={issue}>{issue}</li> {issues.map((issue) => (
))} <li key={issue}>{issue}</li>
</ul> ))}
</div> </ul>
</AlertDescription>
</Alert>
)} )}
<div className="flex items-center justify-end gap-2"> <div className="flex items-center justify-end gap-2">

View file

@ -1,5 +1,6 @@
"use client"; "use client";
import { ShieldAlert } from "lucide-react"; import { AlertCircle, ShieldAlert } from "lucide-react";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { useAutomations } from "@/hooks/use-automations"; import { useAutomations } from "@/hooks/use-automations";
import { AutomationsEmptyState } from "./components/automations-empty-state"; import { AutomationsEmptyState } from "./components/automations-empty-state";
import { AutomationsHeader } from "./components/automations-header"; import { AutomationsHeader } from "./components/automations-header";
@ -60,9 +61,10 @@ export function AutomationsContent({ searchSpaceId }: AutomationsContentProps) {
loading={false} loading={false}
canCreate={perms.canCreate} canCreate={perms.canCreate}
/> />
<div className="rounded-lg border border-destructive/40 bg-destructive/5 px-6 py-8 text-center"> <Alert variant="destructive">
<p className="text-sm text-destructive">Couldn't load automations. {error.message}</p> <AlertCircle aria-hidden />
</div> <AlertDescription>Couldn't load automations. {error.message}</AlertDescription>
</Alert>
</> </>
); );
} }

View file

@ -1,5 +1,5 @@
"use client"; "use client";
import { MessageSquarePlus, SquarePen, Workflow } from "lucide-react"; import { Workflow } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@ -28,16 +28,14 @@ export function AutomationsEmptyState({ searchSpaceId, canCreate }: AutomationsE
{canCreate ? ( {canCreate ? (
<div className="mt-6 flex items-center justify-center gap-2 flex-wrap"> <div className="mt-6 flex items-center justify-center gap-2 flex-wrap">
<Button asChild> <Button asChild>
<Link href={`/dashboard/${searchSpaceId}/new-chat`}> <Link href={`/dashboard/${searchSpaceId}/new-chat`}>Create via chat</Link>
<MessageSquarePlus className="mr-2 h-4 w-4" />
Create via chat
</Link>
</Button> </Button>
<Button asChild variant="outline"> <Button
<Link href={`/dashboard/${searchSpaceId}/automations/new`}> asChild
<SquarePen className="mr-2 h-4 w-4" /> variant="ghost"
Create manually className="h-10 justify-start rounded-md bg-muted px-3 text-sm hover:bg-accent"
</Link> >
<Link href={`/dashboard/${searchSpaceId}/automations/new`}>Create manually</Link>
</Button> </Button>
</div> </div>
) : ( ) : (

View file

@ -1,5 +1,4 @@
"use client"; "use client";
import { MessageSquarePlus, SquarePen } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@ -41,17 +40,16 @@ export function AutomationsHeader({
</div> </div>
{canCreate && showCreateCta && ( {canCreate && showCreateCta && (
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Button asChild size="sm" variant="outline"> <Button
<Link href={`/dashboard/${searchSpaceId}/automations/new`}> asChild
<SquarePen className="mr-2 h-4 w-4" /> size="sm"
Create manually variant="ghost"
</Link> className="justify-start rounded-md bg-muted px-3 hover:bg-accent"
>
<Link href={`/dashboard/${searchSpaceId}/automations/new`}>Create manually</Link>
</Button> </Button>
<Button asChild size="sm"> <Button asChild size="sm">
<Link href={`/dashboard/${searchSpaceId}/new-chat`}> <Link href={`/dashboard/${searchSpaceId}/new-chat`}>Create via chat</Link>
<MessageSquarePlus className="mr-2 h-4 w-4" />
Create via chat
</Link>
</Button> </Button>
</div> </div>
)} )}

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import { Code2, LayoutList, Save } from "lucide-react"; import { AlertCircle, Code2, LayoutList, Save } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
@ -12,6 +12,7 @@ import {
updateAutomationMutationAtom, updateAutomationMutationAtom,
updateTriggerMutationAtom, updateTriggerMutationAtom,
} from "@/atoms/automations/automations-mutation.atoms"; } from "@/atoms/automations/automations-mutation.atoms";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Spinner } from "@/components/ui/spinner"; import { Spinner } from "@/components/ui/spinner";
@ -452,7 +453,12 @@ export function AutomationBuilderForm({
</div> </div>
)} )}
{rootError && <p className="text-right text-xs text-destructive">{rootError}</p>} {rootError && (
<Alert variant="destructive">
<AlertCircle aria-hidden />
<AlertDescription>{rootError}</AlertDescription>
</Alert>
)}
<div className="flex items-center justify-end gap-2"> <div className="flex items-center justify-end gap-2">
<Button asChild type="button" variant="ghost" size="sm"> <Button asChild type="button" variant="ghost" size="sm">

View file

@ -3,7 +3,7 @@
import { TriangleAlert } from "lucide-react"; import { TriangleAlert } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { memo, useId } from "react"; import { memo, useId } from "react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Alert, AlertDescription } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { import {
Select, Select,
@ -118,11 +118,11 @@ const ModelSelectField = memo(function ModelSelectField({
if (kind.options.length === 0) { if (kind.options.length === 0) {
return ( return (
<Field label={label}> <Field label={label}>
<Alert> <Alert variant="warning">
<TriangleAlert aria-hidden /> <TriangleAlert aria-hidden />
<AlertTitle>No eligible models</AlertTitle> <AlertDescription className="block leading-5">
<AlertDescription> <span className="font-medium text-foreground">No eligible models.</span> Automations
Automations need a premium or your own (BYOK) model. Set one up in{" "} need a premium or your own (BYOK) model. Set one up in{" "}
<Link href={rolesHref} className="font-medium underline underline-offset-2"> <Link href={rolesHref} className="font-medium underline underline-offset-2">
role settings role settings
</Link> </Link>

View file

@ -1,6 +1,7 @@
"use client"; "use client";
import { AlertCircle } from "lucide-react"; import { AlertCircle, TriangleAlert } from "lucide-react";
import { JsonView } from "@/components/json-view"; import { JsonView } from "@/components/json-view";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
interface JsonModePanelProps { interface JsonModePanelProps {
value: Record<string, unknown>; value: Record<string, unknown>;
@ -19,9 +20,10 @@ export function JsonModePanel({ value, issues, notice, onChange }: JsonModePanel
return ( return (
<div className="space-y-4"> <div className="space-y-4">
{notice && ( {notice && (
<div className="rounded-md border border-amber-500/40 bg-amber-500/5 px-3 py-2 text-xs text-amber-700 dark:text-amber-400"> <Alert variant="warning">
{notice} <TriangleAlert aria-hidden />
</div> <AlertDescription>{notice}</AlertDescription>
</Alert>
)} )}
<div className="rounded-md border border-input bg-background px-3 py-2 max-h-144 overflow-auto"> <div className="rounded-md border border-input bg-background px-3 py-2 max-h-144 overflow-auto">
@ -34,17 +36,17 @@ export function JsonModePanel({ value, issues, notice, onChange }: JsonModePanel
</div> </div>
{issues.length > 0 && ( {issues.length > 0 && (
<div className="rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2"> <Alert variant="destructive">
<div className="flex items-center gap-1.5 text-xs font-medium text-destructive mb-1.5"> <AlertCircle aria-hidden />
<AlertCircle className="h-3.5 w-3.5" aria-hidden /> <AlertTitle>{issues.length === 1 ? "1 issue" : `${issues.length} issues`}</AlertTitle>
{issues.length === 1 ? "1 issue" : `${issues.length} issues`} <AlertDescription>
</div> <ul className="list-inside list-disc">
<ul className="space-y-0.5 text-xs text-destructive list-disc list-inside"> {issues.map((issue) => (
{issues.map((issue) => ( <li key={issue}>{issue}</li>
<li key={issue}>{issue}</li> ))}
))} </ul>
</ul> </AlertDescription>
</div> </Alert>
)} )}
</div> </div>
); );

View file

@ -39,12 +39,12 @@ export function SidebarSection({
className className
)} )}
> >
<div className="flex items-center group/section shrink-0 px-2 py-1"> <div className="flex items-center group/section shrink-0 px-4 py-1">
<CollapsibleTrigger className="flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-accent-foreground transition-colors min-w-0"> <CollapsibleTrigger className="flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-accent-foreground transition-colors min-w-0">
<span className="truncate">{title}</span> <span className="truncate">{title}</span>
<ChevronRight <ChevronRight
className={cn( className={cn(
"h-3.5 w-3.5 shrink-0 transition-transform duration-200", "h-3.5 w-3.5 shrink-0 transition-[color,opacity,transform] duration-200 opacity-100 md:opacity-0 md:group-hover/section:opacity-100",
isOpen && "rotate-90" isOpen && "rotate-90"
)} )}
/> />

View file

@ -108,4 +108,4 @@ export function ChatExamplePrompts({ onSelect }: ChatExamplePromptsProps) {
) : null} ) : null}
</div> </div>
); );
} }

View file

@ -12,6 +12,7 @@ import {
import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms"; import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms";
import { JsonView } from "@/components/json-view"; import { JsonView } from "@/components/json-view";
import { TextShimmerLoader } from "@/components/prompt-kit/loader"; import { TextShimmerLoader } from "@/components/prompt-kit/loader";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { automationCreateRequest } from "@/contracts/types/automation.types"; import { automationCreateRequest } from "@/contracts/types/automation.types";
import type { HitlDecision, InterruptResult } from "@/features/chat-messages/hitl"; import type { HitlDecision, InterruptResult } from "@/features/chat-messages/hitl";
@ -351,19 +352,21 @@ function JsonEditor({ initialValue, onSave, onCancel }: JsonEditorProps) {
/> />
</div> </div>
{issues.length > 0 && ( {issues.length > 0 && (
<div className="rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2"> <Alert variant="destructive">
<div className="flex items-center gap-1.5 text-xs font-medium text-destructive"> <AlertCircle aria-hidden />
<AlertCircle className="h-3.5 w-3.5" aria-hidden /> <AlertTitle>
{issues.length} issue{issues.length === 1 ? "" : "s"} {issues.length} issue{issues.length === 1 ? "" : "s"}
</div> </AlertTitle>
<ul className="mt-1.5 space-y-0.5 text-xs text-destructive/90 list-disc list-inside"> <AlertDescription>
{issues.map((issue) => ( <ul className="list-inside list-disc">
<li key={issue} className="font-mono"> {issues.map((issue) => (
{issue} <li key={issue} className="font-mono">
</li> {issue}
))} </li>
</ul> ))}
</div> </ul>
</AlertDescription>
</Alert>
)} )}
<div className="flex items-center justify-end gap-2"> <div className="flex items-center justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={onCancel}> <Button type="button" variant="ghost" size="sm" onClick={onCancel}>