Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): edit source from SQL editor side panel (#66862)

Daniel RCe5a3cb8e9325
diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx
index 88b20fc2be2b..a274ba5f9eb9 100644
--- a/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx
@@ -10,6 +10,7 @@ import {
IconCalendar,
IconCheck,
IconClock,
+ IconChevronRight,
IconCode,
IconCode2,
IconDatabase,
@@ -26,7 +27,13 @@ import { LemonTree, LemonTreeRef, TreeDataItem } from 'lib/lemon-ui/LemonTree/Le
import { TreeNodeDisplayIcon } from 'lib/lemon-ui/LemonTree/LemonTreeUtils'
import { Link } from 'lib/lemon-ui/Link'
import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
-import { DropdownMenuGroup, DropdownMenuItem } from 'lib/ui/DropdownMenu/DropdownMenu'
+import {
+ DropdownMenuGroup,
+ DropdownMenuItem,
+ DropdownMenuSub,
+ DropdownMenuSubContent,
+ DropdownMenuSubTrigger,
+} from 'lib/ui/DropdownMenu/DropdownMenu'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { cn } from 'lib/utils/css-classes'
@@ -879,12 +886,68 @@ export const QueryDatabase = ({
return null
}
- // Render the custom "add source of type" button (no dropdown) for external source folders
+ // External source folders get an actions menu: edit the source and add a new one of this type
if (
item.record?.type === 'source-folder' &&
externalDataSources.includes(item.record?.sourceType as (typeof externalDataSources)[number])
) {
- return null
+ const sourceType = item.record?.sourceType
+ const sources: { id: string; label: string }[] = item.record?.sources ?? []
+ return (
+ <DropdownMenuGroup>
+ {sources.length === 1 ? (
+ <DropdownMenuItem asChild>
+ <Link
+ to={urls.dataWarehouseSource(`managed-${sources[0].id}`, 'configuration')}
+ target="_blank"
+ buttonProps={{ menuItem: true }}
+ onClick={(e) => e.stopPropagation()}
+ >
+ Edit source
+ </Link>
+ </DropdownMenuItem>
+ ) : sources.length > 1 ? (
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger asChild>
+ <ButtonPrimitive menuItem>
+ Edit source
+ <IconChevronRight className="ml-auto size-3" />
+ </ButtonPrimitive>
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ {sources.map((source) => (
+ <DropdownMenuItem key={source.id} asChild>
+ <Link
+ to={urls.dataWarehouseSource(
+ `managed-${source.id}`,
+ 'configuration'
+ )}
+ target="_blank"
+ buttonProps={{ menuItem: true }}
+ onClick={(e) => e.stopPropagation()}
+ >
+ {source.label}
+ </Link>
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ ) : null}
+ <DropdownMenuItem
+ asChild
+ onClick={(e) => {
+ e.stopPropagation()
+ posthog.capture('sql-editor-add-source-clicked', {
+ source_type: sourceType,
+ location: 'source_type_row',
+ })
+ newInternalTab(urls.dataWarehouseSourceNew(sourceType))
+ }}
+ >
+ <ButtonPrimitive menuItem>Add new source of this type</ButtonPrimitive>
+ </DropdownMenuItem>
+ </DropdownMenuGroup>
+ )
}
return undefined
@@ -911,32 +974,8 @@ export const QueryDatabase = ({
)
}
- // Only external source kinds have a dedicated creation page; PostHog/System/Self-managed don't
- const sourceType = item.record?.sourceType
- if (
- item.record?.type === 'source-folder' &&
- externalDataSources.includes(sourceType as (typeof externalDataSources)[number])
- ) {
- return (
- <ButtonPrimitive
- iconOnly
- isSideActionRight
- className="absolute right-0 opacity-0 group-hover/lemon-tree-button-group:opacity-100 z-10 data-[state=open]:opacity-100 -outline-offset-2 focus-visible:opacity-100"
- onClick={(e) => {
- e.stopPropagation()
- posthog.capture('sql-editor-add-source-clicked', {
- source_type: sourceType,
- location: 'source_type_row',
- })
- newInternalTab(urls.dataWarehouseSourceNew(sourceType))
- }}
- data-attr="sql-editor-add-source-of-type"
- tooltip="Add new source of this type"
- >
- <IconPlusSmall className="text-tertiary" />
- </ButtonPrimitive>
- )
- }
+ // External source folders fall through to the default ellipsis trigger, which opens
+ // the actions menu (edit source / add new source of this type) defined in itemSideAction
}}
renderItemTooltip={(item) => {
// Show tooltip with full name for items that could be truncated
diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
index 0d32abce5167..8d6fb5335799 100644
--- a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
@@ -1011,6 +1011,21 @@ const createSourceFolderNode = (
? `search-${sourceType === 'PostHog' ? 'posthog' : sourceType}`
: `source-${sourceType === 'PostHog' ? 'posthog' : sourceType}`
+ // Distinct ExternalDataSources behind this type folder, so it can link each to its edit page.
+ // A type can have several sources (e.g. two Postgres connections), distinguished by prefix.
+ const sourceTables = isSearch ? matches.map(([table]) => table) : tables
+ const sources: { id: string; label: string }[] = []
+ const seenSourceIds = new Set<string>()
+ sourceTables.forEach((table) => {
+ const source = (table as DatabaseSchemaDataWarehouseTable).source
+ if (source?.id && !seenSourceIds.has(source.id)) {
+ seenSourceIds.add(source.id)
+ // Prefixes are stored with a trailing underscore (e.g. "stripe_"); strip it for display.
+ const label = source.prefix?.trim().replace(/_+$/, '') || source.source_type
+ sources.push({ id: source.id, label })
+ }
+ })
+
return {
id: sourceFolderId,
name: sourceType,
@@ -1033,6 +1048,7 @@ const createSourceFolderNode = (
record: {
type: 'source-folder',
sourceType,
+ sources,
},
children: sourceChildren,
}