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.

1.5 KB
Raw Blame
import { createSetupDetectionLogic } from 'lib/components/ProductEmptyState/setupDetectionLogic'
import { projectLogic } from 'scenes/projectLogic'

import { dashboardsModel } from '~/models/dashboardsModel'
import { ProductKey } from '~/queries/schema/schema-general'

import { dashboardsList } from '../generated/api'

/**
 * Setup detection for the dashboards empty state. Dashboards are a creation-first
 * product, so "set up" simply means the project has at least one dashboard - no
 * event or traffic signal involved.
 */
export const dashboardsSetupLogic = createSetupDetectionLogic({
    productKey: ProductKey.DASHBOARDS,
    path: ['products', 'dashboards', 'frontend', 'emptyState', 'dashboardsSetupLogic'],
    detect: async () => {
        const projectId = String(projectLogic.findMounted()?.values.currentProjectId)
        const response = await dashboardsList(projectId, { limit: 1, exclude_generated: true })
        return response.count > 0 ? 'has-data' : 'needs-setup'
    },
    // Creation and deletion can leave this scene mounted, so its setup status must follow entity changes.
    recheckActionTypes: () => [
        dashboardsModel.actionTypes.addDashboardSuccess,
        dashboardsModel.actionTypes.deleteDashboardSuccess,
        dashboardsModel.actionTypes.restoreDashboardSuccess,
        dashboardsModel.actionTypes.bulkDeleteDashboardsSuccess,
        dashboardsModel.actionTypes.reloadDashboardsSuccess,
    ],
    allowReturnToSetup: true,
    cacheHasData: true,
    revalidateCachedHasData: true,
})