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.

fix(data-warehouse): give direct connect sources their own section (#74698)

Tom Owers375833aa40a5
diff --git a/frontend/src/scenes/data-management/database/databaseTableListLogic.test.ts b/frontend/src/scenes/data-management/database/databaseTableListLogic.test.ts
index 94aefe624b39..4ca74baba8a3 100644
--- a/frontend/src/scenes/data-management/database/databaseTableListLogic.test.ts
+++ b/frontend/src/scenes/data-management/database/databaseTableListLogic.test.ts
@@ -1,3 +1,4 @@
+import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
import { urls } from 'scenes/urls'
@@ -136,6 +137,28 @@ describe('databaseTableListLogic', () => {
expect(logic.values.views).toEqual([])
})
+ it('resetConnectionScope drops the connection and reloads the project catalog', async () => {
+ logic = databaseTableListLogic()
+ logic.mount()
+ logic.actions.setConnection('conn-123')
+ await logic.asyncActions.loadDatabase()
+ ;(performQuery as jest.Mock).mockClear()
+ ;(performQuery as jest.Mock).mockResolvedValue({
+ tables: { events: { name: 'events', type: 'posthog' } },
+ joins: [],
+ })
+
+ // Without the reload, consumers that only fetch when `database` is empty would keep
+ // rendering the connection's tables long after the SQL editor closed.
+ logic.actions.resetConnectionScope()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.connectionId).toBeNull()
+ expect(performQuery).toHaveBeenCalledTimes(1)
+ expect((performQuery as jest.Mock).mock.calls[0][0]).toMatchObject({ connectionId: undefined })
+ expect(logic.values.allTables.map((table) => table.name)).toEqual(['events'])
+ })
+
it('does not let a stale schema response overwrite the selected connection schema', async () => {
let resolvePosthogQuery:
| ((value: { tables: Record<string, { name: string; type: 'posthog' }>; joins: never[] }) => void)
diff --git a/frontend/src/scenes/data-management/database/databaseTableListLogic.ts b/frontend/src/scenes/data-management/database/databaseTableListLogic.ts
index a74b5d643a87..debf2cd189c1 100644
--- a/frontend/src/scenes/data-management/database/databaseTableListLogic.ts
+++ b/frontend/src/scenes/data-management/database/databaseTableListLogic.ts
@@ -97,6 +97,9 @@ export interface databaseTableListLogicActions {
refreshDatabaseSchema: () => {
value: true
}
+ resetConnectionScope: () => {
+ value: true
+ }
setConnection: (connectionId: string | null) => {
connectionId: string | null
}
@@ -161,6 +164,10 @@ export const databaseTableListLogic = kea<databaseTableListLogicType>([
setSearchTerm: (searchTerm: string) => ({ searchTerm }),
setConnection: (connectionId: string | null) => ({ connectionId }),
refreshDatabaseSchema: true,
+ // Drop any direct-connection scope and go back to the project's own catalog. This logic is
+ // shared and outlives the SQL editor, so without an explicit reset every other consumer
+ // (sources list, taxonomic filters, joins) keeps seeing the connection's tables.
+ resetConnectionScope: true,
}),
loaders(({ values }) => ({
database: [
@@ -236,7 +243,10 @@ export const databaseTableListLogic = kea<databaseTableListLogicType>([
})),
reducers({
searchTerm: ['', { setSearchTerm: (_, { searchTerm }) => searchTerm }],
- connectionId: [null as string | null, { setConnection: (_, { connectionId }) => connectionId }],
+ connectionId: [
+ null as string | null,
+ { setConnection: (_, { connectionId }) => connectionId, resetConnectionScope: () => null },
+ ],
}),
selectors({
allPosthogTables: [
@@ -412,5 +422,10 @@ export const databaseTableListLogic = kea<databaseTableListLogicType>([
refreshDatabaseSchema: () => {
actions.loadDatabase({ force: true })
},
+ // Reload immediately: the cached `database` still holds the connection's schema, and
+ // consumers that only load when `database` is empty would otherwise never refetch it.
+ resetConnectionScope: () => {
+ actions.loadDatabase()
+ },
})),
])
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
index 2a05ebca80b7..193c255cb915 100644
--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
@@ -1766,6 +1766,80 @@ describe('sqlEditorLogic', () => {
performQuerySpy.mockRestore()
})
+ it('hands the shared schema catalog back unscoped when a connected editor unmounts', async () => {
+ const performQuerySpy = jest
+ .spyOn(queryRunner, 'performQuery')
+ .mockResolvedValue({ tables: {}, joins: [] } as never)
+
+ const editorLogic = sqlEditorLogic({
+ tabId: TAB_ID,
+ monaco: createMockMonaco(),
+ editor: createMockEditor(),
+ })
+ editorLogic.mount()
+
+ router.actions.push(urls.sqlEditor(), undefined, { q: 'SELECT 1', c: 'conn-123' })
+ await expectLogic(editorLogic).toDispatchActions(['setSourceQuery', 'createTab', 'updateTab'])
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ expect(databaseLogic.values.connectionId).toEqual('conn-123')
+
+ // databaseTableListLogic outlives the editor, so leaving it scoped hides everything the
+ // project owns (self-managed sources, views) from every other page that reads it.
+ performQuerySpy.mockClear()
+ editorLogic.unmount()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+
+ expect(databaseLogic.values.connectionId).toBeNull()
+ expect(performQuerySpy).toHaveBeenCalledTimes(1)
+ expect(performQuerySpy.mock.calls[0][0]).toMatchObject({ connectionId: undefined })
+
+ performQuerySpy.mockRestore()
+ })
+
+ it('keeps the catalog scoped while another editor on the same connection is still mounted', async () => {
+ const performQuerySpy = jest
+ .spyOn(queryRunner, 'performQuery')
+ .mockResolvedValue({ tables: {}, joins: [] } as never)
+
+ // Notebooks, metrics and endpoints each mount their own embedded editor, so two can sit
+ // on the same connection at once.
+ const firstEditor = sqlEditorLogic({
+ tabId: TAB_ID,
+ monaco: createMockMonaco(),
+ editor: createMockEditor(),
+ })
+ const secondEditor = sqlEditorLogic({
+ tabId: `${TAB_ID}-second`,
+ monaco: createMockMonaco(),
+ editor: createMockEditor(),
+ })
+ firstEditor.mount()
+ secondEditor.mount()
+
+ router.actions.push(urls.sqlEditor(), undefined, { q: 'SELECT 1', c: 'conn-123' })
+ await expectLogic(firstEditor).toDispatchActions(['setSourceQuery', 'createTab', 'updateTab'])
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ expect(databaseLogic.values.connectionId).toEqual('conn-123')
+ expect(secondEditor.values.selectedConnectionId).toEqual('conn-123')
+
+ // Closing one must not yank the scope away from the other: it would keep running with
+ // the project catalog and never rescope, since its own connection never changed.
+ performQuerySpy.mockClear()
+ firstEditor.unmount()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+
+ expect(databaseLogic.values.connectionId).toEqual('conn-123')
+ expect(performQuerySpy).not.toHaveBeenCalled()
+
+ secondEditor.unmount()
+ await new Promise((resolve) => setTimeout(resolve, 0))
+
+ expect(databaseLogic.values.connectionId).toBeNull()
+ expect(performQuerySpy.mock.calls[0][0]).toMatchObject({ connectionId: undefined })
+
+ performQuerySpy.mockRestore()
+ })
+
it('resets stale database connection state when reopening the editor without a connection in the url', async () => {
const performQuerySpy = jest
.spyOn(queryRunner, 'performQuery')
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
index 07ff74f7c7cd..9ec71ce9b972 100644
--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
@@ -667,6 +667,9 @@ export interface sqlEditorLogicActions {
) => {
force?: boolean
} // databaseTableListLogic
+ resetConnectionScope: () => {
+ value: true
+ } // databaseTableListLogic
setConnection: (connectionId: string | null) => {
connectionId: string | null
} // databaseTableListLogic
@@ -1104,6 +1107,25 @@ export type sqlEditorLogicType = MakeLogicType<
sqlEditorLogicMeta
>
+// Which mounted editors currently want the shared schema catalog scoped to a connection, keyed by
+// tab id. Several editors can be mounted at once (notebook SQL nodes, metrics, endpoints) on the
+// same connection, so the last one out is the one that hands the catalog back unscoped.
+const connectionScopeOwners = new Map<string, string>()
+
+function claimConnectionScope(tabId: string, connectionId: string | null | undefined): void {
+ if (connectionId) {
+ connectionScopeOwners.set(tabId, connectionId)
+ } else {
+ connectionScopeOwners.delete(tabId)
+ }
+}
+
+// Drops this tab's claim and reports whether the scoped connection is now unclaimed.
+function releaseConnectionScope(tabId: string, scopedConnectionId: string | null): boolean {
+ connectionScopeOwners.delete(tabId)
+ return scopedConnectionId !== null && ![...connectionScopeOwners.values()].includes(scopedConnectionId)
+}
+
export const sqlEditorLogic = kea<sqlEditorLogicType>([
path(['data-warehouse', 'editor', 'sqlEditorLogic']),
props({ mode: SQLEditorMode.FullScene } as SqlEditorLogicProps),
@@ -1149,7 +1171,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
draftsLogic,
['saveAsDraft', 'deleteDraft', 'saveAsDraftSuccess', 'deleteDraftSuccess'],
databaseTableListLogic,
- ['setConnection', 'loadDatabase'],
+ ['setConnection', 'loadDatabase', 'resetConnectionScope'],
connectionSelectorLogic,
['loadConnectionOptionsSuccess', 'maybeLoadConnectionOptions'],
],
@@ -2819,7 +2841,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
},
}
}),
- subscriptions(({ actions, values, cache }) => ({
+ subscriptions(({ actions, values, cache, props }) => ({
queryInput: (queryInput: string | null) => {
// Subquery validation results are keyed by subquery text — but the same text
// may now refer to a subquery with different surrounding context, so drop
@@ -2903,6 +2925,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
}
cache.lastSelectedConnectionId = selectedConnectionId
+ claimConnectionScope(props.tabId, selectedConnectionId)
actions.setConnection(selectedConnectionId ?? null)
actions.loadDatabase()
if (selectedConnectionId) {
@@ -3463,6 +3486,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
})),
afterMount(({ actions, props, values, cache }) => {
cache.lastSelectedConnectionId = values.selectedConnectionId
+ claimConnectionScope(props.tabId, values.selectedConnectionId)
cache.activeQueryDecorationIds = [] as string[]
cache.decorationGeneration = 0
@@ -3667,7 +3691,16 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
actions.loadDatabase(values.databaseLoading ? { force: true } : undefined)
}
}),
- beforeUnmount(({ cache, props }) => {
+ beforeUnmount(({ actions, values, cache, props }) => {
+ // The editor scopes the shared schema catalog to whichever connection it was querying, and
+ // that logic stays mounted after the editor closes. Hand it back unscoped so pages like the
+ // sources list don't render the connection's tables as if they were the project's own. Only
+ // once no mounted editor still wants that connection though, or closing one of two editors
+ // sharing a connection would leave the survivor with the wrong schema tree.
+ if (releaseConnectionScope(props.tabId, values.databaseConnectionId)) {
+ actions.resetConnectionScope()
+ }
+
cache.cursorDisposable?.dispose()
cache.cursorDisposable = null
clearQueryOutlineOverlay(cache, props.editor)
diff --git a/frontend/src/scenes/data-warehouse/scene/SourcesTab.tsx b/frontend/src/scenes/data-warehouse/scene/SourcesTab.tsx
index 263b27624f06..bdf1c193a58d 100644
--- a/frontend/src/scenes/data-warehouse/scene/SourcesTab.tsx
+++ b/frontend/src/scenes/data-warehouse/scene/SourcesTab.tsx
@@ -1,6 +1,7 @@
import { SceneDivider } from '~/layout/scenes/components/SceneDivider'
import { SceneSection } from '~/layout/scenes/components/SceneSection'
+import { DirectConnectSourcesTable } from 'products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable'
import { ManagedSourcesTable } from 'products/data_warehouse/frontend/shared/components/ManagedSourcesTable'
import { SelfManagedSourcesTable } from 'products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable'
@@ -14,6 +15,13 @@ export function SourcesTab(): JSX.Element {
<ManagedSourcesTable />
</SceneSection>
<SceneDivider />
+ <SceneSection
+ title="Direct connect sources"
+ description="Query these sources live from PostHog. Your data stays where it is, nothing gets imported"
+ >
+ <DirectConnectSourcesTable />
+ </SceneSection>
+ <SceneDivider />
<SceneSection
title="Self-managed data warehouse sources"
description="Connect to your own data sources, making them queryable in PostHog"
diff --git a/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx b/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx
index 81f5a5cc5b2e..eee14ab86d1c 100644
--- a/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx
+++ b/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx
@@ -12,6 +12,7 @@ import { SceneDivider } from '~/layout/scenes/components/SceneDivider'
import { SceneSection } from '~/layout/scenes/components/SceneSection'
import { ProductKey } from '~/queries/schema/schema-general'
+import { DirectConnectSourcesTable } from 'products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable'
import { ManagedSourcesTable } from 'products/data_warehouse/frontend/shared/components/ManagedSourcesTable'
import { SelfManagedSourcesTable } from 'products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable'
import { sourceManagementLogic } from 'products/data_warehouse/frontend/shared/logics/sourceManagementLogic'
@@ -71,6 +72,14 @@ export function SourcesList({ action }: { action: JSX.Element }): JSX.Element {
</>
</FlaggedFeature>
+ <SceneSection
+ title="Direct connect sources"
+ description="Query these sources live from PostHog. Your data stays where it is, nothing gets imported"
+ >
+ <DirectConnectSourcesTable />
+ </SceneSection>
+ <SceneDivider />
+
<SceneSection
title="Self-managed data warehouse sources"
description="Connect to your own data sources, making them queryable in PostHog"
diff --git a/products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable.tsx b/products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable.tsx
new file mode 100644
index 000000000000..90871562120f
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable.tsx
@@ -0,0 +1,91 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonButton, LemonDialog, LemonInput, LemonTable, Spinner } from '@posthog/lemon-ui'
+
+import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'
+import { urls } from 'scenes/urls'
+
+import { sourceManagementLogic } from '../logics/sourceManagementLogic'
+import { SourceIcon } from './SourceIcon'
+
+export function DirectConnectSourcesTable(): JSX.Element {
+ const { filteredDirectSources, directSearchTerm, sourceReloadingById, dataWarehouseSourcesLoading } =
+ useValues(sourceManagementLogic)
+ const { setDirectSearchTerm, reloadSource, deleteSource } = useActions(sourceManagementLogic)
+
+ return (
+ <div>
+ <div className="flex gap-2 justify-between items-center mb-4">
+ <LemonInput
+ type="search"
+ placeholder="Search..."
+ onChange={setDirectSearchTerm}
+ value={directSearchTerm}
+ />
+ </div>
+ <LemonTable
+ id="direct-connect-sources"
+ dataSource={filteredDirectSources}
+ loading={dataWarehouseSourcesLoading}
+ pagination={{ pageSize: 10 }}
+ columns={[
+ {
+ width: 0,
+ render: (_, source) => <SourceIcon type={source.source_type} />,
+ },
+ {
+ title: 'Source',
+ key: 'name',
+ render: (_, source) => (
+ <LemonTableLink
+ to={urls.dataWarehouseSource(`managed-${source.id}`)}
+ title={source.prefix || source.source_type}
+ description={source.description}
+ />
+ ),
+ },
+ {
+ key: 'actions',
+ render: (_, source) => (
+ <div className="flex flex-row justify-end">
+ {sourceReloadingById[source.id] ? (
+ <Spinner />
+ ) : (
+ <>
+ <LemonButton
+ data-attr={`reload-data-warehouse-${source.source_type}`}
+ onClick={() => reloadSource(source)}
+ >
+ Reload
+ </LemonButton>
+ <LemonButton
+ status="danger"
+ data-attr={`delete-data-warehouse-${source.source_type}`}
+ onClick={() => {
+ LemonDialog.open({
+ title: 'Delete data source?',
+ description:
+ 'Are you sure you want to delete this data source? All related tables will be deleted.',
+ primaryButton: {
+ children: 'Delete',
+ status: 'danger',
+ onClick: () => deleteSource(source),
+ },
+ secondaryButton: {
+ children: 'Cancel',
+ },
+ })
+ }}
+ >
+ Delete
+ </LemonButton>
+ </>
+ )}
+ </div>
+ ),
+ },
+ ]}
+ />
+ </div>
+ )
+}
diff --git a/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx b/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx
index c99ad06c54eb..96b8e01c368f 100644
--- a/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx
+++ b/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx
@@ -1,43 +1,16 @@
import { useActions, useValues } from 'kea'
-import { LemonButton, LemonDialog, LemonInput, LemonTable, Spinner } from '@posthog/lemon-ui'
+import { LemonButton, LemonDialog, LemonInput, LemonTable } from '@posthog/lemon-ui'
import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'
import { urls } from 'scenes/urls'
-import { DatabaseSchemaDataWarehouseTable } from '~/queries/schema/schema-general'
-import { ExternalDataSource } from '~/types'
-
import { sourceManagementLogic } from '../logics/sourceManagementLogic'
-import { sourcesDataLogic } from '../logics/sourcesDataLogic'
import { SourceIcon, mapUrlToProvider } from './SourceIcon'
export function SelfManagedSourcesTable(): JSX.Element {
- const { filteredSelfManagedTables, searchTerm, sourceReloadingById } = useValues(sourceManagementLogic)
- const { deleteSelfManagedTable, refreshSelfManagedTableSchema, setSearchTerm, reloadSource, deleteSource } =
- useActions(sourceManagementLogic)
- const { dataWarehouseSources, dataWarehouseSourcesLoading } = useValues(sourcesDataLogic)
-
- const directSources = (dataWarehouseSources?.results ?? [])
- .filter((source) => source.access_method?.toLowerCase() === 'direct')
- .filter((source) => {
- if (!searchTerm?.trim()) {
- return true
- }
- const normalizedSearch = searchTerm.toLowerCase()
- return (
- source.source_type.toLowerCase().includes(normalizedSearch) ||
- source.prefix?.toLowerCase().includes(normalizedSearch) ||
- source.description?.toLowerCase().includes(normalizedSearch)
- )
- })
-
- const rows: Array<
- { kind: 'direct'; source: ExternalDataSource } | { kind: 'table'; table: DatabaseSchemaDataWarehouseTable }
- > = [
- ...directSources.map((source) => ({ kind: 'direct' as const, source })),
- ...filteredSelfManagedTables.map((table) => ({ kind: 'table' as const, table })),
- ]
+ const { filteredSelfManagedTables, searchTerm, databaseLoading } = useValues(sourceManagementLogic)
+ const { deleteSelfManagedTable, refreshSelfManagedTableSchema, setSearchTerm } = useActions(sourceManagementLogic)
return (
<div>
@@ -46,105 +19,55 @@ export function SelfManagedSourcesTable(): JSX.Element {
</div>
<LemonTable
id="self-managed-sources"
- dataSource={rows}
- loading={dataWarehouseSourcesLoading}
+ dataSource={filteredSelfManagedTables}
+ loading={databaseLoading}
pagination={{ pageSize: 10 }}
columns={[
{
width: 0,
- render: (_, row) =>
- row.kind === 'direct' ? (
- <SourceIcon type={row.source.source_type} />
- ) : (
- <SourceIcon type={mapUrlToProvider(row.table.url_pattern)} />
- ),
+ render: (_, table) => <SourceIcon type={mapUrlToProvider(table.url_pattern)} />,
},
{
title: 'Source',
key: 'name',
- render: (_, row) =>
- row.kind === 'direct' ? (
- <LemonTableLink
- to={urls.dataWarehouseSource(`managed-${row.source.id}`)}
- title={row.source.prefix || row.source.source_type}
- description={row.source.description}
- />
- ) : (
- <LemonTableLink
- to={urls.dataWarehouseSource(`self-managed-${row.table.id}`)}
- title={row.table.name}
- />
- ),
+ render: (_, table) => (
+ <LemonTableLink
+ to={urls.dataWarehouseSource(`self-managed-${table.id}`)}
+ title={table.name}
+ />
+ ),
},
{
key: 'actions',
- render: (_, row) => (
+ render: (_, table) => (
<div className="flex flex-row justify-end">
- {row.kind === 'direct' ? (
- sourceReloadingById[row.source.id] ? (
- <Spinner />
- ) : (
- <>
- <LemonButton
- data-attr={`reload-data-warehouse-${row.source.source_type}`}
- onClick={() => reloadSource(row.source)}
- >
- Reload
- </LemonButton>
- <LemonButton
- status="danger"
- data-attr={`delete-data-warehouse-${row.source.source_type}`}
- onClick={() => {
- LemonDialog.open({
- title: 'Delete data source?',
- description:
- 'Are you sure you want to delete this data source? All related tables will be deleted.',
- primaryButton: {
- children: 'Delete',
- status: 'danger',
- onClick: () => deleteSource(row.source),
- },
- secondaryButton: {
- children: 'Cancel',
- },
- })
- }}
- >
- Delete
- </LemonButton>
- </>
- )
- ) : (
- <>
- <LemonButton
- data-attr={`refresh-data-warehouse-${row.table.name}`}
- onClick={() => refreshSelfManagedTableSchema(row.table.id)}
- >
- Update schema from source
- </LemonButton>
- <LemonButton
- status="danger"
- data-attr={`delete-data-warehouse-${row.table.name}`}
- onClick={() => {
- LemonDialog.open({
- title: 'Delete table?',
- description:
- 'Table deletion cannot be undone. All views and joins related to this table will be deleted.',
- primaryButton: {
- children: 'Delete',
- status: 'danger',
- onClick: () => deleteSelfManagedTable(row.table.id),
- },
- secondaryButton: {
- children: 'Cancel',
- },
- })
- }}
- >
- Delete
- </LemonButton>
- </>
- )}
+ <LemonButton
+ data-attr={`refresh-data-warehouse-${table.name}`}
+ onClick={() => refreshSelfManagedTableSchema(table.id)}
+ >
+ Update schema from source
+ </LemonButton>
+ <LemonButton
+ status="danger"
+ data-attr={`delete-data-warehouse-${table.name}`}
+ onClick={() => {
+ LemonDialog.open({
+ title: 'Delete table?',
+ description:
+ 'Table deletion cannot be undone. All views and joins related to this table will be deleted.',
+ primaryButton: {
+ children: 'Delete',
+ status: 'danger',
+ onClick: () => deleteSelfManagedTable(table.id),
+ },
+ secondaryButton: {
+ children: 'Cancel',
+ },
+ })
+ }}
+ >
+ Delete
+ </LemonButton>
</div>
),
},
diff --git a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
index 806f461466ad..50aa887a0794 100644
--- a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
+++ b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
@@ -47,7 +47,7 @@ const REFRESH_INTERVAL = 10000
// matters because the list response is large and was previously re-fetched every REFRESH_INTERVAL
// on pages that never display it.
const SOURCE_LIST_PATHS = [
- '/data-management/sources', // SourcesScene: managed + self-managed sources tables
+ '/data-management/sources', // SourcesScene: managed, direct connect and self-managed sources tables
'/data-management/revenue', // Revenue analytics settings: external source configuration
'/settings/environment-marketing-analytics', // Marketing analytics settings: source configuration
]
@@ -59,8 +59,12 @@ export interface sourceManagementLogicValues {
availableSources: Record<string, SourceConfig> | null // availableSourcesLogic
dataWarehouseTables: DatabaseSchemaDataWarehouseTable[] // databaseTableListLogic
database: Required<DatabaseSchemaQueryResponse> | null // databaseTableListLogic
+ databaseLoading: boolean // databaseTableListLogic
dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null // sourcesDataLogic
dataWarehouseSourcesLoading: boolean // sourcesDataLogic
+ directSearchTerm: string
+ directSources: ExternalDataSource[]
+ filteredDirectSources: ExternalDataSource[]
filteredManagedSources: ExternalDataSource[]
filteredSelfManagedTables: DatabaseSchemaDataWarehouseTable[]
hasZendeskSource: boolean
@@ -150,6 +154,9 @@ export interface sourceManagementLogicActions {
schemaLoadingFinished: (schema: ExternalDataSourceSchema) => {
schema: ExternalDataSourceSchema
}
+ setDirectSearchTerm: (directSearchTerm: string) => {
+ directSearchTerm: string
+ }
setManagedSearchTerm: (managedSearchTerm: string) => {
managedSearchTerm: string
}
@@ -187,6 +194,8 @@ export interface sourceManagementLogicMeta {
searchTerm: string
) => DatabaseSchemaDataWarehouseTable[]
managedSources: (dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null) => ExternalDataSource[]
+ directSources: (dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null) => ExternalDataSource[]
+ filteredDirectSources: (directSources: ExternalDataSource[], directSearchTerm: string) => ExternalDataSource[]
managedSourcesFuse: (
managedSources: ExternalDataSource[],
availableSources: Record<string, SourceConfig> | null
@@ -212,7 +221,7 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([
connect(() => ({
values: [
databaseTableListLogic,
- ['database', 'dataWarehouseTables'],
+ ['database', 'databaseLoading', 'dataWarehouseTables'],
sourcesDataLogic,
['dataWarehouseSources', 'dataWarehouseSourcesLoading'],
availableSourcesLogic,
@@ -242,6 +251,7 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([
refreshSelfManagedTableSchema: (tableId: string) => ({ tableId }),
setSearchTerm: (searchTerm: string) => ({ searchTerm }),
setManagedSearchTerm: (managedSearchTerm: string) => ({ managedSearchTerm }),
+ setDirectSearchTerm: (directSearchTerm: string) => ({ directSearchTerm }),
deleteJoin: (join: DataWarehouseViewLink) => ({ join }),
}),
loaders(({ actions, values }) => ({
@@ -311,6 +321,12 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([
setManagedSearchTerm: (_, { managedSearchTerm }) => managedSearchTerm,
},
],
+ directSearchTerm: [
+ '' as string,
+ {
+ setDirectSearchTerm: (_, { directSearchTerm }) => directSearchTerm,
+ },
+ ],
})),
selectors({
selfManagedTables: [
@@ -341,6 +357,30 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([
(source) => source.access_method?.toLowerCase() !== 'direct'
),
],
+ directSources: [
+ (s) => [s.dataWarehouseSources],
+ (
+ dataWarehouseSources: null | import('lib/api').PaginatedResponse<ExternalDataSource>
+ ): ExternalDataSource[] =>
+ (dataWarehouseSources?.results ?? []).filter(
+ (source) => source.access_method?.toLowerCase() === 'direct'
+ ),
+ ],
+ filteredDirectSources: [
+ (s) => [s.directSources, s.directSearchTerm],
+ (directSources: ExternalDataSource[], directSearchTerm: string): ExternalDataSource[] => {
+ const normalizedSearch = directSearchTerm?.trim().toLowerCase()
+ if (!normalizedSearch) {
+ return directSources
+ }
+ return directSources.filter(
+ (source) =>
+ source.source_type.toLowerCase().includes(normalizedSearch) ||
+ source.prefix?.toLowerCase().includes(normalizedSearch) ||
+ source.description?.toLowerCase().includes(normalizedSearch)
+ )
+ },
+ ],
// Search the display label as well as the internal source_type. Fuzzy, like the source catalog.
managedSourcesFuse: [
(s) => [s.managedSources, s.availableSources],
diff --git a/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts b/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts
index c912aa706e93..65291f5d6cc3 100644
--- a/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts
+++ b/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts
@@ -68,6 +68,31 @@ describe('sourceManagementLogic', () => {
})
})
+ it('lists direct connect sources separately from managed ones', async () => {
+ logic.mount()
+
+ sourceManagementLogic.actions.loadSourcesSuccess({
+ results: [
+ { id: 's1', source_type: 'Stripe', access_method: 'warehouse', schemas: [] },
+ { id: 's2', source_type: 'Postgres', prefix: 'prod', access_method: 'direct', schemas: [] },
+ { id: 's3', source_type: 'Snowflake', prefix: 'analytics', access_method: 'direct', schemas: [] },
+ ],
+ count: 3,
+ next: null,
+ previous: null,
+ } as any)
+
+ await expectLogic(logic).toMatchValues({
+ managedSources: [expect.objectContaining({ id: 's1' })],
+ directSources: [expect.objectContaining({ id: 's2' }), expect.objectContaining({ id: 's3' })],
+ })
+
+ logic.actions.setDirectSearchTerm('analytics')
+ await expectLogic(logic).toMatchValues({
+ filteredDirectSources: [expect.objectContaining({ id: 's3' })],
+ })
+ })
+
it('only includes tables with no source in selfManagedTables', async () => {
databaseLogic.mount()
logic.mount()