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.

1010 B
Raw Blame
import { createSetupDetectionLogic } from 'lib/components/ProductEmptyState/setupDetectionLogic'
import { projectLogic } from 'scenes/projectLogic'

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

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

/**
 * Setup detection for the notebooks empty state. Notebooks are a creation-first
 * product, so "set up" means the project has at least one notebook. Templates the
 * table lists alongside them are local, so they never count as a notebook.
 */
export const notebooksSetupLogic = createSetupDetectionLogic({
    productKey: ProductKey.NOTEBOOKS,
    path: ['products', 'notebooks', 'frontend', 'emptyState', 'notebooksSetupLogic'],
    cacheHasData: true,
    revalidateCachedHasData: true,
    detect: async () => {
        const projectId = String(projectLogic.findMounted()?.values.currentProjectId)
        const response = await notebooksList(projectId, { limit: 1 })
        return response.count > 0 ? 'has-data' : 'needs-setup'
    },
})