The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Centralize empty state + error handling for query results (#49096)
Joshen Limebb8e2336e10
diff --git a/apps/studio/components/interfaces/Explorer/QueryEditor.tsx b/apps/studio/components/interfaces/Explorer/QueryEditor.tsxindex 7d05434ecb2..06e391b58ae 100644--- a/apps/studio/components/interfaces/Explorer/QueryEditor.tsx+++ b/apps/studio/components/interfaces/Explorer/QueryEditor.tsx@@ -21,8 +21,7 @@ import {ExplorerToolbarTitle,} from './ExplorerToolbar'import { DisplaySettingsButton } from './QueryCell/DisplaySettingsButton'-import { QueryResultChart } from './QueryCell/QueryResultChart'-import { QueryResultTable } from './QueryResultTable'+import { QueryResultRenderer } from './QueryResultRenderer'import { type QueryDisplay, type QueryResult } from './types'import { CodeEditor } from '@/components/ui/CodeEditor/CodeEditor'import {@@ -257,13 +256,10 @@ export const QueryEditor = ({<ExplorerQueryResultsclassName={cn(- (result?.rows ?? []).length === 0 && view === 'table'- ? 'items-center justify-center'- : 'overflow-x-auto'+ (result?.rows ?? []).length === 0 ? 'items-center justify-center' : 'overflow-x-auto')}>- {view === 'table' && <QueryResultTable result={result} />}- {view === 'chart' && <QueryResultChart chart={display?.chart} result={result} />}+ <QueryResultRenderer view={view} result={result} chart={display?.chart} /></ExplorerQueryResults><ExplorerQueryFooter className="flex items-center gap-x-2">diff --git a/apps/studio/components/interfaces/Explorer/QueryCell/QueryResultChart.tsx b/apps/studio/components/interfaces/Explorer/QueryResultChart.tsxsimilarity index 98%rename from apps/studio/components/interfaces/Explorer/QueryCell/QueryResultChart.tsxrename to apps/studio/components/interfaces/Explorer/QueryResultChart.tsxindex da90821dbd2..c264ab526cc 100644--- a/apps/studio/components/interfaces/Explorer/QueryCell/QueryResultChart.tsx+++ b/apps/studio/components/interfaces/Explorer/QueryResultChart.tsx@@ -1,7 +1,7 @@import { useMemo } from 'react'import { Chart, ChartBar, ChartCard, ChartContent, ChartLine } from 'ui-patterns/Chart'-import { type QueryChartConfig, type QueryResult } from '../types'+import { type QueryChartConfig, type QueryResult } from './types'import NoDataPlaceholder from '@/components/ui/Charts/NoDataPlaceholder'import { formatLogTick, getCumulativeResults } from '@/components/ui/QueryBlock/QueryBlock.utils'diff --git a/apps/studio/components/interfaces/Explorer/QueryResultTable.tsx b/apps/studio/components/interfaces/Explorer/QueryResultError.tsxsimilarity index 82%rename from apps/studio/components/interfaces/Explorer/QueryResultTable.tsxrename to apps/studio/components/interfaces/Explorer/QueryResultError.tsxindex abf405d0e78..3e06ecd10e0 100644--- a/apps/studio/components/interfaces/Explorer/QueryResultTable.tsx+++ b/apps/studio/components/interfaces/Explorer/QueryResultError.tsx@@ -7,7 +7,6 @@ import { subscriptionHasHipaaAddon } from '../Billing/Subscription/Subscription.import { type QueryResult } from './types'import { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown'import CopyButton from '@/components/ui/CopyButton'-import { DataGridResults } from '@/components/ui/DataGridResults'import { InlineLink, InlineLinkClassName } from '@/components/ui/InlineLink'import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'import { getSqlErrorLines } from '@/data/sql/utils'@@ -15,37 +14,7 @@ import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-qimport { 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 <p className="text-xs text-foreground-light">Run the query to see results</p>- }-- if (error) {- return <QueryError error={error} autoLimit={autoLimit} />- }-- if ((rows ?? []).length === 0) {- return <p className="text-xs text-foreground-light">Success. No rows returned</p>- }-- if (rows && rows.length > 0) {- return <QueryResults rows={rows} />- }-}--const QueryError = ({+export const QueryResultError = ({error,autoLimit,}: {@@ -75,7 +44,7 @@ const QueryError = ({)return (- <div className="bg-table-header-light in-data-[theme*=dark]:bg-table-header-dark overflow-y-auto">+ <div className="w-full bg-table-header-light in-data-[theme*=dark]:bg-table-header-dark overflow-y-auto"><div className="flex flex-row justify-between items-start py-4 px-6 gap-x-4">{isTimeout ? (<div className="flex flex-col gap-y-1">@@ -183,8 +152,3 @@ const QueryError = ({</div>)}--// [Joshen] Eventually migrate the Results component here from SQL Editor-const QueryResults = ({ rows }: { rows: NonNullable<QueryResult['rows']> }) => {- return <DataGridResults rows={rows} />-}diff --git a/apps/studio/components/interfaces/Explorer/QueryResultRenderer.tsx b/apps/studio/components/interfaces/Explorer/QueryResultRenderer.tsxnew file mode 100644index 00000000000..604bdc71a9b--- /dev/null+++ b/apps/studio/components/interfaces/Explorer/QueryResultRenderer.tsx@@ -0,0 +1,33 @@+import { QueryResultChart } from './QueryResultChart'+import { QueryResultError } from './QueryResultError'+import { type QueryChartConfig, type QueryResult } from './types'+import { DataGridResults } from '@/components/ui/DataGridResults'++interface QueryResultRendererProps {+ result?: QueryResult+ view?: 'table' | 'chart'+ chart?: QueryChartConfig+}++export const QueryResultRenderer = ({ result, view, chart }: QueryResultRendererProps) => {+ const { rows, error, autoLimit } = result ?? {}++ if (!result) {+ return <p className="text-xs text-foreground-lighter">Run the query to see results</p>+ }++ if (error) {+ return <QueryResultError error={error} autoLimit={autoLimit} />+ }++ if ((rows ?? []).length === 0) {+ return <p className="text-xs text-foreground-lighter">Success. No rows returned</p>+ }++ if (rows && rows.length > 0) {+ if (view === 'table') return <DataGridResults rows={rows} />+ if (view === 'chart') return <QueryResultChart chart={chart} result={result} />+ }++ return null+}