Skip to content

Automate browser based workflows with AI

4.6 KB
Raw Blame
import { Cross2Icon, ReloadIcon } from "@radix-ui/react-icons";

import { Label } from "@/components/ui/label";
import { TooltipProvider } from "@/components/ui/tooltip";
import { ControlTooltip } from "@/routes/workflows/studio/ControlTooltip";
import type { CodeBlockStep } from "@/routes/workflows/types/workflowTypes";
import { getCodeStepPlainText } from "@/routes/workflows/workflowBlockUtils";
import { cn } from "@/util/utils";

import {
  getStepChipClassName,
  getStepIcon,
  getStepLabel,
} from "./stepPresentation";

type Props = {
  steps: Array<CodeBlockStep>;
  generating?: boolean;
  onStop?: () => void;
  stopBlockedReason?: string | null;
};

function CodeBlockPlainCard({
  steps,
  generating = false,
  onStop,
  stopBlockedReason = null,
}: Props) {
  return (
    <div data-testid="code-block-plain-card" className="space-y-2">
      <div className="flex items-center justify-between gap-2">
        <Label className="text-xs text-tertiary-foreground">Steps</Label>
        {generating ? (
          <div className="flex items-center gap-2 text-xs text-muted-foreground">
            <span className="flex items-center gap-1">
              <ReloadIcon className="size-3 animate-spin" />
              Generating…
            </span>
            {onStop && (
              <TooltipProvider>
                <ControlTooltip
                  content={stopBlockedReason ?? "Stop generating"}
                  blocked={stopBlockedReason !== null}
                >
                  <button
                    type="button"
                    onClick={onStop}
                    disabled={stopBlockedReason !== null}
                    className="nodrag nopan flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-tertiary-foreground hover:bg-slate-elevation2 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
                  >
                    <Cross2Icon className="size-3" />
                    Stop
                  </button>
                </ControlTooltip>
              </TooltipProvider>
            )}
          </div>
        ) : (
          steps.length > 0 && (
            <span className="shrink-0 text-xs tabular-nums text-muted-foreground">
              {steps.length} {steps.length === 1 ? "step" : "steps"}
            </span>
          )
        )}
      </div>
      {generating ? (
        <ol className="space-y-1.5" aria-busy="true">
          {[0, 1, 2].map((index) => (
            <li
              key={index}
              className="flex items-center gap-2.5 rounded-md border border-border/60 bg-slate-elevation1 px-2.5 py-2"
            >
              <div className="size-7 shrink-0 animate-pulse rounded-md bg-slate-elevation2" />
              <div className="min-w-0 flex-1 space-y-1.5">
                <div className="h-3 w-2/3 animate-pulse rounded bg-slate-elevation2" />
                <div className="h-2.5 w-1/3 animate-pulse rounded bg-slate-elevation2" />
              </div>
            </li>
          ))}
        </ol>
      ) : steps.length === 0 ? (
        <p className="rounded-md border border-dashed border-border/70 px-3 py-4 text-xs text-muted-foreground">
          No steps yet. Steps appear once Skyvern generates them.
        </p>
      ) : (
        <ol className="space-y-1.5">
          {steps.map((step, index) => {
            const plainText = getCodeStepPlainText(step);
            return (
              <li
                key={index}
                className="flex items-start gap-2.5 rounded-md border border-border/60 bg-slate-elevation1 px-2.5 py-2"
              >
                <div
                  className={cn(
                    "flex size-7 shrink-0 items-center justify-center rounded-md",
                    getStepChipClassName(step.action_type),
                  )}
                >
                  {getStepIcon(step.action_type)}
                </div>
                <div className="min-w-0 flex-1">
                  <div
                    className="truncate text-xs font-medium text-foreground"
                    title={plainText}
                  >
                    {plainText}
                  </div>
                  <div className="mt-0.5 text-[11px] text-muted-foreground">
                    {getStepLabel(step.action_type)}
                  </div>
                </div>
                <span className="shrink-0 text-[11px] tabular-nums text-muted-foreground dark:text-slate-500">
                  {index + 1}
                </span>
              </li>
            );
          })}
        </ol>
      )}
    </div>
  );
}

export { CodeBlockPlainCard };