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-catalog): split metrics into a review queue and an approved list (#123967)

Sinan Kucukkoseler3b6f4adb4ea3
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index ee21cf677e5a..42a50901269f 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2976,6 +2976,10 @@ snapshots:
hash: v1.k794b7964.0374c7974dec7e4856f35cc96eb4b5581f6fbd90c60e2141b7f91b6251f4db5d.zFGMI4Evxi3Bq17XxaBxRQhfhr1bkSVt5IxYnDtTOw0
data-catalog-lifecycle-strip--drifted-selected--light:
hash: v1.k794b7964.ffe0d2155bc7ca77f345984218ce641ca9747fb40a6bdc65f8cbb2073785986c.XDE9QK2mEGIFM5M9sDeqXJVE4B3S8B8nk_q3Re6rYgw
+ data-catalog-metric-description--clamped--dark:
+ hash: v1.k794b7964.94189c2dd7e3fb15b469cf7eb19f5dc35c0f8f9d71d35d602938e3f07733e280.t8xqMmiX0ceBOMqJIzr1LU9Kq3SZDBS1iuhzohpQWeA
+ data-catalog-metric-description--clamped--light:
+ hash: v1.k794b7964.4380c405fe354b4397f7403340b14b7204574f1a3bef621b36b2b630ec8d80d3.zM6ZRGZdmwZ3QzDZ0ytJMBIN5-HmtPtlZIXLGlKb9c0
data-catalog-metric-run-result-cell--long-values-collapse--dark:
hash: v1.k794b7964.dc188a898119faa5dc90aabb8b42f172657e8d18604c5cb4dfecd77f33dcca14.OkK0G4Kc9D5flwW3eKJ24FBFZcaNd7oEQUHyqqLXtqY
data-catalog-metric-run-result-cell--long-values-collapse--light:
diff --git a/products/data_catalog/frontend/components/MetricDescription.stories.tsx b/products/data_catalog/frontend/components/MetricDescription.stories.tsx
new file mode 100644
index 000000000000..7f67765330fd
--- /dev/null
+++ b/products/data_catalog/frontend/components/MetricDescription.stories.tsx
@@ -0,0 +1,23 @@
+import type { Meta, StoryObj } from '@storybook/react'
+
+import { MetricDescription } from './MetricDescription'
+
+const meta: Meta<typeof MetricDescription> = {
+ title: 'Data catalog/Metric description',
+ component: MetricDescription,
+ parameters: { viewMode: 'story' },
+ render: (props) => (
+ // A fixed width keeps the clamp point, and so the baseline, the same on every run.
+ <div className="w-96 p-4 text-xs text-tertiary">
+ <MetricDescription {...props} />
+ </div>
+ ),
+}
+export default meta
+
+export const Clamped: StoryObj<typeof MetricDescription> = {
+ args: {
+ description:
+ 'The number of dashboards created in PostHog, across every surface that can create one: web, API, MCP, PostHog AI, CLI and Terraform. Each creation counts once, including dashboards made from a template or by duplicating an existing one.',
+ },
+}
diff --git a/products/data_catalog/frontend/components/MetricDescription.tsx b/products/data_catalog/frontend/components/MetricDescription.tsx
new file mode 100644
index 000000000000..9740e7ab7249
--- /dev/null
+++ b/products/data_catalog/frontend/components/MetricDescription.tsx
@@ -0,0 +1,34 @@
+import { useEffect, useRef, useState } from 'react'
+
+import { useResizeObserver } from 'lib/hooks/useResizeObserver'
+import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
+import { Tooltip } from 'lib/lemon-ui/Tooltip'
+
+/** A metric description clamped to two lines, with the full text in a tooltip when it overflows. */
+export function MetricDescription({ description }: { description: string }): JSX.Element {
+ const contentRef = useRef<HTMLDivElement | null>(null)
+ const [isOverflowing, setIsOverflowing] = useState(false)
+ // The column resizes with the scene (e.g. opening a side panel), which changes the line count.
+ const { width } = useResizeObserver({ ref: contentRef })
+
+ useEffect(() => {
+ if (contentRef.current) {
+ setIsOverflowing(contentRef.current.scrollHeight > contentRef.current.clientHeight)
+ }
+ }, [description, width])
+
+ // Images stay disabled so a stored image URL can't beacon other viewers.
+ const markdown = (
+ <LemonMarkdown lowKeyHeadings disableImages>
+ {description}
+ </LemonMarkdown>
+ )
+
+ return (
+ <Tooltip title={isOverflowing ? <div className="max-w-120">{markdown}</div> : undefined}>
+ <div ref={contentRef} className="max-w-[30rem] line-clamp-2">
+ {markdown}
+ </div>
+ </Tooltip>
+ )
+}
diff --git a/products/data_catalog/frontend/components/MetricOwnerSelect.tsx b/products/data_catalog/frontend/components/MetricOwnerSelect.tsx
index f5a081f50f62..332d1c3b9f19 100644
--- a/products/data_catalog/frontend/components/MetricOwnerSelect.tsx
+++ b/products/data_catalog/frontend/components/MetricOwnerSelect.tsx
@@ -7,11 +7,14 @@ export function MetricOwnerSelect({
loading,
disabledReason,
onChange,
+ truncate,
}: {
owner: string | null | undefined
loading: boolean
disabledReason?: string
onChange: (owner: string | null) => void
+ /** Cut a long owner email with an ellipsis, with the full email on hover. */
+ truncate?: boolean
}): JSX.Element {
return (
<MemberSelect value={null} defaultLabel="Unassigned" onChange={(user) => onChange(user?.email ?? null)}>
@@ -19,7 +22,9 @@ export function MetricOwnerSelect({
<LemonButton
type="tertiary"
size="small"
- className="-ml-2 -my-1.5"
+ className={truncate ? '-ml-2 -my-1.5 max-w-40' : '-ml-2 -my-1.5'}
+ truncate={truncate}
+ tooltip={truncate && owner ? owner : undefined}
loading={loading}
disabledReason={disabledReason}
data-attr="data-catalog-metric-owner-select"
diff --git a/products/data_catalog/frontend/metricsLogic.test.ts b/products/data_catalog/frontend/metricsLogic.test.ts
index b4b1c9637d67..16ff2a5148c6 100644
--- a/products/data_catalog/frontend/metricsLogic.test.ts
+++ b/products/data_catalog/frontend/metricsLogic.test.ts
@@ -6,6 +6,7 @@ import { userLogic } from 'scenes/userLogic'
import { initKeaTests } from '~/test/init'
import { expectLogic } from '~/test/keaTestUtils'
+import type { UserType } from '~/types'
import {
dataCatalogMetricsApproveCreate,
@@ -287,6 +288,45 @@ describe('metricsLogic', () => {
expect(logic.values.metrics).toEqual([proposed, approvedDrifted, approved])
})
+ it('orders the review queue by drift, ownership, then AI confidence, and keeps clean approved metrics out', async () => {
+ const me = userLogic.values.user as UserType
+ const mine = { id: 1, uuid: me.uuid, email: me.email, hedgehog_config: null }
+ const theirs = { id: 2, uuid: 'someone-else', email: '[email protected]', hedgehog_config: null }
+ const metric = (name: string, overrides: Partial<DataCatalogMetricApi>): DataCatalogMetricApi =>
+ buildMetric({ id: name, name, created_by: theirs, created_at: '2026-10-01T00:00:00Z', ...overrides })
+ logic.actions.loadMetricsSuccess([
+ metric('their_proposal', {}),
+ metric('ai_low', { created_source: 'ai_generated', confidence: 0.6 }),
+ metric('approved_clean', { status: 'approved' }),
+ metric('my_newer_proposal', { created_by: mine, created_at: '2026-10-02T00:00:00Z' }),
+ metric('ai_high', { created_source: 'ai_generated', confidence: 0.9 }),
+ metric('their_drifted_approved', { status: 'approved', is_drifted: true }),
+ metric('my_older_proposal', { created_by: mine }),
+ metric('owned_drifted', { is_drifted: true, owner: me.email }),
+ ])
+
+ expect(logic.values.reviewQueue.map((m) => m.name)).toEqual([
+ 'owned_drifted',
+ 'their_drifted_approved',
+ 'my_newer_proposal',
+ 'my_older_proposal',
+ 'ai_high',
+ 'ai_low',
+ 'their_proposal',
+ ])
+ expect(logic.values.approvedMetrics.map((m) => m.name)).toEqual(['approved_clean'])
+
+ logic.actions.toggleStage('approved')
+ expect(logic.values.reviewQueue.map((m) => m.name)).toEqual(['their_drifted_approved'])
+ expect(logic.values).toMatchObject({ showReviewQueue: true, showApproved: true })
+
+ logic.actions.loadMetricsSuccess([metric('approved_clean', { status: 'approved' })])
+ expect(logic.values).toMatchObject({ showReviewQueue: false, showApproved: true })
+
+ logic.actions.toggleStage('proposed')
+ expect(logic.values).toMatchObject({ showReviewQueue: true, showApproved: false })
+ })
+
it('patches approved rows and reloads to reconcile skipped ones', async () => {
logic.actions.loadMetricsSuccess([
buildMetric({ id: 'metric-1', name: 'first' }),
diff --git a/products/data_catalog/frontend/metricsLogic.tsx b/products/data_catalog/frontend/metricsLogic.tsx
index 4999270a7858..13ca20631bd1 100644
--- a/products/data_catalog/frontend/metricsLogic.tsx
+++ b/products/data_catalog/frontend/metricsLogic.tsx
@@ -25,6 +25,7 @@ import {
} from './generated/api'
import type { DataCatalogMetricApi, DataCatalogMetricBulkSkipApi } from './generated/api.schemas'
import { openOverwriteMetricDialog } from './openOverwriteMetricDialog'
+import { compareReviewQueue, needsReview } from './reviewQueue'
export type MetricStage = 'proposed' | 'approved' | 'drifted'
@@ -32,6 +33,9 @@ export type MetricStatusFilter = 'all' | MetricStage
export type MetricStageCounts = Record<MetricStage, number>
+/** 'unknown' until the first load answers, so an empty list is never read as an empty catalog. */
+export type MetricsLoadState = 'unknown' | 'loaded' | 'failed'
+
export type BulkMetricAction = 'approve' | 'delete' | 'change_owner'
const METRICS_PAGE_SIZE = 100
@@ -86,13 +90,19 @@ export interface metricsLogicValues {
actionsInFlight: Record<string, boolean>
allMetrics: DataCatalogMetricApi[]
allMetricsLoading: boolean
+ approvedMetrics: DataCatalogMetricApi[]
bulkActionInFlight: BulkMetricAction | null
creatingMetricAs: MetricSaveAction | null
filters: MetricsFilters
metricFromInsightModalOpen: boolean
metrics: DataCatalogMetricApi[]
+ metricsLoadState: MetricsLoadState
ownerFilterOptions: string[]
proposedCount: number
+ reviewQueue: DataCatalogMetricApi[]
+ showApproved: boolean
+ showReviewQueue: boolean
+ splitTablesLoading: boolean
stageCounts: MetricStageCounts
}
@@ -192,6 +202,11 @@ export interface metricsLogicActions {
export interface metricsLogicMeta {
__keaTypeGenInternalSelectorTypes: {
metrics: (allMetrics: DataCatalogMetricApi[], filters: MetricsFilters) => DataCatalogMetricApi[]
+ reviewQueue: (metrics: DataCatalogMetricApi[], user: UserType | null) => DataCatalogMetricApi[]
+ approvedMetrics: (metrics: DataCatalogMetricApi[]) => DataCatalogMetricApi[]
+ splitTablesLoading: (allMetricsLoading: boolean, metricsLoadState: MetricsLoadState) => boolean
+ showReviewQueue: (filters: MetricsFilters, reviewQueue: DataCatalogMetricApi[]) => boolean
+ showApproved: (filters: MetricsFilters) => boolean
ownerFilterOptions: (allMetrics: DataCatalogMetricApi[]) => string[]
proposedCount: (allMetrics: DataCatalogMetricApi[]) => number
stageCounts: (allMetrics: DataCatalogMetricApi[]) => MetricStageCounts
@@ -258,6 +273,13 @@ export const metricsLogic = kea<metricsLogicType>([
],
})),
reducers({
+ metricsLoadState: [
+ 'unknown' as MetricsLoadState,
+ {
+ loadMetricsSuccess: () => 'loaded',
+ loadMetricsFailure: () => 'failed',
+ },
+ ],
filters: [
DEFAULT_METRICS_FILTERS as MetricsFilters,
{
@@ -320,6 +342,32 @@ export const metricsLogic = kea<metricsLogicType>([
return results
},
],
+ reviewQueue: [
+ (s) => [s.metrics, s.user],
+ (metrics: DataCatalogMetricApi[], user: UserType | null): DataCatalogMetricApi[] =>
+ metrics.filter(needsReview).sort(compareReviewQueue(user)),
+ ],
+ approvedMetrics: [
+ (s) => [s.metrics],
+ (metrics: DataCatalogMetricApi[]): DataCatalogMetricApi[] =>
+ metrics.filter((metric) => !needsReview(metric)),
+ ],
+ // An empty queue is a verdict about loaded data, so stay in the skeleton until the first load answers.
+ splitTablesLoading: [
+ (s) => [s.allMetricsLoading, s.metricsLoadState],
+ (allMetricsLoading: boolean, metricsLoadState: MetricsLoadState): boolean =>
+ allMetricsLoading || metricsLoadState === 'unknown',
+ ],
+ // A drifted approved metric sits in the queue, so the queue stays visible under the Approved stage when it holds one.
+ showReviewQueue: [
+ (s) => [s.filters, s.reviewQueue],
+ (filters: MetricsFilters, reviewQueue: DataCatalogMetricApi[]): boolean =>
+ filters.status !== 'approved' || reviewQueue.length > 0,
+ ],
+ showApproved: [
+ (s) => [s.filters],
+ (filters: MetricsFilters): boolean => filters.status === 'all' || filters.status === 'approved',
+ ],
ownerFilterOptions: [
(s) => [s.allMetrics],
(allMetrics: DataCatalogMetricApi[]): string[] =>
@@ -427,9 +475,18 @@ export const metricsLogic = kea<metricsLogicType>([
)
lemonToast.success('Metric refreshed from its source insight')
} catch (error) {
- lemonToast.error(
- apiErrorDetail(error) || 'Could not refresh the metric from its source insight. Try again.'
- )
+ if (error instanceof ApiError && error.code === 'source_insight_unavailable') {
+ lemonToast.error(error.detail || 'The source insight is no longer available.', {
+ button: {
+ label: 'Open metric',
+ action: () => router.actions.push(urls.dataCatalogMetric(name)),
+ },
+ })
+ } else {
+ lemonToast.error(
+ apiErrorDetail(error) || 'Could not refresh the metric from its source insight. Try again.'
+ )
+ }
} finally {
actions.setActionInFlight(name, false)
}
diff --git a/products/data_catalog/frontend/reviewQueue.ts b/products/data_catalog/frontend/reviewQueue.ts
new file mode 100644
index 000000000000..8dce9c5c4ded
--- /dev/null
+++ b/products/data_catalog/frontend/reviewQueue.ts
@@ -0,0 +1,50 @@
+import type { UserType } from '~/types'
+
+import type { DataCatalogMetricApi } from './generated/api.schemas'
+
+/** A metric needs review until it is approved and matches its source insight. */
+export function needsReview(metric: DataCatalogMetricApi): boolean {
+ return metric.status !== 'approved' || !!metric.is_drifted
+}
+
+function isMine(metric: DataCatalogMetricApi, user: Pick<UserType, 'uuid' | 'email'> | null): boolean {
+ if (!user) {
+ return false
+ }
+ // created_by is SET_NULL on the model, so a deleted creator arrives as null despite the serializer type.
+ return metric.created_by?.uuid === user.uuid || (!!metric.owner && metric.owner === user.email)
+}
+
+// Drift comes first because agents answer with a drifted metric until someone refreshes it.
+function priority(metric: DataCatalogMetricApi, user: Pick<UserType, 'uuid' | 'email'> | null): number {
+ const mine = isMine(metric, user)
+ if (metric.is_drifted) {
+ return mine ? 0 : 1
+ }
+ if (mine) {
+ return 2
+ }
+ return metric.created_source === 'ai_generated' ? 3 : 4
+}
+
+/**
+ * Orders the review queue: your drifted metrics, other drifted metrics, your proposals,
+ * AI proposals by confidence, then the rest. Newer metrics come first inside a group.
+ */
+export function compareReviewQueue(
+ user: Pick<UserType, 'uuid' | 'email'> | null
+): (a: DataCatalogMetricApi, b: DataCatalogMetricApi) => number {
+ return (a, b) => {
+ const byPriority = priority(a, user) - priority(b, user)
+ if (byPriority !== 0) {
+ return byPriority
+ }
+ if (priority(a, user) === 3) {
+ const byConfidence = (b.confidence ?? 0) - (a.confidence ?? 0)
+ if (byConfidence !== 0) {
+ return byConfidence
+ }
+ }
+ return (b.created_at ?? '').localeCompare(a.created_at ?? '')
+ }
+}
diff --git a/products/data_catalog/frontend/tabs/MetricsTab.tsx b/products/data_catalog/frontend/tabs/MetricsTab.tsx
index a1bdbabca904..a5a64e97304f 100644
--- a/products/data_catalog/frontend/tabs/MetricsTab.tsx
+++ b/products/data_catalog/frontend/tabs/MetricsTab.tsx
@@ -5,6 +5,7 @@ import { IconRefresh } from '@posthog/icons'
import { LemonButton, LemonDialog, LemonSelect } from '@posthog/lemon-ui'
import { MemberSelect } from 'lib/components/MemberSelect'
+import { TZLabel } from 'lib/components/TZLabel'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { More } from 'lib/lemon-ui/LemonButton/More'
import { LemonInput } from 'lib/lemon-ui/LemonInput'
@@ -13,13 +14,18 @@ import { LemonSegmentedButton } from 'lib/lemon-ui/LemonSegmentedButton'
import { LemonTable, LemonTableColumns } from 'lib/lemon-ui/LemonTable'
import { createdAtColumn } from 'lib/lemon-ui/LemonTable/columnUtils'
import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'
+import type { BulkSelectionConfig } from 'lib/lemon-ui/LemonTable/useBulkSelection'
import { LemonTag } from 'lib/lemon-ui/LemonTag'
+import { Link } from 'lib/lemon-ui/Link'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { urls } from 'scenes/urls'
+import { InsightShortId } from '~/types'
+
import { METRIC_BULK_MAX, compareText, humanizeDefinitionKind, metricCount, reportCatalogTableSorted } from '../common'
import { CatalogExplainer } from '../components/CatalogExplainer'
import { LifecycleStrip } from '../components/LifecycleStrip'
+import { MetricDescription } from '../components/MetricDescription'
import { MetricOwnerSelect } from '../components/MetricOwnerSelect'
import type { DataCatalogMetricApi } from '../generated/api.schemas'
import { BulkMetricAction, MetricStatusFilter, metricsLogic } from '../metricsLogic'
@@ -30,6 +36,14 @@ const STATUS_FILTER_OPTIONS: { value: MetricStatusFilter; label: string }[] = [
{ value: 'approved', label: 'Approved' },
]
+const BULK_BAR_CLASS =
+ 'sticky bottom-4 z-10 self-center w-fit rounded border border-primary bg-surface-primary px-2 py-1 shadow empty:hidden'
+
+// Short pages keep both split tables on screen together, however long either list is.
+const SPLIT_TABLE_PAGE_SIZE = 6
+
+const LOAD_FAILED = 'Could not load metrics. Reload the list to try again.'
+
const OVER_CAP_REASON = `Select at most ${METRIC_BULK_MAX} metrics at a time`
function isApprovable(metric: DataCatalogMetricApi): boolean {
@@ -69,6 +83,7 @@ export function MetricsTab(): JSX.Element {
// State, not a ref, so the table re-renders once the slot mounts and the bar can portal into it.
// The bar portals below the table instead of above it, so selecting a row never shifts the rows.
const [bulkBarTarget, setBulkBarTarget] = useState<HTMLDivElement | null>(null)
+ const [approvedBulkBarTarget, setApprovedBulkBarTarget] = useState<HTMLDivElement | null>(null)
const {
metrics,
allMetrics,
@@ -78,6 +93,12 @@ export function MetricsTab(): JSX.Element {
bulkActionInFlight,
ownerFilterOptions,
stageCounts,
+ reviewQueue,
+ approvedMetrics,
+ metricsLoadState,
+ splitTablesLoading,
+ showReviewQueue,
+ showApproved,
} = useValues(metricsLogic)
const {
setFilters,
@@ -161,7 +182,7 @@ export function MetricsTab(): JSX.Element {
})
}
- const columns: LemonTableColumns<DataCatalogMetricApi> = [
+ const baseColumns: LemonTableColumns<DataCatalogMetricApi> = [
{
title: 'Name',
key: 'name',
@@ -173,9 +194,13 @@ export function MetricsTab(): JSX.Element {
// Render descriptions with images disabled so a stored image URL can't beacon other viewers.
description={
metric.description ? (
- <LemonMarkdown className="max-w-[30rem]" lowKeyHeadings disableImages>
- {metric.description}
- </LemonMarkdown>
+ reviewQueueEnabled ? (
+ <MetricDescription description={metric.description} />
+ ) : (
+ <LemonMarkdown className="max-w-[30rem]" lowKeyHeadings disableImages>
+ {metric.description}
+ </LemonMarkdown>
+ )
) : undefined
}
/>
@@ -206,6 +231,7 @@ export function MetricsTab(): JSX.Element {
key: 'owner',
render: (_, metric) => (
<MetricOwnerSelect
+ truncate={reviewQueueEnabled}
owner={metric.owner}
loading={!!actionsInFlight[metric.name]}
disabledReason={bulkBusyReason}
@@ -214,56 +240,205 @@ export function MetricsTab(): JSX.Element {
),
sorter: (a, b) => compareText(a.owner, b.owner),
},
- createdAtColumn<DataCatalogMetricApi>() as LemonTableColumns<DataCatalogMetricApi>[number],
- {
- key: 'actions',
- width: 0,
- render: (_, metric) => {
- const inFlight = !!actionsInFlight[metric.name]
- return (
- <More
- overlay={
- <>
- {metric.status !== 'approved' && (
- <LemonButton
- fullWidth
- loading={inFlight}
- disabledReason={
- bulkBusyReason ??
- (metric.is_drifted
- ? 'This metric has drifted from its source insight. Refresh it first.'
- : undefined)
- }
- onClick={() => approveMetric(metric.name)}
- >
- Approve
- </LemonButton>
- )}
- {metric.source_insight_short_id && (
- <LemonButton
- fullWidth
- loading={inFlight}
- disabledReason={bulkBusyReason}
- onClick={() => refreshMetricFromInsight(metric.name)}
- >
- Refresh from insight
- </LemonButton>
- )}
+ // Left-aligned so the date sits next to the owner instead of across an empty gap.
+ // The shared column right-aligns inside its render, so only the render is replaced; sorting is kept.
+ reviewQueueEnabled
+ ? {
+ ...(createdAtColumn<DataCatalogMetricApi>() as LemonTableColumns<DataCatalogMetricApi>[number]),
+ align: 'left',
+ render: (_, metric) => (
+ <div className="whitespace-nowrap">
+ <TZLabel time={metric.created_at} />
+ </div>
+ ),
+ }
+ : (createdAtColumn<DataCatalogMetricApi>() as LemonTableColumns<DataCatalogMetricApi>[number]),
+ ]
+
+ const menuColumn: LemonTableColumns<DataCatalogMetricApi>[number] = {
+ key: 'actions',
+ width: 0,
+ render: (_, metric) => {
+ const inFlight = !!actionsInFlight[metric.name]
+ return (
+ <More
+ overlay={
+ <>
+ {metric.status !== 'approved' && (
<LemonButton
fullWidth
- status="danger"
- disabledReason={bulkBusyReason ?? (inFlight ? 'Working' : undefined)}
- onClick={() => confirmDelete(metric)}
+ loading={inFlight}
+ disabledReason={
+ bulkBusyReason ??
+ (metric.is_drifted
+ ? 'This metric has drifted from its source insight. Refresh it first.'
+ : undefined)
+ }
+ onClick={() => approveMetric(metric.name)}
>
- Delete
+ Approve
+ </LemonButton>
+ )}
+ {metric.source_insight_short_id && (
+ <LemonButton
+ fullWidth
+ loading={inFlight}
+ disabledReason={bulkBusyReason}
+ onClick={() => refreshMetricFromInsight(metric.name)}
+ >
+ Refresh from insight
+ </LemonButton>
+ )}
+ <LemonButton
+ fullWidth
+ status="danger"
+ disabledReason={bulkBusyReason ?? (inFlight ? 'Working' : undefined)}
+ onClick={() => confirmDelete(metric)}
+ >
+ Delete
+ </LemonButton>
+ </>
+ }
+ />
+ )
+ },
+ }
+
+ // The queue puts the next step on the row. Delete stays in a menu, away from the primary action.
+ const reviewActionsColumn: LemonTableColumns<DataCatalogMetricApi>[number] = {
+ key: 'actions',
+ width: 0,
+ render: (_, metric) => {
+ const inFlight = !!actionsInFlight[metric.name]
+ return (
+ <div className="flex items-center justify-end gap-1">
+ {metric.is_drifted ? (
+ metric.source_insight_short_id && (
+ <>
+ <Link
+ to={urls.insightView(metric.source_insight_short_id as InsightShortId)}
+ target="_blank"
+ className="text-xs whitespace-nowrap"
+ data-attr="data-catalog-metric-source-insight"
+ >
+ Insight
+ </Link>
+ <LemonButton
+ type="secondary"
+ size="small"
+ loading={inFlight}
+ disabledReason={bulkBusyReason}
+ tooltip="Update the definition from the source insight"
+ onClick={() => refreshMetricFromInsight(metric.name)}
+ data-attr="data-catalog-review-queue-refresh"
+ >
+ Refresh
</LemonButton>
</>
+ )
+ ) : (
+ <LemonButton
+ type="primary"
+ size="small"
+ loading={inFlight}
+ disabledReason={bulkBusyReason}
+ onClick={() => approveMetric(metric.name)}
+ data-attr="data-catalog-review-queue-approve"
+ >
+ Approve
+ </LemonButton>
+ )}
+ <More
+ overlay={
+ <LemonButton
+ fullWidth
+ status="danger"
+ disabledReason={bulkBusyReason ?? (inFlight ? 'Working' : undefined)}
+ onClick={() => confirmDelete(metric)}
+ >
+ Delete
+ </LemonButton>
}
/>
- )
- },
+ </div>
+ )
},
- ]
+ }
+
+ const columns = [...baseColumns, menuColumn]
+ const reviewColumns = [...baseColumns, reviewActionsColumn]
+ const approvedColumns = [...baseColumns.filter((column) => column.key !== 'status'), menuColumn]
+
+ const bulkSelection = (
+ tableMetrics: DataCatalogMetricApi[],
+ barPortalTarget: HTMLDivElement | null,
+ { withApprove }: { withApprove: boolean }
+ ): BulkSelectionConfig<DataCatalogMetricApi> => ({
+ // 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 metric
+ // that later takes the same name.
+ getKey: (metric: DataCatalogMetricApi) => metric.id,
+ noun: ['metric', 'metrics'],
+ rowAriaLabel: (metric: DataCatalogMetricApi) => `Select metric ${metric.name}`,
+ headerAriaLabel: 'Select all metrics on this page',
+ barPortalTarget,
+ renderActions: (ctx) => {
+ // Selection spans pages, so resolve the keys against every row of this table rather
+ // than ctx.selectedRecords, which only covers the page on screen. Resolving by id also
+ // drops any selected metric that has since left the table, e.g. one approved inline
+ // that moved from the review queue to the approved table.
+ const selected = new Set(ctx.selectedKeys)
+ const selectedMetrics = tableMetrics.filter((metric) => selected.has(metric.id))
+ const approvableNames = selectedMetrics.filter(isApprovable).map((metric) => metric.name)
+ const selectedNames = selectedMetrics.map((metric) => metric.name)
+ return (
+ <>
+ {withApprove && (
+ <LemonButton
+ type="secondary"
+ size="small"
+ data-attr="data-catalog-metrics-bulk-approve"
+ loading={bulkActionInFlight === 'approve'}
+ disabledReason={bulkApproveDisabledReason(approvableNames.length)}
+ onClick={() => bulkApproveMetrics(approvableNames, ctx.clearSelection)}
+ >
+ Approve ({approvableNames.length})
+ </LemonButton>
+ )}
+ <MemberSelect
+ value={null}
+ defaultLabel="Unassigned"
+ onChange={(user) =>
+ bulkChangeMetricOwner(selectedNames, user?.email ?? null, ctx.clearSelection)
+ }
+ >
+ {() => (
+ <LemonButton
+ type="secondary"
+ size="small"
+ data-attr="data-catalog-metrics-bulk-change-owner"
+ loading={bulkActionInFlight === 'change_owner'}
+ disabledReason={bulkSelectionDisabledReason(selectedNames.length, 'change_owner')}
+ >
+ Change owner
+ </LemonButton>
+ )}
+ </MemberSelect>
+ <LemonButton
+ type="secondary"
+ status="danger"
+ size="small"
+ data-attr="data-catalog-metrics-bulk-delete"
+ loading={bulkActionInFlight === 'delete'}
+ disabledReason={bulkSelectionDisabledReason(selectedNames.length, 'delete')}
+ onClick={() => confirmBulkDelete(selectedNames, ctx.clearSelection)}
+ >
+ Delete
+ </LemonButton>
+ </>
+ )
+ },
+ })
return (
<div className="@container flex flex-col gap-4">
@@ -320,88 +495,80 @@ export function MetricsTab(): JSX.Element {
</LemonButton>
</div>
</div>
- <LemonTable
- id="data-catalog-metrics"
- data-attr="data-catalog-metrics-table"
- dataSource={metrics}
- rowKey="name"
- columns={columns}
- loading={allMetricsLoading}
- 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 metric
- // that later takes the same name.
- getKey: (metric: DataCatalogMetricApi) => metric.id,
- noun: ['metric', 'metrics'],
- rowAriaLabel: (metric: DataCatalogMetricApi) => `Select metric ${metric.name}`,
- headerAriaLabel: 'Select all metrics on this page',
- barPortalTarget: bulkBarTarget,
- renderActions: (ctx) => {
- // Selection spans pages, so resolve the keys against every metric rather
- // than ctx.selectedRecords, which only covers the page on screen. Resolving
- // by id also drops any selected metric that has since left the list.
- const selected = new Set(ctx.selectedKeys)
- const selectedMetrics = allMetrics.filter((metric) => selected.has(metric.id))
- const approvableNames = selectedMetrics.filter(isApprovable).map((metric) => metric.name)
- const selectedNames = selectedMetrics.map((metric) => metric.name)
- return (
- <>
- <LemonButton
- type="secondary"
- size="small"
- data-attr="data-catalog-metrics-bulk-approve"
- loading={bulkActionInFlight === 'approve'}
- disabledReason={bulkApproveDisabledReason(approvableNames.length)}
- onClick={() => bulkApproveMetrics(approvableNames, ctx.clearSelection)}
- >
- Approve ({approvableNames.length})
- </LemonButton>
- <MemberSelect
- value={null}
- defaultLabel="Unassigned"
- onChange={(user) =>
- bulkChangeMetricOwner(selectedNames, user?.email ?? null, ctx.clearSelection)
- }
- >
- {() => (
- <LemonButton
- type="secondary"
- size="small"
- data-attr="data-catalog-metrics-bulk-change-owner"
- loading={bulkActionInFlight === 'change_owner'}
- disabledReason={bulkSelectionDisabledReason(
- selectedNames.length,
- 'change_owner'
- )}
- >
- Change owner
- </LemonButton>
- )}
- </MemberSelect>
- <LemonButton
- type="secondary"
- status="danger"
- size="small"
- data-attr="data-catalog-metrics-bulk-delete"
- loading={bulkActionInFlight === 'delete'}
- disabledReason={bulkSelectionDisabledReason(selectedNames.length, 'delete')}
- onClick={() => confirmBulkDelete(selectedNames, ctx.clearSelection)}
- >
- Delete
- </LemonButton>
- </>
- )
- },
- }}
- />
- <div
- ref={setBulkBarTarget}
- className="sticky bottom-4 z-10 self-center w-fit rounded border border-primary bg-surface-primary px-2 py-1 shadow empty:hidden"
- />
+ {reviewQueueEnabled ? (
+ <>
+ {showReviewQueue && (
+ <section className="flex flex-col gap-2" data-attr="data-catalog-review-queue">
+ <div className="flex flex-wrap items-baseline gap-x-2">
+ <h3 className="m-0">
+ <span>Needs review </span>
+ <span>{`(${reviewQueue.length})`}</span>
+ </h3>
+ <span className="text-xs text-secondary">
+ Drifted metrics come first, then your proposals, then AI proposals by confidence.
+ </span>
+ </div>
+ <LemonTable
+ id="data-catalog-review-queue"
+ data-attr="data-catalog-review-queue-table"
+ dataSource={reviewQueue}
+ rowKey="name"
+ columns={reviewColumns}
+ loading={splitTablesLoading}
+ pagination={{ pageSize: SPLIT_TABLE_PAGE_SIZE }}
+ emptyState={metricsLoadState === 'failed' ? LOAD_FAILED : 'Nothing to review.'}
+ nouns={['metric', 'metrics']}
+ onSort={(sorting) => reportCatalogTableSorted('metrics', sorting)}
+ bulkSelection={bulkSelection(reviewQueue, bulkBarTarget, { withApprove: true })}
+ />
+ <div ref={setBulkBarTarget} className={BULK_BAR_CLASS} />
+ </section>
+ )}
+ {showApproved && (
+ <section className="flex flex-col gap-2" data-attr="data-catalog-approved">
+ <h3 className="m-0">
+ <span>Approved </span>
+ <span>{`(${approvedMetrics.length})`}</span>
+ </h3>
+ <LemonTable
+ id="data-catalog-approved"
+ data-attr="data-catalog-approved-table"
+ dataSource={approvedMetrics}
+ rowKey="name"
+ columns={approvedColumns}
+ loading={splitTablesLoading}
+ pagination={{ pageSize: SPLIT_TABLE_PAGE_SIZE }}
+ emptyState={metricsLoadState === 'failed' ? LOAD_FAILED : 'No approved metrics yet.'}
+ nouns={['metric', 'metrics']}
+ onSort={(sorting) => reportCatalogTableSorted('metrics', sorting)}
+ bulkSelection={bulkSelection(approvedMetrics, approvedBulkBarTarget, {
+ withApprove: false,
+ })}
+ />
+ <div ref={setApprovedBulkBarTarget} className={BULK_BAR_CLASS} />
+ </section>
+ )}
+ </>
+ ) : (
+ <>
+ <LemonTable
+ id="data-catalog-metrics"
+ data-attr="data-catalog-metrics-table"
+ dataSource={metrics}
+ rowKey="name"
+ columns={columns}
+ loading={allMetricsLoading}
+ 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={bulkSelection(allMetrics, bulkBarTarget, { withApprove: true })}
+ />
+ <div ref={setBulkBarTarget} className={BULK_BAR_CLASS} />
+ </>
+ )}
</div>
)
}