Skip to content

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

feat(studio): show SQL snippet description (#42090)

Danny Whitee96199081b8a
diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
index e92935aae50..46fabb5d205 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
@@ -251,6 +251,8 @@ export const SQLEditorTreeViewItem = ({
}}
{...props}
name={element.name}
+ nameForTitle={props.nameForTitle}
+ description={element.metadata?.description || undefined}
xPadding={16}
/>
</ContextMenuTrigger_Shadcn_>
diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SearchList.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SearchList.tsx
index c41ee1e3442..3a196101983 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SearchList.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SearchList.tsx
@@ -115,17 +115,14 @@ export const SearchList = ({ search }: SearchListProps) => {
...element,
name: (
<span className="flex flex-col py-0.5">
- <span title={element.name} className="truncate">
- {element.name}
- </span>
+ <span className="truncate">{element.name}</span>
{!!visibility && (
- <span title={visibility} className="text-foreground-lighter text-xs">
- {visibility}
- </span>
+ <span className="text-foreground-lighter text-xs">{visibility}</span>
)}
</span>
),
}}
+ nameForTitle={element.name}
isBranch={false}
isOpened={isOpened && !isPreview}
isSelected={isActive}
diff --git a/packages/ui/src/components/TreeView/TreeView.tsx b/packages/ui/src/components/TreeView/TreeView.tsx
index ff4a1da3640..e3c9a97a291 100644
--- a/packages/ui/src/components/TreeView/TreeView.tsx
+++ b/packages/ui/src/components/TreeView/TreeView.tsx
@@ -63,7 +63,11 @@ const TreeViewItem = forwardRef<
/** The horizontal padding of the item */
xPadding?: number
/** name of entity */
- name: string
+ name: string | ReactNode
+ /** Optional description of entity */
+ description?: string
+ /** String name to use for title attribute when name is a ReactNode */
+ nameForTitle?: string
/** icon of entity */
icon?: ReactNode
/** Specifies if the item is being edited, shows an input */
@@ -90,6 +94,8 @@ const TreeViewItem = forwardRef<
isLoading = false,
xPadding = 16,
name = '',
+ description,
+ nameForTitle,
icon,
isEditing = false,
onEditSubmit,
@@ -99,7 +105,8 @@ const TreeViewItem = forwardRef<
},
ref
) => {
- const [localValueState, setLocalValueState] = useState(name)
+ const nameString = nameForTitle ?? (typeof name === 'string' ? name : '')
+ const [localValueState, setLocalValueState] = useState(nameString)
const inputRef = useRef<HTMLInputElement>(null)
const timeRef = useRef<number>(0)
@@ -140,15 +147,15 @@ const TreeViewItem = forwardRef<
}
}, 200)
} else {
- setLocalValueState(name)
+ setLocalValueState(nameString)
}
- }, [isEditing])
+ }, [isEditing, nameString])
useEffect(() => {
if (!isLoading) {
- setLocalValueState(name)
+ setLocalValueState(nameString)
}
- }, [isLoading])
+ }, [isLoading, nameString])
const handleBlur = (e: FocusEvent<HTMLInputElement, Element>) => {
const timestamp = Number(new Date())
@@ -178,9 +185,13 @@ const TreeViewItem = forwardRef<
...divProps
} = props as any
+ const trimmedDescription = description?.trim()
+ const titleText = trimmedDescription ? `${nameString}\n${trimmedDescription}` : nameString
+
return (
<div
ref={ref}
+ title={titleText}
{...divProps}
aria-selected={isSelected}
aria-expanded={!isEditing && isExpanded}
@@ -254,9 +265,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>
</div>
{!isEditing && actions}
@@ -275,8 +284,8 @@ const TreeViewItem = forwardRef<
if (e.key === 'Enter') {
inputRef.current?.blur()
} else if (e.key === 'Escape') {
- setLocalValueState(name)
- onEditSubmit?.(name)
+ setLocalValueState(nameString)
+ onEditSubmit?.(nameString)
} else {
e.stopPropagation()
}