: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(bi): show field descriptions and source check health (#124962)
Marius Andradc76bfc7c7ab
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.mdindex 93faf28f13b8..095cba419c3b 100644--- a/docs/published/handbook/engineering/data-warehouse.md+++ b/docs/published/handbook/engineering/data-warehouse.md@@ -437,7 +437,7 @@ Implementation audit, October 28, 2026. These are proposed integration contracts- [x] Adopt the catalog overwrite-confirmation flow for worksheet metric proposals. Preserve entered values on cancel, allow retry, and keep overwritten metrics proposed.- [x] Show catalog trust context when exploring a metric: approval and drift status, unit, owner, and stable identity. Saved copies retain metadata from copy time, labeled **Catalog status when copied (unverified)** without positive approval styling. Only Proposed and Approved statuses are recorded. Older copies explicitly say no status was recorded. The metadata is editable worksheet content, not verified provenance or a live approval; authors are directed to the current catalog entry. Live version checks remain shared-layer work.- [x] Add deliberate, searchable metric discovery in BI using the existing catalog search API. The picker handles loading, failure, no matches, pagination, and unsupported definition kinds explicitly.-- [ ] Surface existing field descriptions and data-quality context in the data pane. Preserve raw field identities and distinguish certification from current check health.+- [x] Surface existing table and view field descriptions in the data pane, including related tables. Show recorded data-quality check health separately from certification, with explicit unavailable, unchecked, and error states. Raw field identities remain unchanged.### Shared-layer requestsdiff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 65425bee9ef8..22de0b07da45 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6802,6 +6802,22 @@ snapshots:hash: v1.k794b7964.5272d9fc095372492de4bc666a4fd7c995c2fb3de8c859a48ddbf7dae5094c8b.VCgPn7znPvjkY-Sx_PsctneSMhp8KtDuBPxFoGjYdPAproducts-business-intelligence-scatter--read-only--light:hash: v1.k794b7964.21cf4e3c6d31ac5d3653d176f876dbec5894d2569bd082e4fc5117a7dbe40af3.b-Dnoj2QTxOlUnZTMZuBqQGvSNk2lnMS0V6wnY_Aud0+ products-business-intelligence-source-health--error--dark:+ hash: v1.k794b7964.e55e642803d235180cd19f951368d12698df3adc97164683a5f585d00374617a.10Zr7vH5JoME2gR--lXPvH1BC_YAXXhiPtG7vnNRdYs+ products-business-intelligence-source-health--error--light:+ hash: v1.k794b7964.351b3ec8e9639cac0f7bb8497b295601aed67f4e9aa8dca9631bd3e7f3d447ca.f3IadStFIm-AL7AWwenFn2gHGdeTKDZcKfwZhWesNWQ+ products-business-intelligence-source-health--failing--dark:+ hash: v1.k794b7964.70995d848776a1abd9b226114a05066bfea8ea3aca12c7db0faff84e276b7a24.UM3d0qoKL1nIiozVBEDpIWWw1mPFsCYpbGyoOhH8no4+ products-business-intelligence-source-health--failing--light:+ hash: v1.k794b7964.37b8fa962f0ec79ba7a8e112206eae700afd11f8425099bc81f0c6095b0b51a8.XfiSLVnO2S7c1HhG4BKjWhMcuYg1UxgdObEHepHKL2c+ products-business-intelligence-source-health--unavailable--dark:+ hash: v1.k794b7964.4657af431223fb9f7c94710d176568b882ab46627e625eeadd35977adcb70c20.96FcM6xFh5WcBIy-zvKetxaL5Iy1yXLfUGO7z5zwslc+ products-business-intelligence-source-health--unavailable--light:+ hash: v1.k794b7964.838dd4905b2bc4c870b53e2a1e7aa88a8dbc25921198384ffb7f1fd107832fec.yeITttzv_gPbpB03JhM8YZ8zc8dpV5CJvWXD_LM7D8M+ products-business-intelligence-source-health--unchecked--dark:+ hash: v1.k794b7964.610de38001f5bc8fd92e79912cdd1c686294d94b2ce975261251a8e3ebeb6678.vzs8c07HMykac-2_ABIVd0sGTHs5OibMmErq7wj9xuw+ products-business-intelligence-source-health--unchecked--light:+ hash: v1.k794b7964.112ead2222e857b3247d1f421fabeb99754fe244fbc54282f8458b5d0f254475.1w4xZj1-mrUWM0vxCo8jM5DyfAVxK9AbQ8ActvPg-2Iproducts-business-intelligence-worksheet-exploration--catalog-metric-parameters--dark:hash: v1.k794b7964.8fefa0b4720ec5e2a555da632ceb950910aa46fd16a7bd1d40111ddb331ee3ad.ksRj5txXEFCxPL705jBaTN7m1rUiLBFrJkz3pE0Kq6sproducts-business-intelligence-worksheet-exploration--catalog-metric-parameters--light:@@ -6827,9 +6843,9 @@ snapshots:products-business-intelligence-worksheet-exploration--nested-panes-narrow--light:hash: v1.k794b7964.10c232baf0e2d4c1afcc5fb2be5acddc52a30dc4404875e96de9c0e2070614f4.RMRmcYG-Phs-D2knyQeqbJHzqJKwrp57f9c5g1Tgd_0products-business-intelligence-worksheet-exploration--relationship-key-check--dark:- hash: v1.k794b7964.2a11a78e396147fd11cc26642853e3cc96e277c51ca2e2abed410b7b26de00b5.BCmW-8EYSpraeogrER9QgS7iPpgfF0cKuZpI9PjvKPs+ hash: v1.k794b7964.cb23e7cb076cdbc6cd66a72153e6b3c85e51eea97e69aecc2807fe34c25e2199.uXZ6kfVfdQVC_-Vd8sPLhDP6YNfoYd9OC9MMGbWGTOwproducts-business-intelligence-worksheet-exploration--relationship-key-check--light:- hash: v1.k794b7964.7cadfcd686a396debfecfb0e8479f27b3e05d17a97d705d8abb3b2c232d346be.pOtL9jQKqz5nFkHkCrl_1hOAvKF5qOvCYPg2ihea0HU+ hash: v1.k794b7964.029013456e3f15d43cc073ff61da04d5cfa1c17b99c73c632c316316241ac740.4BaeetRUMQRxDjDleygqgr-ND0w__kS9sr2aADoKOQAproducts-business-intelligence-worksheet-exploration--scatter-selection--dark:hash: v1.k794b7964.ee16fb7d4d6e6dc398f1c164ce88f1ac8d7226449171daa2ad74695a64b5b306.Ia7P6JWA8-O6kyHAk-a_LzZplfWxDHaDifEW5vvYXzgproducts-business-intelligence-worksheet-exploration--scatter-selection--light:diff --git a/products/business_intelligence/frontend/BIConnectionGroup.tsx b/products/business_intelligence/frontend/BIConnectionGroup.tsxindex 6cf123d37e29..ebda7fcf8159 100644--- a/products/business_intelligence/frontend/BIConnectionGroup.tsx+++ b/products/business_intelligence/frontend/BIConnectionGroup.tsx@@ -60,12 +60,14 @@ export function BIConnectionGroup({ connections }: { connections: BIConnection[]<BIDataPaneSectionfields={connection.fields.dimensions}path={connection.path}+ tableName={connection.tableName}measure={false}emptyText="No matching dimensions"/><BIDataPaneSectionfields={connection.fields.measures}path={connection.path}+ tableName={connection.tableName}measureemptyText="No matching measures"/>diff --git a/products/business_intelligence/frontend/BIDataPaneField.tsx b/products/business_intelligence/frontend/BIDataPaneField.tsxindex aa5b2f6704e4..bf7d3de59702 100644--- a/products/business_intelligence/frontend/BIDataPaneField.tsx+++ b/products/business_intelligence/frontend/BIDataPaneField.tsx@@ -1,7 +1,7 @@import { useActions, useMountedLogic, useValues } from 'kea'-import { IconCalendar, IconEllipsis } from '@posthog/icons'-import { LemonButton, LemonMenu } from '@posthog/lemon-ui'+import { IconCalendar, IconEllipsis, IconInfo } from '@posthog/icons'+import { LemonButton, LemonMenu, Tooltip } from '@posthog/lemon-ui'import { cn } from 'lib/utils/css-classes'@@ -49,10 +49,12 @@ export function BIDataPaneField({field,measure,path = [],+ description,}: {field: BIFieldmeasure: booleanpath?: string[]+ description?: string}): JSX.Element {const editor = useMountedLogic(biEditorLogic)const { config } = useValues(editor)@@ -98,6 +100,11 @@ export function BIDataPaneField({<span className="truncate">{path.length ? field.name.slice(path.join('.').length + 1) : field.name}</span>+ {description && (+ <Tooltip title={description}>+ <IconInfo className="shrink-0 text-secondary" aria-label={description} />+ </Tooltip>+ )}</button>{(field.localDefinition || isNumericBIField(field) || ['string', 'boolean'].includes(field.type)) && (<LemonMenudiff --git a/products/business_intelligence/frontend/BIDataPaneSection.tsx b/products/business_intelligence/frontend/BIDataPaneSection.tsxindex 2dcf7cfb92a3..e5dd4bb77a3b 100644--- a/products/business_intelligence/frontend/BIDataPaneSection.tsx+++ b/products/business_intelligence/frontend/BIDataPaneSection.tsx@@ -6,6 +6,7 @@ import { BIDataPaneField } from './BIDataPaneField'import { biEditorLogic } from './biEditorLogic'import { BIPropertyFieldGroup } from './BIPropertyFieldGroup'import { getBIPropertyTarget } from './biPropertyFields'+import { biSourceMetadataLogic } from './biSourceMetadataLogic'export function BIDataPaneSection({title,@@ -13,15 +14,24 @@ export function BIDataPaneSection({measure,emptyText,path = [],+ tableName,}: {title?: stringfields: BIField[]measure: booleanemptyText: stringpath?: string[]+ tableName?: string}): JSX.Element {const logic = useMountedLogic(biEditorLogic)- const { dataPaneSearch } = useValues(logic)+ const { dataPaneSearch, config, allTables, databaseConnectionId } = useValues(logic)+ const table =+ !config.source?.connectionId && !databaseConnectionId+ ? allTables.find(+ (candidate) => candidate.name === (tableName ?? (path.length ? undefined : config.source?.table))+ )+ : undefined+ const { annotations, annotationsError } = useValues(biSourceMetadataLogic({ table }))return (<div className="flex flex-col">{title ? <div className="px-2 pb-1 pt-2 text-xs font-semibold text-secondary">{title}</div> : null}@@ -36,7 +46,17 @@ export function BIDataPaneSection({dataPaneSearch={dataPaneSearch}/>) : (- <BIDataPaneField key={field.id} field={field} measure={measure} path={path} />+ <BIDataPaneField+ key={field.id}+ field={field}+ measure={measure}+ path={path}+ description={+ field.localDefinition || annotationsError+ ? undefined+ : annotations[path.length ? field.name.slice(path.join('.').length + 1) : field.name]+ }+ />))}</div>diff --git a/products/business_intelligence/frontend/BISourceContext.tsx b/products/business_intelligence/frontend/BISourceContext.tsxindex 8f8bb28dc1fc..eb37a9b1408a 100644--- a/products/business_intelligence/frontend/BISourceContext.tsx+++ b/products/business_intelligence/frontend/BISourceContext.tsx@@ -13,6 +13,8 @@ import { captureBIWorksheetAction } from './biEditorAnalytics'import { biEditorLogic } from './biEditorLogic'import { joinKeyCheckQuery } from './biJoinKeyCheck'import { biSourceContextLogic } from './biSourceContextLogic'+import { BISourceHealth } from './BISourceHealth'+import { biSourceMetadataLogic } from './biSourceMetadataLogic'export function BISourceContext({ table }: { table: DatabaseSchemaTable }): JSX.Element {const { config } = useValues(biEditorLogic)@@ -20,6 +22,10 @@ export function BISourceContext({ table }: { table: DatabaseSchemaTable }): JSX.biSourceContextLogic({ table }))const { loadRelationships } = useActions(biSourceContextLogic({ table }))+ const metadata = biSourceMetadataLogic({ table })+ const { annotations, annotationsError, annotationsLoading, health, healthError, healthLoading } =+ useValues(metadata)+ const { loadAnnotations, loadHealth } = useActions(metadata)const catalog = `${urls.dataCatalog('relationships')}&table=${encodeURIComponent(table.name)}`return (<details className="min-w-0 text-xs" data-attr="bi-source-context">@@ -33,8 +39,19 @@ export function BISourceContext({ table }: { table: DatabaseSchemaTable }): JSX.aria-label="Catalog details"tabIndex={0}>- {description && <p className="m-0 break-words text-secondary">{description}</p>}+ {(description || annotations['']) && (+ <p className="m-0 break-words text-secondary">{description || annotations['']}</p>+ )}+ {annotationsError && (+ <div>+ Couldn't load field descriptions.{' '}+ <LemonButton size="xsmall" loading={annotationsLoading} onClick={() => loadAnnotations()}>+ Retry+ </LemonButton>+ </div>+ )}{table.certification?.notes && <p className="m-0 break-words">{table.certification.notes}</p>}+ <BISourceHealth health={health} loading={healthLoading} error={healthError} retry={loadHealth} /><LemonButtonsize="xsmall"sideIcon={<IconExternal />}diff --git a/products/business_intelligence/frontend/BISourceHealth.stories.tsx b/products/business_intelligence/frontend/BISourceHealth.stories.tsxnew file mode 100644index 000000000000..121ae2a3f99a--- /dev/null+++ b/products/business_intelligence/frontend/BISourceHealth.stories.tsx@@ -0,0 +1,36 @@+import { Meta, StoryObj } from '@storybook/react'++import { BISourceHealth } from './BISourceHealth'++const meta: Meta<typeof BISourceHealth> = {+ title: 'Products/Business intelligence/Source health',+ component: BISourceHealth,+ args: {+ health: {+ subject_type: 'table',+ subject_uuid: 'example',+ health: 'failing',+ checks_total: 3,+ checks_failing: 1,+ },+ loading: false,+ error: false,+ retry: () => {},+ },+}+export default meta+type Story = StoryObj<typeof meta>+export const Failing: Story = {}+export const Unchecked: Story = {+ args: {+ health: {+ subject_type: 'table',+ subject_uuid: 'example',+ health: 'unknown',+ checks_total: 0,+ checks_failing: 0,+ },+ },+}+export const Unavailable: Story = { args: { health: null } }+export const Error: Story = { args: { health: null, error: true } }diff --git a/products/business_intelligence/frontend/BISourceHealth.tsx b/products/business_intelligence/frontend/BISourceHealth.tsxnew file mode 100644index 000000000000..5100bb70ad99--- /dev/null+++ b/products/business_intelligence/frontend/BISourceHealth.tsx@@ -0,0 +1,48 @@+import { LemonButton, LemonTag } from '@posthog/lemon-ui'++import { HEALTH_LABELS, HEALTH_TAG_TYPES } from 'products/data_quality/frontend/checksConstants'+import { DataQualitySubjectHealthApi } from 'products/data_quality/frontend/generated/api.schemas'++export function BISourceHealth({+ health,+ loading,+ error,+ retry,+}: {+ health: DataQualitySubjectHealthApi | null+ loading: boolean+ error: boolean+ retry: () => void+}): JSX.Element {+ return (+ <div className="flex flex-col gap-1" aria-label="Data quality check health">+ <span className="font-semibold">Data quality checks</span>+ {loading ? (+ <span>Loading check health…</span>+ ) : error ? (+ <div>+ Couldn't load check health.{' '}+ <LemonButton size="xsmall" onClick={retry} loading={loading}>+ Retry+ </LemonButton>+ </div>+ ) : health ? (+ health.checks_total === 0 ? (+ <span>No enabled checks.</span>+ ) : (+ <div className="flex flex-wrap items-center gap-1">+ <LemonTag type={HEALTH_TAG_TYPES[health.health] ?? 'muted'}>+ {HEALTH_LABELS[health.health] ?? 'Unknown'}+ </LemonTag>+ <span>+ {health.checks_total} enabled · {health.checks_failing} failing+ </span>+ </div>+ )+ ) : (+ <span>Check health is unavailable for this source.</span>+ )}+ <span className="text-secondary">Latest recorded check results. Certification is a separate review.</span>+ </div>+ )+}diff --git a/products/business_intelligence/frontend/biSourceContextLogic.ts b/products/business_intelligence/frontend/biSourceContextLogic.tsindex d650b27f572c..027965eac353 100644--- a/products/business_intelligence/frontend/biSourceContextLogic.ts+++ b/products/business_intelligence/frontend/biSourceContextLogic.ts@@ -9,10 +9,9 @@ import { DataWarehouseViewLink } from '~/types'import { dataCatalogRelationshipProposalsList } from 'products/data_catalog/frontend/generated/api'import { DataCatalogRelationshipProposalApi } from 'products/data_catalog/frontend/generated/api.schemas'-import {- warehouseColumnAnnotationsList,- warehouseSavedQueriesRetrieve,-} from 'products/data_warehouse/frontend/generated/api'+import { warehouseSavedQueriesRetrieve } from 'products/data_warehouse/frontend/generated/api'++import { biSourceMetadataLogic } from './biSourceMetadataLogic'export interface BISourceContextProps {table: DatabaseSchemaTable@@ -34,6 +33,7 @@ export interface biSourceContextLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface biSourceContextLogicActions {+ loadHealth: (_?: void | undefined) => void // biSourceMetadataLogicloadDescription: () => anyloadDescriptionFailure: (error: string,@@ -91,7 +91,10 @@ export const biSourceContextLogic = kea<biSourceContextLogicType>([props({} as BISourceContextProps),key(({ table }) => table.id + ':' + table.name),path((key) => ['products', 'business_intelligence', 'biSourceContextLogic', key]),- connect({ values: [databaseTableListLogic, ['database']] }),+ connect((props: BISourceContextProps) => ({+ values: [databaseTableListLogic, ['database']],+ actions: [biSourceMetadataLogic(props), ['loadHealth']],+ })),loaders(({ props, values }) => ({description: ['',@@ -101,10 +104,6 @@ export const biSourceContextLogic = kea<biSourceContextLogicType>([if (props.table.type === 'view' || props.table.type === 'materialized_view') {return (await warehouseSavedQueriesRetrieve(project, props.table.id)).description ?? ''}- if (props.table.type === 'data_warehouse' && props.table.id) {- const result = await warehouseColumnAnnotationsList(project, { table_id: props.table.id })- return result.results.find((annotation) => annotation.column_name === '')?.description ?? ''- }return ''},},@@ -148,5 +147,6 @@ export const biSourceContextLogic = kea<biSourceContextLogicType>([afterMount(({ actions }) => {actions.loadDescription()actions.loadRelationships()+ actions.loadHealth()}),])diff --git a/products/business_intelligence/frontend/biSourceMetadataLogic.test.ts b/products/business_intelligence/frontend/biSourceMetadataLogic.test.tsnew file mode 100644index 000000000000..df986e8b5dd3--- /dev/null+++ b/products/business_intelligence/frontend/biSourceMetadataLogic.test.ts@@ -0,0 +1,148 @@+import { expectLogic } from 'kea-test-utils'++import { useMocks } from '~/mocks/jest'+import { DatabaseSchemaTable } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'++import { biSourceContextLogic } from './biSourceContextLogic'+import { biSourceMetadataLogic } from './biSourceMetadataLogic'++const table: DatabaseSchemaTable = { id: 'table-example', name: 'purchases', type: 'data_warehouse', fields: {} }+beforeEach(() => initKeaTests())++it('loads all annotation pages and keeps check health independent of certification', async () => {+ const offsets: string[] = []+ useMocks({+ get: {+ '/api/projects/:team_id/warehouse_column_annotations/': ({ request }) => {+ const offset = new URL(request.url).searchParams.get('offset')!+ offsets.push(offset)+ return offset === '0'+ ? { results: [{ column_name: '', description: 'Completed purchases' }], next: 'next' }+ : { results: [{ column_name: 'amount', description: 'Amount in cents' }], next: null }+ },+ '/api/projects/:team_id/data_quality_checks/health/': [+ {+ subject_type: 'table',+ subject_uuid: table.id,+ health: 'failing',+ checks_total: 2,+ checks_failing: 1,+ },+ ],+ },+ })+ const logic = biSourceMetadataLogic({ table })+ await expectLogic(logic, () => {+ logic.mount()+ logic.actions.loadHealth()+ }).toFinishAllListeners()+ expect(offsets).toEqual(['0', '1'])+ expect(logic.values.annotations).toEqual({ '': 'Completed purchases', amount: 'Amount in cents' })+ expect(logic.values.health?.health).toBe('failing')+ logic.unmount()+})++it('resolves native table identity before asking for health and isolates table metadata', async () => {+ const requestedIds: string[] = []+ useMocks({+ get: {+ '/api/projects/:team_id/data_quality_checks/subjects/': [+ { name: 'events', id: 'native-event-id', subject_type: 'posthog_table' },+ ],+ '/api/projects/:team_id/data_quality_checks/health/': ({ request }) => {+ requestedIds.push(new URL(request.url).searchParams.get('subject_uuid')!)+ return []+ },+ '/api/projects/:team_id/warehouse_column_annotations/': {+ results: [{ column_name: 'amount', description: 'Only on purchases' }],+ next: null,+ },+ },+ })+ const source = biSourceMetadataLogic({ table })+ await expectLogic(source, () => {+ source.mount()+ source.actions.loadHealth()+ }).toFinishAllListeners()+ const native = biSourceMetadataLogic({ table: { ...table, id: 'events', name: 'events', type: 'posthog' } })+ await expectLogic(native, () => {+ native.mount()+ native.actions.loadHealth()+ }).toFinishAllListeners()+ expect(requestedIds).toEqual([table.id, 'native-event-id'])+ expect(native.values.annotations).toEqual({})+ expect(native.values.health).toMatchObject({ checks_total: 0, health: 'unknown' })+ expect(source.values.annotations.amount).toBe('Only on purchases')+ source.unmount()+ native.unmount()+})++it('does not turn failed requests into healthy or unchecked sources and retries', async () => {+ let fail = true+ useMocks({+ get: {+ '/api/projects/:team_id/warehouse_column_annotations/': { results: [], next: null },+ '/api/projects/:team_id/data_quality_checks/health/': () => (fail ? [403, { detail: 'Unavailable' }] : []),+ },+ })+ const logic = biSourceMetadataLogic({ table })+ await expectLogic(logic, () => {+ logic.mount()+ logic.actions.loadHealth()+ }).toFinishAllListeners()+ expect(logic.values.healthError).toBe(true)+ expect(logic.values.health).toBeNull()+ fail = false+ await expectLogic(logic, () => logic.actions.loadHealth()).toFinishAllListeners()+ expect(logic.values.healthError).toBe(false)+ expect(logic.values.health?.checks_total).toBe(0)+ logic.unmount()+})++it('keeps prototype-like column names safe before and after annotation loading', async () => {+ useMocks({+ get: {+ '/api/projects/:team_id/warehouse_column_annotations/': {+ results: [+ { column_name: 'constructor', description: 'Assembly method' },+ { column_name: '__proto__', description: 'A literal source column' },+ ],+ next: null,+ },+ },+ })+ const logic = biSourceMetadataLogic({ table })+ logic.mount()+ expect(logic.values.annotations.constructor).toBeUndefined()+ expect(logic.values.annotations.__proto__).toBeUndefined()+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.annotations.constructor).toBe('Assembly method')+ expect(logic.values.annotations.__proto__).toBe('A literal source column')+ expect(logic.values.annotations.toString).toBeUndefined()+ logic.unmount()+})++it('loads health only when the source-details consumer mounts', async () => {+ const health = jest.fn(() => [])+ useMocks({+ get: {+ '/api/projects/:team_id/warehouse_column_annotations/': { results: [], next: null },+ '/api/projects/:team_id/data_quality_checks/health/': health,+ '/api/projects/:team_id/data_catalog/relationship_proposals/': { results: [], next: null },+ },+ })+ const fields = biSourceMetadataLogic({ table })+ await expectLogic(fields, () => {+ fields.mount()+ }).toFinishAllListeners()+ expect(health).not.toHaveBeenCalled()+ const context = biSourceContextLogic({ table })+ await expectLogic(context, () => {+ context.mount()+ }).toFinishAllListeners()+ await expectLogic(fields).toFinishAllListeners()+ expect(health).toHaveBeenCalledTimes(1)+ context.unmount()+ fields.unmount()+})diff --git a/products/business_intelligence/frontend/biSourceMetadataLogic.ts b/products/business_intelligence/frontend/biSourceMetadataLogic.tsnew file mode 100644index 000000000000..699e4f97d672--- /dev/null+++ b/products/business_intelligence/frontend/biSourceMetadataLogic.ts@@ -0,0 +1,180 @@+import { LogicWrapper, MakeLogicType, afterMount, kea, key, path, props, reducers } from 'kea'+import { loaders } from 'kea-loaders'++import { teamLogic } from 'scenes/teamLogic'++import { DatabaseSchemaTable } from '~/queries/schema/schema-general'++import * as qualityApi from 'products/data_quality/frontend/generated/api'+import { DataQualitySubjectHealthApi } from 'products/data_quality/frontend/generated/api.schemas'+import * as warehouseApi from 'products/data_warehouse/frontend/generated/api'++export interface BISourceMetadataProps {+ table?: DatabaseSchemaTable+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface biSourceMetadataLogicValues {+ annotations: Record<string, string>+ annotationsError: boolean+ annotationsLoading: boolean+ health: DataQualitySubjectHealthApi | null+ healthError: boolean+ healthLoading: boolean+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface biSourceMetadataLogicActions {+ loadAnnotations: (_: void) => void+ loadAnnotationsFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadAnnotationsSuccess: (+ annotations: Record<string, string>,+ payload?: void+ ) => {+ annotations: Record<string, string>+ payload?: void+ }+ loadHealth: (_: void) => void+ loadHealthFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadHealthSuccess: (+ health: DataQualitySubjectHealthApi | null,+ payload?: void+ ) => {+ health: DataQualitySubjectHealthApi | null+ payload?: void+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface biSourceMetadataLogicMeta {+ key: string+}++export type biSourceMetadataLogicType = MakeLogicType<+ biSourceMetadataLogicValues,+ biSourceMetadataLogicActions,+ BISourceMetadataProps,+ biSourceMetadataLogicMeta+>++export const biSourceMetadataLogic: LogicWrapper<biSourceMetadataLogicType> = kea<biSourceMetadataLogicType>([+ props({} as BISourceMetadataProps),+ key(({ table }) => (table ? `${table.type}:${table.id}:${table.name}` : 'none')),+ path((key) => ['products', 'business_intelligence', 'biSourceMetadataLogic', key]),+ reducers({+ annotationsError: [false, { loadAnnotations: () => false, loadAnnotationsFailure: () => true }],+ healthError: [false, { loadHealth: () => false, loadHealthFailure: () => true }],+ }),+ loaders(({ props }) => ({+ annotations: [+ Object.create(null) as Record<string, string>,+ {+ loadAnnotations: async (_: void, breakpoint): Promise<Record<string, string>> => {+ const table = props.table+ if (!table || !['data_warehouse', 'view', 'materialized_view'].includes(table.type) || !table.id) {+ return Object.create(null) as Record<string, string>+ }+ const project = String(teamLogic.values.currentTeamId)+ const annotations = Object.create(null) as Record<string, string>+ let offset = 0+ while (true) {+ const result =+ table.type === 'data_warehouse'+ ? await warehouseApi.warehouseColumnAnnotationsList(project, {+ table_id: table.id,+ limit: 100,+ offset,+ })+ : await warehouseApi.savedQueryColumnAnnotationsList(project, {+ saved_query_id: table.id,+ limit: 100,+ offset,+ })+ breakpoint()+ for (const annotation of result.results) {+ annotations[annotation.column_name ?? ''] = annotation.description+ }+ if (!result.next || !result.results.length) {+ return annotations+ }+ offset += result.results.length+ }+ },+ },+ ],+ health: [+ null as DataQualitySubjectHealthApi | null,+ {+ loadHealth: async (_: void, breakpoint): Promise<DataQualitySubjectHealthApi | null> => {+ const table = props.table+ if (!table) {+ return null+ }+ const project = String(teamLogic.values.currentTeamId)+ const subjectType =+ table.type === 'data_warehouse'+ ? 'table'+ : ['view', 'materialized_view'].includes(table.type)+ ? 'view'+ : table.type === 'posthog'+ ? 'posthog_table'+ : null+ if (!subjectType || !table.id) {+ return null+ }+ let subjectId = table.id+ if (subjectType === 'posthog_table') {+ let offset = 0+ while (true) {+ const subjects = await qualityApi.dataQualityChecksSubjectsList(project, {+ subject_type: 'posthog_table',+ search: table.name,+ limit: 100,+ offset,+ })+ breakpoint()+ const subject = subjects.find((candidate) => candidate.name === table.name)+ if (subject) {+ subjectId = subject.id+ break+ }+ if (subjects.length < 100) {+ return null+ }+ offset += subjects.length+ }+ }+ const rollups = await qualityApi.dataQualityChecksHealthList(project, {+ subject_type: subjectType,+ subject_uuid: subjectId,+ })+ breakpoint()+ return (+ rollups[0] ?? {+ subject_type: subjectType,+ subject_uuid: subjectId,+ health: 'unknown',+ checks_total: 0,+ checks_failing: 0,+ }+ )+ },+ },+ ],+ })),+ afterMount(({ actions }) => {+ actions.loadAnnotations()+ }),+])