The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Chore/add hover card back to snippets (#29561)
Terry Sutton3e279dac7e0e
diff --git a/apps/design-system/registry/default/example/tree-view-multi-select.tsx b/apps/design-system/registry/default/example/tree-view-multi-select.tsxindex 2487c8eecd1..669e59da782 100644--- a/apps/design-system/registry/default/example/tree-view-multi-select.tsx+++ b/apps/design-system/registry/default/example/tree-view-multi-select.tsx@@ -97,7 +97,6 @@ export default function TreeViewDemo() {name={element.name}isEditing={element.metadata?.isEditing === true}onEditSubmit={(value) => {- console.log('value', value)let updatedTreeData = { ...treeData }const findNode = (node: any) => {if (node.id === element.id) {diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsxindex d8b728746e2..906a676224b 100644--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx@@ -18,7 +18,16 @@ import {ContextMenuTrigger_Shadcn_,ContextMenu_Shadcn_,TreeViewItem,+ HoverCardTrigger_Shadcn_,+ HoverCard_Shadcn_,+ HoverCardContent_Shadcn_,+ ScrollArea,+ HoverCardContent,+ SimpleCodeBlock,} from 'ui'+import { useSqlSnippetsQuery } from 'data/content/sql-snippets-query'+import { SqlSnippet } from '../../../../data/content/sql-snippets-query'+import CopyButton from 'components/ui/CopyButton'interface SQLEditorTreeViewItemProps {element: any@@ -70,6 +79,13 @@ export const SQLEditorTreeViewItem = ({const [isFetching, setIsFetching] = useState(false)+ const snippets = useSqlSnippetsQuery(ref)++ const snippetContent =+ snippets.data?.snippets+ ?.filter((snippet: SqlSnippet) => snippet.type === 'sql')+ .find((snippet: SqlSnippet) => snippet.id === element.id)?.content?.sql ?? ''+const isOwner = profile?.id === element?.metadata.owner_idconst isSharedSnippet = element.metadata.visibility === 'project'@@ -99,195 +115,215 @@ export const SQLEditorTreeViewItem = ({}return (- <>- <ContextMenu_Shadcn_ modal={false}>- <ContextMenuTrigger_Shadcn_ asChild>- <TreeViewItem- level={level}- xPadding={16}- name={element.name}- className={className}- isExpanded={isExpanded}- isBranch={isBranch}- isSelected={isSelected || id === element.id}- isEditing={isEditing}- isLoading={isFetching || isSaving}- onEditSubmit={(value) => {- if (onEditSave !== undefined) onEditSave(value)- }}- onClick={(e) => {- if (!isBranch) {- if (!e.shiftKey) {- router.push(`/project/${ref}/sql/${element.id}`)- } else if (id !== 'new') {- onMultiSelect?.(element.id)+ <ContextMenu_Shadcn_ modal={false}>+ <ContextMenuTrigger_Shadcn_ asChild>+ <HoverCard_Shadcn_ openDelay={300}>+ <HoverCardTrigger_Shadcn_ asChild>+ <TreeViewItem+ level={level}+ xPadding={16}+ name={element.name}+ className={className}+ isExpanded={isExpanded}+ isBranch={isBranch}+ isSelected={isSelected || id === element.id}+ isEditing={isEditing}+ isLoading={isFetching || isSaving}+ onEditSubmit={(value) => {+ if (onEditSave !== undefined) onEditSave(value)+ }}+ onClick={(e) => {+ if (!isBranch) {+ if (!e.shiftKey) {+ router.push(`/project/${ref}/sql/${element.id}`)+ } else if (id !== 'new') {+ onMultiSelect?.(element.id)+ } else {+ router.push(`/project/${ref}/sql/${element.id}`)+ }} else {- router.push(`/project/${ref}/sql/${element.id}`)- }- } else {- // Prevent expanding folder while editing text- // as the user may double click to select etc- if (isEditing) {- return- }+ // Prevent expanding folder while editing text+ // as the user may double click to select etc+ if (isEditing) {+ return+ }- onClick(e)- if (!isExpanded) onOpenFolder(element.id)- }- }}- />- </ContextMenuTrigger_Shadcn_>- <ContextMenuContent_Shadcn_ onCloseAutoFocus={(e) => e.stopPropagation()}>- {isBranch ? (- <>- {onSelectCreate !== undefined && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectCreate()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Plus size={14} />- Create new snippet- </ContextMenuItem_Shadcn_>- )}- {onSelectRename !== undefined && isOwner && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectRename()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Edit size={14} />- Rename folder- </ContextMenuItem_Shadcn_>- )}- {onSelectDelete !== undefined && isOwner && (- <>- <ContextMenuSeparator_Shadcn_ />- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectDelete()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Trash size={14} />- Delete folder- </ContextMenuItem_Shadcn_>- </>- )}- </>- ) : isMultiSelected ? (- <>- {onSelectMove !== undefined && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectMove()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Move size={14} />- Move selected queries- </ContextMenuItem_Shadcn_>- )}- <ContextMenuSeparator_Shadcn_ />- {onSelectDelete !== undefined && (+ onClick(e)+ if (!isExpanded) onOpenFolder(element.id)+ }+ }}+ />+ </HoverCardTrigger_Shadcn_>+ <HoverCardContent_Shadcn_ className="w-[500px]" side="right">+ <ScrollArea className="h-[240px] relative max-w-[475px] pr-8">+ <SimpleCodeBlock+ showCopy={false}+ className="sql"+ parentClassName="!p-0 [&>div>span]:text-xs"+ >+ {snippetContent}+ </SimpleCodeBlock>+ <CopyButton+ iconOnly+ text={snippetContent}+ type="text"+ icon={<Copy />}+ className="px-1 absolute right-3 top-0"+ />+ </ScrollArea>+ </HoverCardContent_Shadcn_>+ </HoverCard_Shadcn_>+ </ContextMenuTrigger_Shadcn_>+ <ContextMenuContent_Shadcn_ onCloseAutoFocus={(e) => e.stopPropagation()}>+ {isBranch ? (+ <>+ {onSelectCreate !== undefined && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectCreate()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Plus size={14} />+ Create new snippet+ </ContextMenuItem_Shadcn_>+ )}+ {onSelectRename !== undefined && isOwner && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectRename()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Edit size={14} />+ Rename folder+ </ContextMenuItem_Shadcn_>+ )}+ {onSelectDelete !== undefined && isOwner && (+ <>+ <ContextMenuSeparator_Shadcn_ /><ContextMenuItem_Shadcn_className="gap-x-2"onSelect={() => onSelectDelete()}onFocusCapture={(e) => e.stopPropagation()}><Trash size={14} />- Delete selected queries+ Delete folder</ContextMenuItem_Shadcn_>- )}- </>- ) : (- <>+ </>+ )}+ </>+ ) : isMultiSelected ? (+ <>+ {onSelectMove !== undefined && (<ContextMenuItem_Shadcn_- asChildclassName="gap-x-2"- onSelect={() => {}}+ onSelect={() => onSelectMove()}onFocusCapture={(e) => e.stopPropagation()}>- <Link href={`/project/${ref}/sql/${element.id}`} target="_blank" rel="noreferrer">- <ExternalLink size={14} />- Open in new tab- </Link>+ <Move size={14} />+ Move selected queries</ContextMenuItem_Shadcn_>- <ContextMenuSeparator_Shadcn_ />- {onSelectRename !== undefined && isOwner && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectRename()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Edit size={14} />- Rename query- </ContextMenuItem_Shadcn_>- )}- {onSelectMove !== undefined && isOwner && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectMove()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Move size={14} />- Move query- </ContextMenuItem_Shadcn_>- )}- {onSelectShare !== undefined && !isSharedSnippet && canCreateSQLSnippet && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectShare()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Share size={14} />- Share query with team- </ContextMenuItem_Shadcn_>- )}- {onSelectUnshare !== undefined && isSharedSnippet && isOwner && (+ )}+ <ContextMenuSeparator_Shadcn_ />+ {onSelectDelete !== undefined && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectDelete()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Trash size={14} />+ Delete selected queries+ </ContextMenuItem_Shadcn_>+ )}+ </>+ ) : (+ <>+ <ContextMenuItem_Shadcn_+ asChild+ className="gap-x-2"+ onSelect={() => {}}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Link href={`/project/${ref}/sql/${element.id}`} target="_blank" rel="noreferrer">+ <ExternalLink size={14} />+ Open in new tab+ </Link>+ </ContextMenuItem_Shadcn_>+ <ContextMenuSeparator_Shadcn_ />+ {onSelectRename !== undefined && isOwner && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectRename()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Edit size={14} />+ Rename query+ </ContextMenuItem_Shadcn_>+ )}+ {onSelectMove !== undefined && isOwner && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectMove()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Move size={14} />+ Move query+ </ContextMenuItem_Shadcn_>+ )}+ {onSelectShare !== undefined && !isSharedSnippet && canCreateSQLSnippet && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectShare()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Share size={14} />+ Share query with team+ </ContextMenuItem_Shadcn_>+ )}+ {onSelectUnshare !== undefined && isSharedSnippet && isOwner && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectUnshare()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Lock size={14} />+ Unshare query with team+ </ContextMenuItem_Shadcn_>+ )}+ {onSelectCopyPersonal !== undefined &&+ isSharedSnippet &&+ !isOwner &&+ canCreateSQLSnippet && (<ContextMenuItem_Shadcn_className="gap-x-2"- onSelect={() => onSelectUnshare()}+ onSelect={() => onSelectCopyPersonal()}onFocusCapture={(e) => e.stopPropagation()}>- <Lock size={14} />- Unshare query with team+ <Copy size={14} />+ Duplicate personal copy</ContextMenuItem_Shadcn_>)}- {onSelectCopyPersonal !== undefined &&- isSharedSnippet &&- !isOwner &&- canCreateSQLSnippet && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectCopyPersonal()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Copy size={14} />- Duplicate personal copy- </ContextMenuItem_Shadcn_>- )}- {onSelectDownload !== undefined && IS_PLATFORM && (- <ContextMenuItem_Shadcn_- className="gap-x-2"- onSelect={() => onSelectDownload()}- onFocusCapture={(e) => e.stopPropagation()}- >- <Download size={14} />- Download as migration file+ {onSelectDownload !== undefined && IS_PLATFORM && (+ <ContextMenuItem_Shadcn_+ className="gap-x-2"+ onSelect={() => onSelectDownload()}+ onFocusCapture={(e) => e.stopPropagation()}+ >+ <Download size={14} />+ Download as migration file+ </ContextMenuItem_Shadcn_>+ )}+ {onSelectDelete !== undefined && isOwner && (+ <>+ <ContextMenuSeparator_Shadcn_ />+ <ContextMenuItem_Shadcn_ className="gap-x-2" onSelect={() => onSelectDelete()}>+ <Trash size={14} />+ Delete query</ContextMenuItem_Shadcn_>- )}- {onSelectDelete !== undefined && isOwner && (- <>- <ContextMenuSeparator_Shadcn_ />- <ContextMenuItem_Shadcn_ className="gap-x-2" onSelect={() => onSelectDelete()}>- <Trash size={14} />- Delete query- </ContextMenuItem_Shadcn_>- </>- )}- </>- )}- </ContextMenuContent_Shadcn_>- </ContextMenu_Shadcn_>- </>+ </>+ )}+ </>+ )}+ </ContextMenuContent_Shadcn_>+ </ContextMenu_Shadcn_>)}diff --git a/apps/studio/state/sql-editor-v2.ts b/apps/studio/state/sql-editor-v2.tsindex 2fd708c9853..728c2fb4572 100644--- a/apps/studio/state/sql-editor-v2.ts+++ b/apps/studio/state/sql-editor-v2.ts@@ -394,6 +394,7 @@ async function upsertSnippet(id: string, projectRef: string, payload: UpsertContconst queryClient = getQueryClient()await queryClient.invalidateQueries(contentKeys.count(projectRef, 'sql'))+ await queryClient.invalidateQueries(contentKeys.list(projectRef))sqlEditorState.savingStates[id] = 'IDLE'} catch (error) {diff --git a/packages/ui/src/components/TreeView/TreeView.tsx b/packages/ui/src/components/TreeView/TreeView.tsxindex 53e463971e6..7911dfc108a 100644--- a/packages/ui/src/components/TreeView/TreeView.tsx+++ b/packages/ui/src/components/TreeView/TreeView.tsx@@ -174,9 +174,7 @@ const TreeViewItem = forwardRef</>))}- <span className={cn(isEditing && 'hidden', 'truncate text-sm')} title={name}>- {name}- </span>+ <span className={cn(isEditing && 'hidden', 'truncate text-sm')}>{name}</span><form autoFocus onSubmit={handleSubmit} className={cn(!isEditing && 'hidden')}><Inputref={inputRef}