import { useParams } from 'common' import dayjs from 'dayjs' import { Clock } 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 { /** Controls shown beside the name and URL, e.g. the chart period selector */ actions?: ReactNode } /** * Top section of an edge function's Overview tab: the function name, its invoke URL and when it * was last deployed. */ 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 return ( {selectedFunction?.name || functionSlug} {isLoadingFunction && } {!!functionUrl && ( {functionUrl} )} {!!selectedFunction && ( {createdRelative && (

Created

)} {updatedRelative && (

Last deployed

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

Deployments

{selectedFunction.version}

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