: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
import { useActions, useValues } from 'kea'
import type { ReactNode } from 'react'
import { materializationJobsLogic } from 'scenes/data-warehouse/saved_queries/materializationJobsLogic'
import {
CADENCE_LABELS,
inheritedCadence,
modeDisabledReason,
SyncFrequencyValue,
} from 'scenes/data-warehouse/saved_queries/SyncFrequencySelect'
import { urls } from 'scenes/urls'
import { DataModelingSyncInterval } from '~/types'
import { SERVING_ENGINE } from '../suspension'
import { ModelHealthSummary } from './ModelHealthSummary'
import { ModelTableSummary } from './ModelTableSummary'
import { ModelViewSummary } from './ModelViewSummary'
import { nodeDetailSceneLogic } from './nodeDetailSceneLogic'
export function NodeDetailOverview({ id, metadata }: { id: string; metadata?: ReactNode }): JSX.Element | null {
const sceneLogic = nodeDetailSceneLogic({ id })
const {
node,
savedQuery: sceneSavedQuery,
isMaterialized,
savedQueryError,
effectiveLastRunStatus,
tableDetails,
tableDetailsAccessDenied,
tableDetailsLoading,
tableDetailsError,
} = useValues(sceneLogic)
const { loadTableDetails } = useActions(sceneLogic)
const materializationLogic = materializationJobsLogic({
viewId: node?.saved_query_id ?? '',
kind: node?.type === 'endpoint' ? 'endpoint' : 'view',
})
const {
savedQuery: polledSavedQuery,
dataModelingJobs,
dataModelingJobsLoading,
dataModelingJobsError,
savedQueryError: statusRefreshError,
savedQueryLoading: statusRefreshing,
lastSuccessfulSyncAt,
nodeFrequency,
} = useValues(materializationLogic)
const { refreshMaterialization } = useActions(materializationLogic)
const savedQuery = polledSavedQuery ?? sceneSavedQuery
if (!node) {
return null
}
if (node.type === 'table') {
return (
<ModelTableSummary
id={id}
node={node}
table={tableDetails?.table ?? null}
source={tableDetails?.source ?? null}
schema={tableDetails?.schema ?? null}
loading={tableDetailsLoading}
error={tableDetailsError}
accessDenied={tableDetailsAccessDenied}
onRetry={loadTableDetails}
metadata={metadata}
/>
)
}
if (!(savedQuery?.is_materialized ?? isMaterialized)) {
return (
<ModelViewSummary
downstreamCount={node.downstream_count}
lineageUrl={urls.nodeDetail(id, 'lineage')}
metadata={metadata}
/>
)
}
// Only ClickHouse serves queries, so a marker on a shadow engine means the comparison
// run stopped, not that this model stopped refreshing.
const suspension = (savedQuery?.suspended ?? node.suspended)?.[SERVING_ENGINE]
const suspended = !!suspension
// The saved setting is a lower bound: a downstream view can make this one run more often unless it is pinned.
// The node in the scene store is not reloaded after a pin save, so the refreshed bounds win when they have loaded.
const inherited =
(nodeFrequency?.bounds.pinned ?? node.pinned)
? null
: inheritedCadence(
savedQuery?.sync_frequency_bounds,
(savedQuery?.sync_frequency as SyncFrequencyValue | undefined) ?? null
)
const cadence = inherited?.cadence ?? savedQuery?.sync_frequency
const schedule = suspended
? 'Suspended after repeated failures'
: node.type === 'endpoint'
? 'Managed by endpoint'
: modeDisabledReason(savedQuery?.sync_frequency_bounds)
? 'Managed by PostHog'
: !savedQuery
? savedQueryError
? 'Schedule unavailable'
: null
: !cadence || cadence === 'never'
? 'Paused'
: `Every ${CADENCE_LABELS[cadence as DataModelingSyncInterval] ?? cadence}`
const latestJob = dataModelingJobs?.results?.[0]
return (
<ModelHealthSummary
metadata={metadata}
status={latestJob?.status ?? savedQuery?.status ?? effectiveLastRunStatus}
suspended={suspended}
error={suspension?.reason ?? latestJob?.error ?? savedQuery?.latest_error ?? node.last_run_error}
lastSuccessfulSyncAt={lastSuccessfulSyncAt}
historyLoaded={dataModelingJobs !== null}
historyError={dataModelingJobsError || statusRefreshError}
onRetry={refreshMaterialization}
retryLoading={dataModelingJobsLoading || statusRefreshing}
schedule={schedule}
lineageUrl={urls.nodeDetail(id, 'lineage')}
downstreamCount={node.downstream_count}
/>
)
}