import { IS_PLATFORM } from 'common' import { MoreHorizontalIcon, PlugZapIcon, TrashIcon } from 'lucide-react' import { cloneElement, useEffect, useRef, useState } from 'react' import { Button, Card, cn, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from 'ui' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' import { LOG_DRAIN_TYPES, LogDrainType } from './LogDrains.constants' import { LogDrainsCard } from './LogDrainsCard' import { useEnabledLogDrainTypes } from './useEnabledLogDrainTypes' import { VoteLink } from './VoteLink' import { AlertError } from '@/components/ui/AlertError' import { LogDrainData } from '@/data/log-drains/log-drains-query' import type { StudioError } from '@/lib/errors/studio-errors' export function LogDrainsList({ logDrains, isLoading, isError, error, isDeleting, onNewDrainClick, onDeleteDrain, onTestDrain, }: { logDrains: LogDrainData[] | undefined isLoading: boolean isError: boolean error: StudioError | null isDeleting?: boolean onNewDrainClick: (src: LogDrainType) => void onDeleteDrain: (drain: LogDrainData) => void onTestDrain?: (drain: LogDrainData) => void }) { const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false) const [selectedLogDrain, setSelectedLogDrain] = useState(null) const enabledDrainTypes = useEnabledLogDrainTypes() const hasLogDrains = !!logDrains?.length const wasDeleting = useRef(false) useEffect(() => { if (wasDeleting.current && !isDeleting) { setIsDeleteModalOpen(false) setSelectedLogDrain(null) } wasDeleting.current = !!isDeleting }, [isDeleting]) if (isLoading) { return (
) } if (isError) { return } if (!hasLogDrains) { return ( <>
{enabledDrainTypes.map((src) => ( { onNewDrainClick(src.value) }} /> ))}
) } return ( <> Name Description Destination
Actions
{logDrains ?.slice() .sort((a, b) => b.id - a.id) .map((drain) => ( {drain.name} {drain.description || '-'}
{LOG_DRAIN_TYPES.find((t) => t.value === drain.type)?.icon && ( {cloneElement(LOG_DRAIN_TYPES.find((t) => t.value === drain.type)!.icon, { height: 16, width: 16, })} )} {LOG_DRAIN_TYPES.find((t) => t.value === drain.type)?.name ?? drain.type}
) }