Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

enhance(sql editor): set result column width roughly based on contents (#23235)

Charis8455b48ed8c9
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsx
index 87f2e91fbbb..3e3d751c76d 100644
--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsx
@@ -55,23 +55,35 @@ const Results = ({ id, rows }: { id: string; rows: readonly any[] }) => {
return <div className="flex h-full items-center justify-center font-mono text-xs">{name}</div>
}
- const columns: CalculatedColumn<any>[] = Object.keys(rows?.[0] ?? []).map((key, idx) => ({
- idx,
- key,
- name: key,
- resizable: true,
- parent: undefined,
- level: 0,
- width: 120,
- minWidth: 120,
- maxWidth: undefined,
- draggable: false,
- frozen: false,
- sortable: false,
- isLastFrozenColumn: false,
- renderCell: ({ row }: any) => formatter(key, row),
- renderHeaderCell: () => columnRender(key),
- }))
+ const EST_CHAR_WIDTH = 8.25
+ const MIN_COLUMN_WIDTH = 100
+ const MAX_COLUMN_WIDTH = 500
+
+ const columns: CalculatedColumn<any>[] = Object.keys(rows?.[0] ?? []).map((key, idx) => {
+ const maxColumnValueLength = Math.max(...rows.map((row) => String(row[key]).length))
+ const columnWidth = Math.max(
+ Math.min(maxColumnValueLength * EST_CHAR_WIDTH, MAX_COLUMN_WIDTH),
+ MIN_COLUMN_WIDTH
+ )
+
+ return {
+ idx,
+ key,
+ name: key,
+ resizable: true,
+ parent: undefined,
+ level: 0,
+ width: columnWidth,
+ minWidth: MIN_COLUMN_WIDTH,
+ maxWidth: undefined,
+ draggable: false,
+ frozen: false,
+ sortable: false,
+ isLastFrozenColumn: false,
+ renderCell: ({ row }: any) => formatter(key, row),
+ renderHeaderCell: () => columnRender(key),
+ }
+ })
function onSelectedCellChange(position: any) {
setCellPosition(position)
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx
index e976d4c9587..01c8f235ed5 100644
--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityPanel.tsx
@@ -2,7 +2,6 @@ import { useQueryClient } from '@tanstack/react-query'
import { useParams } from 'common'
import toast from 'react-hot-toast'
-import { useContentQuery } from 'data/content/content-query'
import { useContentUpsertMutation } from 'data/content/content-upsert-mutation'
import { contentKeys } from 'data/content/keys'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
@@ -38,7 +37,6 @@ const UtilityPanel = ({
}: UtilityPanelProps) => {
const snap = useSqlEditorStateSnapshot()
const { ref } = useParams()
- const { data } = useContentQuery(ref)
const snippet = snap.snippets[id]?.snippet
const queryKeys = contentKeys.list(ref)