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.

2.4 KB
Raw Blame
import { IconPlusSmall } from '@posthog/icons'

import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { ButtonPrimitive, ButtonPrimitiveProps } from 'lib/ui/Button/ButtonPrimitives'
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from 'lib/ui/DropdownMenu/DropdownMenu'
import { MenuOpenIndicator } from 'lib/ui/Menus/Menus'
import { NotebookNodeType } from 'scenes/notebooks/types'

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

import { SceneDataAttrKeyProps } from '../utils'
import { SceneNotebookMenuItems } from './SceneNotebookMenuItems'

type SceneNotebookDropdownMenuProps = SceneDataAttrKeyProps &
    Pick<ButtonPrimitiveProps, 'disabledReasons'> & {
        shortId?: string
    }

export function SceneAddToNotebookDropdownMenu({
    shortId,
    dataAttrKey,
    disabledReasons,
}: SceneNotebookDropdownMenuProps): JSX.Element | null {
    // The rail redesign (`today-rail-nav`) deprecates adding to notebooks from outside a notebook. See QuillNotebookSelectButton to bring it back.
    const hidden = useFeatureFlag('TODAY_RAIL_NAV')
    if (hidden) {
        return null
    }
    const isDisabled = disabledReasons ? Object.values(disabledReasons).some(Boolean) : false
    return (
        <DropdownMenu>
            <DropdownMenuTrigger asChild disabled={isDisabled}>
                <ButtonPrimitive
                    menuItem
                    data-attr={`${dataAttrKey}-add-to-dropdown-menu`}
                    disabledReasons={disabledReasons}
                >
                    <IconPlusSmall />
                    Add to notebook
                    <MenuOpenIndicator className="ml-auto" />
                </ButtonPrimitive>
            </DropdownMenuTrigger>
            <DropdownMenuContent align="end" matchTriggerWidth className="min-w-none max-w-none">
                <SceneNotebookMenuItems
                    notebookSelectButtonProps={{
                        resource: {
                            type: NotebookNodeType.Query,
                            attrs: {
                                query: {
                                    kind: NodeKind.SavedInsightNode,
                                    shortId: shortId,
                                },
                            },
                        },
                    }}
                    dataAttrKey={dataAttrKey}
                />
            </DropdownMenuContent>
        </DropdownMenu>
    )
}