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.7 KB
Raw Blame
import { useActions, useValues } from 'kea'

import { LemonSkeleton } from '@posthog/lemon-ui'

import { NotFound } from 'lib/components/NotFound'
import { userPreferencesLogic } from 'lib/logic/userPreferencesLogic'
import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper'

import { PropertyDefinitionType } from '~/types'

import { groupLogic } from 'products/groups/frontend/logics/groupLogic'

import { NotebookNodeType } from '../types'
import { Properties } from './components/Properties'
import { notebookNodeLogic } from './notebookNodeLogic'

const Component = (): JSX.Element | null => {
    const { expanded } = useValues(notebookNodeLogic)

    const { groupData, groupDataLoading } = useValues(groupLogic)
    const { pinnedGroupProperties } = useValues(userPreferencesLogic)
    const { pinGroupProperty, unpinGroupProperty } = useActions(userPreferencesLogic)

    if (groupDataLoading) {
        return <LemonSkeleton className="h-6" />
    } else if (!groupData) {
        return <NotFound object="group" />
    }

    if (!expanded) {
        return null
    }

    return (
        <Properties
            key={`${groupData.group_type_index}-${groupData.group_key}`}
            properties={groupData.group_properties || {}}
            pinnedProperties={pinnedGroupProperties}
            onPin={pinGroupProperty}
            onUnpin={unpinGroupProperty}
            type={PropertyDefinitionType.Group}
        />
    )
}

export const NotebookNodeGroupProperties = createPostHogWidgetNode({
    nodeType: NotebookNodeType.GroupProperties,
    titlePlaceholder: 'Properties',
    Component,
    resizeable: false,
    expandable: true,
    startExpanded: true,
    attributes: {},
})