The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
SQL Editor support opening cell into side panel for read only detailed view (#28547)
Joshen Lim355aee7d7643
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/CellDetailPanel.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/CellDetailPanel.tsxnew file mode 100644index 00000000000..03eb6500e15--- /dev/null+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/CellDetailPanel.tsx@@ -0,0 +1,72 @@+import { useEffect, useState } from 'react'+import remarkGfm from 'remark-gfm'++import { Markdown } from 'components/interfaces/Markdown'+import CodeEditor from 'components/ui/CodeEditor/CodeEditor'+import TwoOptionToggle from 'components/ui/TwoOptionToggle'+import { Sheet, SheetContent, SheetHeader, SheetTitle } from 'ui'++interface CellDetailPanelProps {+ column: string+ value: any+ visible: boolean+ onClose: () => void+}++export const CellDetailPanel = ({ column, value, visible, onClose }: CellDetailPanelProps) => {+ const [view, setView] = useState<'view' | 'md'>('view')++ const formattedValue =+ value === null+ ? ''+ : typeof value === 'object'+ ? JSON.stringify(value, null, '\t')+ : String(value)+ const showMarkdownToggle = typeof value === 'string'++ useEffect(() => {+ if (visible) setView('view')+ }, [visible])++ return (+ <Sheet open={visible} onOpenChange={() => onClose()}>+ <SheetContent size="lg" className="flex flex-col gap-0">+ <SheetHeader className="py-2.5">+ <SheetTitle className="flex items-center justify-between pr-7">+ <p className="truncate">+ Viewing cell details on column: <code className="text-sm">{column}</code>+ </p>+ {showMarkdownToggle && (+ <TwoOptionToggle+ options={['MD', 'view']}+ activeOption={view}+ borderOverride="border-muted"+ onClickOption={setView}+ />+ )}+ </SheetTitle>+ </SheetHeader>+ {view === 'view' ? (+ <div className="relative h-full">+ <CodeEditor+ isReadOnly+ id="sql-editor-expand-cell"+ language="json"+ value={formattedValue}+ placeholder={value === null ? 'NULL' : undefined}+ options={{ wordWrap: 'off', contextmenu: false }}+ />+ </div>+ ) : (+ <div className="flex-grow py-4 px-4 bg-default overflow-y-auto">+ <Markdown+ remarkPlugins={[remarkGfm]}+ className="!max-w-full markdown-body"+ content={formattedValue}+ />+ </div>+ )}+ </SheetContent>+ </Sheet>+ )+}diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsxindex e726140c736..d501c08ce50 100644--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsx+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.tsx@@ -1,20 +1,34 @@-import { Clipboard } from 'lucide-react'+import { Clipboard, Expand } from 'lucide-react'import { useState } from 'react'-import { Item, Menu, useContextMenu } from 'react-contexify'import DataGrid, { CalculatedColumn } from 'react-data-grid'-import { createPortal } from 'react-dom'import { GridFooter } from 'components/ui/GridFooter'import { useKeyboardShortcuts } from 'hooks/deprecated'+import { useFlag } from 'hooks/ui/useFlag'import { copyToClipboard } from 'lib/helpers'import { useSqlEditorStateSnapshot } from 'state/sql-editor'-import { useFlag } from 'hooks/ui/useFlag'import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'+import {+ cn,+ ContextMenu_Shadcn_,+ ContextMenuContent_Shadcn_,+ ContextMenuItem_Shadcn_,+ ContextMenuTrigger_Shadcn_,+} from 'ui'+import { CellDetailPanel } from './CellDetailPanel'++function formatClipboardValue(value: any) {+ if (value === null) return ''+ if (typeof value == 'object' || Array.isArray(value)) {+ return JSON.stringify(value)+ }+ return value+}const Results = ({ id, rows }: { id: string; rows: readonly any[] }) => {- const SQL_CONTEXT_EDITOR_ID = 'sql-context-menu-' + idconst enableFolders = useFlag('sqlFolderOrganization')- const [cellPosition, setCellPosition] = useState<any>(undefined)+ const [expandCell, setExpandCell] = useState(false)+ const [cellPosition, setCellPosition] = useState<{ column: any; row: any; rowIdx: number }>()const snap = useSqlEditorStateSnapshot()const snapV2 = useSqlEditorV2StateSnapshot()@@ -44,22 +58,45 @@ const Results = ({ id, rows }: { id: string; rows: readonly any[] }) => {['INPUT', 'TEXTAREA'] as any)- const { show: showContextMenu } = useContextMenu()-const formatter = (column: any, row: any) => {return (- <span- className="font-mono text-xs w-full whitespace-pre"- onContextMenu={(e) =>- showContextMenu(e, {- id: SQL_CONTEXT_EDITOR_ID,- })- }- >- {JSON.stringify(row[column])}- </span>+ <ContextMenu_Shadcn_ modal={false}>+ <ContextMenuTrigger_Shadcn_ asChild>+ <div+ className={cn(+ 'flex items-center h-full font-mono text-xs w-full whitespace-pre',+ row[column] === null && 'text-foreground-lighter'+ )}+ >+ {row[column] === null ? 'NULL' : JSON.stringify(row[column])}+ </div>+ </ContextMenuTrigger_Shadcn_>+ <ContextMenuContent_Shadcn_ onCloseAutoFocus={(e) => e.stopPropagation()}>+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => {+ const cellValue = row[column] ?? ''+ const value = formatClipboardValue(cellValue)+ copyToClipboard(value)+ }}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Clipboard size={14} />+ Copy cell content+ </ContextMenuItem_Shadcn_>+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => setExpandCell(true)}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Expand size={14} />+ View cell content+ </ContextMenuItem_Shadcn_>+ </ContextMenuContent_Shadcn_>+ </ContextMenu_Shadcn_>)}+const columnRender = (name: string) => {return <div className="flex h-full items-center justify-center font-mono text-xs">{name}</div>}@@ -92,15 +129,11 @@ const Results = ({ id, rows }: { id: string; rows: readonly any[] }) => {frozen: false,sortable: false,isLastFrozenColumn: false,- renderCell: ({ row }: any) => formatter(key, row),+ renderCell: ({ row }) => formatter(key, row),renderHeaderCell: () => columnRender(key),}})- function onSelectedCellChange(position: any) {- setCellPosition(position)- }-if (rows.length <= 0) {return (<div className="bg-table-header-light [[data-theme*=dark]_&]:bg-table-header-dark">@@ -116,36 +149,24 @@ const Results = ({ id, rows }: { id: string; rows: readonly any[] }) => {rows={rows}className="flex-grow border-t-0"rowClass={() => '[&>.rdg-cell]:items-center'}- onSelectedCellChange={onSelectedCellChange}+ onSelectedCellChange={setCellPosition}/>- {typeof window !== 'undefined' &&- createPortal(- <Menu id={SQL_CONTEXT_EDITOR_ID} animation={false}>- <Item onClick={onCopyCell}>- <Clipboard size={14} />- <span className="ml-2 text-xs">Copy cell content</span>- </Item>- </Menu>,- document.body- )}-<GridFooter className="flex items-center justify-center"><p className="text-xs text-foreground-light">{rows.length} row{rows.length > 1 ? 's' : ''}{results.autoLimit !== undefined && ` (auto limit ${results.autoLimit} rows)`}</p></GridFooter>++ <CellDetailPanel+ column={cellPosition?.column.name ?? ''}+ value={cellPosition?.row[cellPosition.column.name]}+ visible={expandCell}+ onClose={() => setExpandCell(false)}+ /></>)}export default Results--function formatClipboardValue(value: any) {- if (value === null) return ''- if (typeof value == 'object' || Array.isArray(value)) {- return JSON.stringify(value)- }- return value-}diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsxindex 6930d9f10df..e7962c9f508 100644--- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx+++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx@@ -176,7 +176,7 @@ const NavigationBar = () => {)} else if (route.key === 'advisors') {return (- <div className="relative">+ <div className="relative" key={route.key}>{securityLints.length > 0 && (<divclassName={cn(@@ -187,7 +187,6 @@ const NavigationBar = () => {)}<NavigationIconLink- key={route.key}route={route}isActive={activeRoute === route.key}onClick={onCloseNavigationIconLink}