Files
supabase/apps/studio/components/interfaces/BranchManagement/WorkflowLogsCard.tsx
Gildas Garcia 96d43099bb chore: refactor Button API so that it can be used a standard button (#46880)
## Problem

Our `<Button>` component breaks the default `button` contract by
redefining the `type` prop to set its variant (`primary`, `default`,
etc) instead of the button type (`submit`, `button`, etc).
This is confusing and forces to write more code when using it with
shadcn components that expect/inject the standard button props.

## Solution

- rename the `type` prop to `variant`
- rename the `htmlType` prop to `type`
- propagate the changes where necessary
- format code

## How to test

As this is just prop renaming, if it builds it's ok

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2026-06-16 23:59:58 +02:00

113 lines
3.5 KiB
TypeScript

import { motion } from 'framer-motion'
import { CircleDotDashed, GitMerge, X } from 'lucide-react'
import { useEffect, useRef } from 'react'
import { Button, Card, CardContent, CardHeader, CardTitle } from 'ui'
import { ActionRun } from '@/data/actions/action-detail-query'
interface WorkflowLogsCardProps {
workflowRun: ActionRun | null | undefined
logs: string | undefined
isLoading?: boolean
onClose?: () => void
// Override props for failed workflows
overrideTitle?: string
overrideDescription?: string
overrideIcon?: React.ReactNode
overrideAction?: React.ReactNode
}
export const WorkflowLogsCard = ({
workflowRun,
logs,
isLoading = false,
onClose,
overrideTitle,
overrideDescription,
overrideIcon,
overrideAction,
}: WorkflowLogsCardProps) => {
const scrollRef = useRef<HTMLDivElement>(null)
// Auto-scroll to bottom when logs change
useEffect(() => {
if (scrollRef.current && logs) {
scrollRef.current.scrollTop = scrollRef.current.scrollHeight
}
}, [logs])
const workflowRunStatus = workflowRun?.status
const isSuccess = workflowRunStatus === 'SUCCESS'
const isFailed = workflowRunStatus === 'FAILED'
const isPolling = workflowRunStatus === 'RUNNING'
const displayTitle =
overrideTitle ||
(isPolling
? 'Processing...'
: isSuccess
? 'Workflow completed successfully'
: isFailed
? 'Workflow failed'
: 'Workflow completed')
const displayIcon =
overrideIcon ||
(isPolling ? (
<motion.div
animate={{ rotate: 360 }}
transition={{ duration: 2, repeat: Infinity, ease: 'linear' }}
>
<CircleDotDashed size={16} strokeWidth={1.5} className="text-warning" />
</motion.div>
) : isSuccess ? (
<GitMerge size={16} strokeWidth={1.5} className="text-brand" />
) : null)
return (
<Card className="bg-background overflow-hidden h-64 flex flex-col">
<CardHeader className={isSuccess ? 'text-brand' : isFailed ? 'text-destructive' : ''}>
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
{displayIcon}
<div>
<CardTitle className="text-sm font-medium">{displayTitle}</CardTitle>
{overrideDescription && (
<div className="text-sm text-foreground-light font-normal mt-0">
{overrideDescription}
</div>
)}
</div>
</div>
<div className="flex items-center gap-4">
{overrideAction}
{onClose && (
<Button
variant="text"
size="tiny"
icon={<X size={12} strokeWidth={1.5} />}
onClick={onClose}
className="h-5 w-5 p-0"
/>
)}
</div>
</div>
</CardHeader>
<CardContent
ref={scrollRef}
className="overflow-hidden border-0 overflow-y-auto relative p-0"
>
{/* sticky gradient overlay */}
<div className="sticky top-0 -mb-8 h-8 bg-linear-to-b from-background to-transparent pointer-events-none z-10" />
{logs ? (
<pre className="p-6 text-xs text-foreground-light p-0 rounded-sm">{logs}</pre>
) : (
<pre className="p-6 text-sm text-foreground-light rounded-sm">
{isLoading || isPolling ? 'Initializing workflow...' : 'Waiting for logs...'}
</pre>
)}
</CardContent>
</Card>
)
}