: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 { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { SidePanelTab } from '~/types'
import type { FeatureFlagsSet } from '../../../lib/logic/featureFlagLogic'
import { NotebookNodeResource } from '../types'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookPanelLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
selectedTab: SidePanelTab | null // sidePanelStateLogic
sidePanelOpen: boolean // sidePanelStateLogic
dropMode: boolean
droppedResource: string | NotebookNodeResource | null
selectedNotebook: string
visibility: 'hidden' | 'visible'
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookPanelLogicActions {
closeSidePanel: (tab?: SidePanelTab | undefined) => {
tab: SidePanelTab | undefined
} // sidePanelStateLogic
openSidePanel: (
tab: SidePanelTab,
options?: string | undefined
) => {
options: string | undefined
tab: SidePanelTab
} // sidePanelStateLogic
endDropMode: () => {
value: true
}
selectNotebook: (
id: string,
options?: {
silent?: boolean
}
) => {
id: string
silent?: boolean | undefined
}
setDroppedResource: (resource: string | NotebookNodeResource | null) => {
resource: string | NotebookNodeResource | null
}
startDropMode: () => {
value: true
}
toggleVisibility: () => {
value: true
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookPanelLogicMeta {
__keaTypeGenInternalSelectorTypes: {
visibility: (selectedTab: SidePanelTab | null, sidePanelOpen: boolean) => 'hidden' | 'visible'
}
}
export type notebookPanelLogicType = MakeLogicType<
notebookPanelLogicValues,
notebookPanelLogicActions,
Record<string, any>,
notebookPanelLogicMeta
>
export const notebookPanelLogic = kea<notebookPanelLogicType>([
path(['scenes', 'notebooks', 'Notebook', 'notebookPanelLogic']),
connect(() => ({
values: [sidePanelStateLogic, ['sidePanelOpen', 'selectedTab'], featureFlagLogic, ['featureFlags']],
actions: [sidePanelStateLogic, ['openSidePanel', 'closeSidePanel']],
})),
actions({
selectNotebook: (id: string, options: { silent?: boolean } = {}) => ({
id,
...options,
}),
startDropMode: true,
endDropMode: true,
setDroppedResource: (resource: NotebookNodeResource | string | null) => ({ resource }),
toggleVisibility: true,
}),
reducers(() => ({
selectedNotebook: [
'scratchpad',
{ persist: true },
{
selectNotebook: (_, { id }) => id,
},
],
dropMode: [
false,
{
startDropMode: () => true,
endDropMode: () => false,
},
],
droppedResource: [
null as NotebookNodeResource | string | null,
{
closeSidePanel: () => null,
setDroppedResource: (_, { resource }) => resource,
},
],
})),
selectors({
visibility: [
(s) => [s.selectedTab, s.sidePanelOpen],
(selectedTab: SidePanelTab | null, sidePanelOpen: boolean): 'hidden' | 'visible' => {
return selectedTab === SidePanelTab.Notebooks && sidePanelOpen ? 'visible' : 'hidden'
},
],
}),
listeners(({ actions, values }) => ({
selectNotebook: (options) => {
if (options.silent) {
return
}
actions.openSidePanel(SidePanelTab.Notebooks)
},
toggleVisibility: () => {
if (values.visibility === 'hidden') {
actions.openSidePanel(SidePanelTab.Notebooks)
} else {
actions.closeSidePanel()
}
},
})),
])