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

import { urls } from 'scenes/urls'

import { RelatedGroups, RelatedGroupsProps } from 'products/groups/frontend/components/RelatedGroups'

import { NotebookNodeProps, NotebookNodeType } from '../types'
import { createPostHogWidgetNode } from './NodeWrapper'
import { notebookNodeLogic } from './notebookNodeLogic'

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

    if (!expanded) {
        return null
    }

    return <RelatedGroups {...attributes} pageSize={10} embedded />
}

type NotebookNodeRelatedGroupsAttributes = Pick<RelatedGroupsProps, 'id' | 'groupTypeIndex' | 'type'>

const href = ({ id, groupTypeIndex }: NotebookNodeRelatedGroupsAttributes): string => {
    if (typeof groupTypeIndex === 'number') {
        return urls.group(groupTypeIndex, id, false, 'related')
    }
    return urls.personByUUID(id) + '#activeTab=related'
}

export const NotebookNodeRelatedGroups = createPostHogWidgetNode<NotebookNodeRelatedGroupsAttributes>({
    nodeType: NotebookNodeType.RelatedGroups,
    titlePlaceholder: 'Related groups',
    Component,
    resizeable: false,
    expandable: true,
    startExpanded: true,
    href,
    attributes: {
        id: {},
        groupTypeIndex: {},
        type: {},
    },
})