import * as Tooltip from '@radix-ui/react-tooltip' import { PermissionAction } from '@supabase/shared-types/out/constants' import { Alert, Badge, Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, IconChevronDown, IconPlay, Popover, } from 'ui' import { useCheckPermissions, useIsFeatureEnabled } from 'hooks' import { IS_PLATFORM } from 'lib/constants' import { useProfile } from 'lib/profile' import Link from 'next/link' import React from 'react' import { EXPLORER_DATEPICKER_HELPERS, LogsTableName, LogsWarning, LOGS_SOURCE_DESCRIPTION, LogTemplate, } from '.' import DatePickers from './Logs.DatePickers' export interface LogsQueryPanelProps { templates?: LogTemplate[] onSelectTemplate: (template: LogTemplate) => void onSelectSource: (source: LogsTableName) => void onRun: (e: React.MouseEvent) => void onClear: () => void onSave?: () => void hasEditorValue: boolean isLoading: boolean onDateChange: React.ComponentProps['onChange'] defaultTo: string defaultFrom: string warnings: LogsWarning[] } const LogsQueryPanel = ({ templates = [], onSelectTemplate, hasEditorValue, onRun, onClear, onSave, onSelectSource, isLoading, defaultFrom, defaultTo, onDateChange, warnings, }: LogsQueryPanelProps) => { const { profile } = useProfile() const canCreateLogQuery = useCheckPermissions(PermissionAction.CREATE, 'user_content', { resource: { type: 'log_sql', owner_id: profile?.id }, subject: { id: profile?.id }, }) const { projectAuthAll: authEnabled, projectStorageAll: storageEnabled, projectEdgeFunctionAll: edgeFunctionsEnabled, } = useIsFeatureEnabled(['project_auth:all', 'project_storage:all', 'project_edge_function:all']) const logsTableNames = Object.entries(LogsTableName) .filter(([key]) => { if (key === 'AUTH') return authEnabled if (key === 'STORAGE') return storageEnabled if (key === 'FN_EDGE') return edgeFunctionsEnabled return true }) .map(([, value]) => value) return (
{logsTableNames .sort((a, b) => a.localeCompare(b)) .map((source) => ( onSelectSource(source)}>
{source} {LOGS_SOURCE_DESCRIPTION[source]}
))}
{templates .sort((a, b) => a.label!.localeCompare(b.label!)) .map((template) => ( onSelectTemplate(template)} >

{template.label}

))}
0 ? 'opacity-100' : 'invisible h-0 w-0 opacity-0' }`} >
{warnings.map((warning, index) => (

{warning.text}{' '} {warning.link && ( {warning.linkText || 'View'} )}

))}
} > {warnings.length} {warnings.length > 1 ? 'warnings' : 'warning'}
{IS_PLATFORM && onSave && ( {!canCreateLogQuery && (
You need additional permissions to save your query
)}
)}
) } export default LogsQueryPanel