import { useParams } from 'common' import dayjs from 'dayjs' import { ClockIcon } from 'lucide-react' import type { ReactNode } from 'react' import { HoverCard, HoverCardContent, HoverCardTrigger } from 'ui' import { PageHeader, PageHeaderAside, PageHeaderDescription, PageHeaderMeta, PageHeaderSummary, PageHeaderTitle, } from 'ui-patterns/PageHeader' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { TimestampInfo } from 'ui-patterns/TimestampInfo' import CopyButton from '@/components/ui/CopyButton' import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip' import { useProjectApiUrl } from '@/data/config/project-endpoint-query' import { useEdgeFunctionQuery } from '@/data/edge-functions/edge-function-query' import { SHORTCUT_IDS } from '@/state/shortcuts/registry' interface EdgeFunctionOverviewHeaderProps { actions?: ReactNode } export const EdgeFunctionOverviewHeader = ({ actions }: EdgeFunctionOverviewHeaderProps) => { const { ref: projectRef, functionSlug } = useParams() const { data: selectedFunction, isPending: isLoadingFunction } = useEdgeFunctionQuery({ projectRef, slug: functionSlug, }) const { data: endpoint } = useProjectApiUrl({ projectRef }) const functionUrl = endpoint && selectedFunction?.slug ? `${endpoint}/functions/v1/${selectedFunction.slug}` : '' const createdRelative = selectedFunction?.created_at ? dayjs(selectedFunction.created_at).fromNow() : undefined const updatedRelative = selectedFunction?.updated_at ? dayjs(selectedFunction.updated_at).fromNow() : undefined let detailsStatus = '' if (isLoadingFunction) detailsStatus = 'Loading function details' if (selectedFunction) { detailsStatus = `${selectedFunction.name} details loaded. Last deployed ${updatedRelative ?? 'status unavailable'}.` } return ( {detailsStatus} {selectedFunction?.name || functionSlug} {isLoadingFunction && } {!!functionUrl && ( {functionUrl} )} {!!selectedFunction && ( {createdRelative && (

Created

)} {updatedRelative && (

Last deployed

)} {selectedFunction.version !== undefined && (

Deployments

{selectedFunction.version}

)}
)}
{actions && {actions}}
) }