: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(data-catalog): sort every column in the catalog tables (#119804)
Sinan Kucukkoseler4443268a5ea9
diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 2efffa3067a8..b023a5bbf453 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -3298,6 +3298,9 @@ importers:kea-router:specifier: 'catalog:'version: 3.4.2([email protected](patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected]))+ posthog-js:+ specifier: 'catalog:'+ version: 1.438.12(@types/[email protected])([email protected])react:specifier: 18.3.1version: 18.3.1diff --git a/products/data_catalog/frontend/common.ts b/products/data_catalog/frontend/common.tsindex efad58c06b6e..b89fc0bd5bd1 100644--- a/products/data_catalog/frontend/common.ts+++ b/products/data_catalog/frontend/common.ts@@ -1,3 +1,7 @@+import posthog from 'posthog-js'++import type { Sorting } from '@posthog/lemon-ui'+export const METRIC_NAME_REGEX = /^[A-Za-z][A-Za-z0-9_]*$/export const HOGQL_METRIC_DEFINITION_KIND = 'HogQLQuery'@@ -49,6 +53,20 @@ export const METRIC_MARKDOWN_MAX_LENGTH = 20000// Mirrors METRIC_BULK_MAX enforced in products/data_catalog/backend/logic/metrics.py.export const METRIC_BULK_MAX = 100+export type DataCatalogTable = 'metrics' | 'relationships' | 'certifications'++export function compareText(a: string | null | undefined, b: string | null | undefined): number {+ return (a ?? '').localeCompare(b ?? '')+}++export function reportCatalogTableSorted(table: DataCatalogTable, sorting: Sorting | null): void {+ posthog.capture('data catalog table sorted', {+ table,+ column: sorting?.columnKey ?? null,+ order: sorting ? (sorting.order === 1 ? 'asc' : 'desc') : null,+ })+}+export function metricCount(count: number): string {return `${count} ${count === 1 ? 'metric' : 'metrics'}`}diff --git a/products/data_catalog/frontend/relationshipsLogic.test.ts b/products/data_catalog/frontend/relationshipsLogic.test.tsindex caaa1aa09b0f..19cfdf263d7d 100644--- a/products/data_catalog/frontend/relationshipsLogic.test.ts+++ b/products/data_catalog/frontend/relationshipsLogic.test.ts@@ -134,6 +134,17 @@ describe('relationshipsLogic', () => {).toFinishAllListeners()expect(dataCatalogRelationshipProposalsList).toHaveBeenLastCalledWith('1', { table_name: 'events' })expect(logic.values.proposals).toHaveLength(1)+ const listCalls = (dataCatalogRelationshipProposalsList as jest.Mock).mock.calls.length+ const joinCalls = (warehouseViewLinksList as jest.Mock).mock.calls.length+ await expectLogic(logic, () =>+ router.actions.push('/data-catalog', {+ tab: 'relationships',+ table: 'events',+ 'data-catalog-relationships_order': '-confidence',+ })+ ).toFinishAllListeners()+ expect(dataCatalogRelationshipProposalsList).toHaveBeenCalledTimes(listCalls)+ expect(warehouseViewLinksList).toHaveBeenCalledTimes(joinCalls)await expectLogic(logic, () => logic.actions.loadProposals()).toFinishAllListeners()expect(dataCatalogRelationshipProposalsList).toHaveBeenLastCalledWith('1', { table_name: 'events' })await expectLogic(logic, () =>diff --git a/products/data_catalog/frontend/relationshipsLogic.tsx b/products/data_catalog/frontend/relationshipsLogic.tsxindex b22902f1db62..b833eaa1cc9c 100644--- a/products/data_catalog/frontend/relationshipsLogic.tsx+++ b/products/data_catalog/frontend/relationshipsLogic.tsx@@ -472,7 +472,7 @@ export const relationshipsLogic = kea<relationshipsLogicType>([})),urlToAction(({ actions, values }) => ({// Load the full proposals and joins only when the Relationships tab is actually viewed.- [urls.dataCatalog()]: (_, searchParams) => {+ [urls.dataCatalog()]: (_, searchParams, __, currentLocation, previousLocation) => {if (searchParams.tab === 'relationships') {if (typeof searchParams.table === 'string') {actions.setFilters({ search: searchParams.table })@@ -480,8 +480,15 @@ export const relationshipsLogic = kea<relationshipsLogicType>([if (typeof searchParams.propose_table === 'string' && !values.proposalOpen) {actions.openProposal(searchParams.propose_table)}- actions.loadProposals()- actions.loadJoins()+ // The table writes its sort order to the URL, so reload only on tab entry or a new table scope.+ const enteredTab =+ currentLocation.initial ||+ currentLocation.pathname !== previousLocation?.pathname ||+ previousLocation?.searchParams.tab !== 'relationships'+ if (enteredTab || previousLocation?.searchParams.table !== searchParams.table) {+ actions.loadProposals()+ actions.loadJoins()+ }}},})),diff --git a/products/data_catalog/frontend/tabs/CertificationsTab.tsx b/products/data_catalog/frontend/tabs/CertificationsTab.tsxindex cd734d07cf8c..fb18791a0c1b 100644--- a/products/data_catalog/frontend/tabs/CertificationsTab.tsx+++ b/products/data_catalog/frontend/tabs/CertificationsTab.tsx@@ -10,6 +10,7 @@ import { LemonTable, LemonTableColumns } from 'lib/lemon-ui/LemonTable'import { LemonTag } from 'lib/lemon-ui/LemonTag'import { CertificationStatusFilter, certificationsLogic } from '../certificationsLogic'+import { compareText, reportCatalogTableSorted } from '../common'import { NewCertificationModal } from '../components/NewCertificationModal'import type { DataCatalogCertificationApi } from '../generated/api.schemas'@@ -59,11 +60,13 @@ export function CertificationsTab(): JSX.Element {title: 'Target',key: 'target_name',render: (_, certification) => certification.target_name,+ sorter: (a, b) => compareText(a.target_name, b.target_name),},{title: 'Type',key: 'target_type',render: (_, certification) => <LemonTag type="option">{certification.target_type}</LemonTag>,+ sorter: (a, b) => compareText(a.target_type, b.target_type),},{title: 'Status',@@ -75,17 +78,20 @@ export function CertificationsTab(): JSX.Element {: (STATUS_TAG[certification.status] ?? { label: certification.status, type: 'muted' as const })return <LemonTag type={tag.type}>{tag.label}</LemonTag>},+ sorter: (a, b) => compareText(a.status, b.status) || compareText(a.proposed_status, b.proposed_status),},{title: 'Notes',key: 'notes',render: (_, certification) => certification.notes || <span className="text-secondary">-</span>,+ sorter: (a, b) => compareText(a.notes, b.notes),},{title: 'Certified by',key: 'certified_by',render: (_, certification) =>certification.certified_by?.email || <span className="text-secondary">-</span>,+ sorter: (a, b) => compareText(a.certified_by?.email, b.certified_by?.email),},{key: 'actions',@@ -167,6 +173,7 @@ export function CertificationsTab(): JSX.Element {</div></div><LemonTable+ id="data-catalog-certifications"data-attr="data-catalog-certifications-table"dataSource={filteredCertifications}rowKey="id"@@ -175,6 +182,7 @@ export function CertificationsTab(): JSX.Element {pagination={{ pageSize: 20 }}emptyState="No certifications match your filters."nouns={['certification', 'certifications']}+ onSort={(sorting) => reportCatalogTableSorted('certifications', sorting)}/><NewCertificationModal /></div>diff --git a/products/data_catalog/frontend/tabs/MetricsTab.tsx b/products/data_catalog/frontend/tabs/MetricsTab.tsxindex 3cc7c9a5a51a..0448b2f8ace9 100644--- a/products/data_catalog/frontend/tabs/MetricsTab.tsx+++ b/products/data_catalog/frontend/tabs/MetricsTab.tsx@@ -15,7 +15,7 @@ import { LemonTag } from 'lib/lemon-ui/LemonTag'import { Tooltip } from 'lib/lemon-ui/Tooltip'import { urls } from 'scenes/urls'-import { METRIC_BULK_MAX, humanizeDefinitionKind, metricCount } from '../common'+import { METRIC_BULK_MAX, compareText, humanizeDefinitionKind, metricCount, reportCatalogTableSorted } from '../common'import type { DataCatalogMetricApi } from '../generated/api.schemas'import { BulkMetricAction, MetricStatusFilter, metricsLogic } from '../metricsLogic'@@ -152,27 +152,32 @@ export function MetricsTab(): JSX.Element {}/>),- sorter: (a, b) => a.name.localeCompare(b.name),+ sorter: (a, b) => compareText(a.display_name || a.name, b.display_name || b.name),},{title: 'Status',key: 'status',render: (_, metric) => <StatusTag metric={metric} />,+ sorter: (a, b) => compareText(a.status, b.status) || Number(a.is_drifted) - Number(b.is_drifted),},{title: 'Definition',key: 'definition_kind',render: (_, metric) => <LemonTag type="option">{humanizeDefinitionKind(metric.definition_kind)}</LemonTag>,+ sorter: (a, b) =>+ compareText(humanizeDefinitionKind(a.definition_kind), humanizeDefinitionKind(b.definition_kind)),},{title: 'Source',key: 'created_source',render: (_, metric) => <SourceTag metric={metric} />,+ sorter: (a, b) => compareText(a.created_source, b.created_source),},{title: 'Owner',key: 'owner',render: (_, metric) => metric.owner || <span className="text-secondary">Unassigned</span>,+ sorter: (a, b) => compareText(a.owner, b.owner),},createdAtColumn<DataCatalogMetricApi>() as LemonTableColumns<DataCatalogMetricApi>[number],{@@ -254,6 +259,7 @@ export function MetricsTab(): JSX.Element {</div></div><LemonTable+ id="data-catalog-metrics"data-attr="data-catalog-metrics-table"dataSource={metrics}rowKey="name"@@ -262,6 +268,7 @@ export function MetricsTab(): JSX.Element {pagination={{ pageSize: 20 }}emptyState={allMetrics.length === 0 ? 'No metrics defined yet.' : 'No metrics match your filters.'}nouns={['metric', 'metrics']}+ onSort={(sorting) => reportCatalogTableSorted('metrics', sorting)}bulkSelection={{// Key on the stable id, not the name: a name is freed for reuse when a metric is// deleted or renamed, so a name-keyed selection could target a different metricdiff --git a/products/data_catalog/frontend/tabs/RelationshipsTab.tsx b/products/data_catalog/frontend/tabs/RelationshipsTab.tsxindex 7ba97f1c83e6..5f76b44af619 100644--- a/products/data_catalog/frontend/tabs/RelationshipsTab.tsx+++ b/products/data_catalog/frontend/tabs/RelationshipsTab.tsx@@ -16,6 +16,7 @@ import { Tooltip } from 'lib/lemon-ui/Tooltip'import { ViewLinkModal } from 'products/data_warehouse/frontend/shared/components/ViewLinkModal'import { viewLinkLogic } from 'products/data_warehouse/frontend/shared/logics/viewLinkLogic'+import { compareText, reportCatalogTableSorted } from '../common'import { RelationshipProposalModal } from '../components/RelationshipProposalModal'import { RelationshipRow, RelationshipStatusFilter, relationshipsLogic } from '../relationshipsLogic'@@ -74,11 +75,21 @@ export function RelationshipsTab(): JSX.Element {title: 'Source',key: 'source',render: (_, row) => <TableRefCell table={row.sourceTableName} refKey={row.sourceTableKey} />,+ sorter: (a, b) =>+ compareText(+ tableRef(a.sourceTableName, a.sourceTableKey),+ tableRef(b.sourceTableName, b.sourceTableKey)+ ),},{title: 'Joins to',key: 'joining',render: (_, row) => <TableRefCell table={row.joiningTableName} refKey={row.joiningTableKey} />,+ sorter: (a, b) =>+ compareText(+ tableRef(a.joiningTableName, a.joiningTableKey),+ tableRef(b.joiningTableName, b.joiningTableKey)+ ),},{title: (@@ -88,11 +99,13 @@ export function RelationshipsTab(): JSX.Element {),key: 'field',render: (_, row) => row.fieldName,+ sorter: (a, b) => compareText(a.fieldName, b.fieldName),},{title: 'Confidence',key: 'confidence',render: (_, row) => (row.confidence != null ? `${Math.round(row.confidence * 100)}%` : ''),+ sorter: (a, b) => (a.confidence ?? -1) - (b.confidence ?? -1),},{title: 'Status',@@ -103,11 +116,13 @@ export function RelationshipsTab(): JSX.Element {{row.viaCatalog && <LemonTag type="completion">Via catalog</LemonTag>}</div>),+ sorter: (a, b) => compareText(a.rowStatus, b.rowStatus) || Number(a.viaCatalog) - Number(b.viaCatalog),},{title: 'Reviewed by',key: 'reviewedBy',render: (_, row) => row.reviewedBy || <span className="text-secondary">-</span>,+ sorter: (a, b) => compareText(a.reviewedBy, b.reviewedBy),},{key: 'actions',@@ -203,6 +218,7 @@ export function RelationshipsTab(): JSX.Element {</div></div><LemonTable+ id="data-catalog-relationships"data-attr="data-catalog-relationships-table"dataSource={filteredRows}rowKey="key"@@ -211,6 +227,7 @@ export function RelationshipsTab(): JSX.Element {pagination={{ pageSize: 20 }}emptyState="No relationships match your filters."nouns={['relationship', 'relationships']}+ onSort={(sorting) => reportCatalogTableSorted('relationships', sorting)}expandable={{rowExpandable: (row) => !!row.reasoning || !!row.evidence || !!row.rejectionReason,expandedRowRender: (row) => <RelationshipDetail row={row} />,diff --git a/products/data_catalog/package.json b/products/data_catalog/package.jsonindex 92f2046b8aa5..b9e8ec5ae77f 100644--- a/products/data_catalog/package.json+++ b/products/data_catalog/package.json@@ -8,6 +8,7 @@"kea": "catalog:","kea-loaders": "catalog:","kea-router": "catalog:",+ "posthog-js": "catalog:","yaml": "catalog:"},"devDependencies": {