import { useParams } from 'common' import { ExternalLink } from 'lucide-react' import { parseAsBoolean, useQueryState } from 'nuqs' import { Button, cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { subscriptionHasHipaaAddon } from '../Billing/Subscription/Subscription.utils' import { Results } from '../SQLEditor/UtilityPanel/Results' import { getSqlErrorLines } from '../SQLEditor/UtilityPanel/UtilityTabResults.utils' import { type QueryResult } from './types' import { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown' import CopyButton from '@/components/ui/CopyButton' import { InlineLink, InlineLinkClassName } from '@/components/ui/InlineLink' import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query' import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { DOCS_URL } from '@/lib/constants' interface QueryResultTableProps { result?: QueryResult } // [Joshen] This is essentially a duplicate of UtilityTabResults from the SQL Editor // I'll eventually migrate the Results component over - just trying to avoid bloating // changes wherever possible // [Joshen] Should be shifted into QueryCell folder export const QueryResultTable = ({ result }: QueryResultTableProps) => { const { rows, error, autoLimit } = result ?? {} if (!result) { return

Run the query to see results

} if (error) { return } if ((rows ?? []).length === 0) { return

Success. No rows returned

} if (rows && rows.length > 0) { return } } const QueryError = ({ error, autoLimit, }: { error: NonNullable autoLimit?: QueryResult['autoLimit'] }) => { const { ref } = useParams() const { data: org } = useSelectedOrganizationQuery() const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: org?.slug }) const { data: projectSettings } = useProjectSettingsV2Query({ projectRef: ref }) const hasHipaaAddon = subscriptionHasHipaaAddon(subscription) && projectSettings?.is_sensitive const [, setShowConnect] = useQueryState('showConnect', parseAsBoolean.withDefault(false)) const isTimeout = error.message?.includes('canceling statement due to statement timeout') || error.message?.includes('upstream request timeout') || error.message?.includes('Query read timeout') const isNetWorkError = error.message?.includes('EHOSTUNREACH') const errorLines = getSqlErrorLines(error) // [Joshen] Need to check if a replica is selected as well const readReplicaError = error.message.includes('in a read-only transaction') const payloadTooLargeError = error.message.includes( 'Query is too large to be run via the SQL Editor' ) return (
{isTimeout ? (

Error: SQL query ran into an upstream timeout

You can either{' '} optimize your query , or{' '} increase the statement timeout {' or '} .

) : (
{errorLines.length > 0 ? ( errorLines.map((x: string, i: number) => (
                  {x}
                
)) ) : (

Error: {error.message}

)} {!isTimeout && !isNetWorkError && autoLimit && (

Note: A limit of {autoLimit} was applied to your query. If this was the cause of a syntax error, try selecting "No limit" instead and re-run the query.

)} {readReplicaError && (

Note: Read replicas are for read only queries. Run write queries on the primary database instead.

)} {payloadTooLargeError && (

Run this query by{' '} .

)}
)}
{readReplicaError && ( )} {errorLines.length > 0 && ( Copy error )} {!hasHipaaAddon && ( // [Joshen] TODO ''} onOpenAssistant={() => {}} disabled={false} loading={false} /> )}
) } // [Joshen] Eventually migrate the Results component here from SQL Editor const QueryResults = ({ rows }: { rows: NonNullable }) => { return }