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): match managed sources by display label in search (#69060)

Javier Bahamondes7da027b85205
diff --git a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
index 2b1bcbec838b..3e041fa4856a 100644
--- a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
+++ b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
@@ -6,6 +6,7 @@ import posthog from 'posthog-js'
import api from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { deleteWithUndo } from 'lib/utils/deleteWithUndo'
+import { createFuse, Fuse } from 'lib/utils/fuseSearch'
import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import { DatabaseSchemaDataWarehouseTable } from '~/queries/schema/schema-general'
@@ -17,6 +18,7 @@ import {
ExternalDataSourceSchema,
} from '~/types'
+import { availableSourcesLogic } from '../../scenes/NewSourceScene/availableSourcesLogic'
import { joinsLogic } from './joinsLogic'
import type { sourceManagementLogicType } from './sourceManagementLogicType'
import { sourcesDataLogic } from './sourcesDataLogic'
@@ -31,6 +33,8 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([
['database', 'dataWarehouseTables'],
sourcesDataLogic,
['dataWarehouseSources', 'dataWarehouseSourcesLoading'],
+ availableSourcesLogic,
+ ['availableSources'],
],
actions: [
databaseTableListLogic,
@@ -146,22 +150,37 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([
return selfManagedTables.filter((table) => table.name.toLowerCase().includes(normalizedSearch))
},
],
- filteredManagedSources: [
- (s) => [s.dataWarehouseSources, s.managedSearchTerm],
- (dataWarehouseSources, managedSearchTerm): ExternalDataSource[] => {
- const sources = (dataWarehouseSources?.results ?? []).filter(
+ managedSources: [
+ (s) => [s.dataWarehouseSources],
+ (dataWarehouseSources): ExternalDataSource[] =>
+ (dataWarehouseSources?.results ?? []).filter(
(source) => source.access_method?.toLowerCase() !== 'direct'
- )
- if (!managedSearchTerm?.trim()) {
- return sources
+ ),
+ ],
+ // Search the display label as well as the internal source_type. Fuzzy, like the source catalog.
+ managedSourcesFuse: [
+ (s) => [s.managedSources, s.availableSources],
+ (managedSources, availableSources): Fuse<ExternalDataSource> =>
+ createFuse(managedSources, {
+ keys: [
+ {
+ name: 'label',
+ getFn: (source) => availableSources?.[source.source_type]?.label ?? source.source_type,
+ },
+ 'source_type',
+ 'prefix',
+ 'description',
+ ],
+ }),
+ ],
+ filteredManagedSources: [
+ (s) => [s.managedSources, s.managedSourcesFuse, s.managedSearchTerm],
+ (managedSources, managedSourcesFuse, managedSearchTerm): ExternalDataSource[] => {
+ const trimmed = managedSearchTerm?.trim()
+ if (!trimmed) {
+ return managedSources
}
- const normalizedSearch = managedSearchTerm.toLowerCase()
- return sources.filter(
- (source) =>
- source.source_type.toLowerCase().includes(normalizedSearch) ||
- source.prefix?.toLowerCase().includes(normalizedSearch) ||
- source.description?.toLowerCase().includes(normalizedSearch)
- )
+ return managedSourcesFuse.search(trimmed).map((r) => r.item)
},
],
hasZendeskSource: [
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 8d279ad2ffdc..c912aa706e93 100644
--- a/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts
+++ b/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts
@@ -8,6 +8,7 @@ import { DatabaseSchemaQueryResponse } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { ExternalDataSource } from '~/types'
+import { availableSourcesLogic } from '../../../scenes/NewSourceScene/availableSourcesLogic'
import { sourceManagementLogic } from '../sourceManagementLogic'
jest.mock('lib/api')
@@ -43,6 +44,30 @@ describe('sourceManagementLogic', () => {
databaseLogic.unmount()
})
+ it.each([
+ ['display label', 'Google ads'],
+ ['internal source_type', 'googleads'],
+ ])('finds a managed source by its %s', async (_, searchTerm) => {
+ jest.spyOn(api.externalDataSources, 'wizard').mockResolvedValue({
+ GoogleAds: { name: 'GoogleAds', label: 'Google Ads' },
+ } as any)
+
+ logic.mount()
+ await expectLogic(availableSourcesLogic).toDispatchActions(['loadSuccess'])
+
+ sourceManagementLogic.actions.loadSourcesSuccess({
+ results: [{ id: 's1', source_type: 'GoogleAds', access_method: 'warehouse', schemas: [] }],
+ count: 1,
+ next: null,
+ previous: null,
+ } as any)
+
+ logic.actions.setManagedSearchTerm(searchTerm)
+ await expectLogic(logic).toMatchValues({
+ filteredManagedSources: [expect.objectContaining({ source_type: 'GoogleAds' })],
+ })
+ })
+
it('only includes tables with no source in selfManagedTables', async () => {
databaseLogic.mount()
logic.mount()