: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 { useActions, useValues } from 'kea'
import { useEffect } from 'react'
import * as stopPng from '@posthog/brand/hoggies/png/stop'
import { pngHoggie } from 'lib/brand/hoggies'
import { humanizeScope } from 'lib/components/ActivityLog/humanizeActivity'
import { CommentComposer } from 'lib/components/Comments/CommentComposer'
import { CommentsList } from 'lib/components/Comments/CommentsList'
import { CommentsLogicProps, commentsLogic } from 'lib/components/Comments/commentsLogic'
import { SidePanelPaneHeader } from '../../components/SidePanelPaneHeader'
import { SidePanelContentContainer } from '../../SidePanelContentContainer'
import { sidePanelStateLogic } from '../../sidePanelStateLogic'
import { sidePanelDiscussionLogic } from './sidePanelDiscussionLogic'
const HedgehogStop = pngHoggie(stopPng)
export const SidePanelDiscussion = (): JSX.Element => {
const { commentsLogicProps, sceneSidePanelContext } = useValues(sidePanelDiscussionLogic)
const disabledReason = sceneSidePanelContext.discussions_disabled_reason
const { scope, item_id } = commentsLogicProps ?? {}
const discussionTitle = (
<div className="flex deprecated-space-x-2">
<span>
Discussion{' '}
{scope ? (
<span className="font-normal text-secondary">
about {item_id ? 'this' : ''} {humanizeScope(scope, !!item_id)}
</span>
) : null}
</span>
</div>
)
return (
<div className="flex flex-col overflow-hidden flex-1">
<SidePanelContentContainer>
{commentsLogicProps && commentsLogicProps.disabled ? (
<SidePanelPaneHeader title={discussionTitle} />
) : null}
{commentsLogicProps && !commentsLogicProps.disabled ? (
<DiscussionContent logicProps={commentsLogicProps}>
<SidePanelPaneHeader title={discussionTitle} />
</DiscussionContent>
) : disabledReason ? (
<p className="m-0 p-4 text-secondary">{disabledReason}</p>
) : (
<div className="mx-auto p-8 max-w-160 mt-8 ">
<div className="max-w-24 mx-auto">
<HedgehogStop className="w-full h-full" />
</div>
<h2>Discussions aren't supported here yet...</h2>
<p>
This a beta feature that is currently only available when viewing things like an Insight,
Dashboard or Notebook.
</p>
</div>
)}
</SidePanelContentContainer>
</div>
)
}
const DiscussionContent = ({
logicProps,
children,
}: {
logicProps: CommentsLogicProps
children?: React.ReactNode
}): JSX.Element => {
const { selectedTabOptions } = useValues(sidePanelStateLogic)
const { setSelectedComment } = useActions(commentsLogic(logicProps))
const { setCommentsListRef } = useActions(sidePanelDiscussionLogic)
useEffect(() => {
// Select without auto-focusing the composer; reveal expands the thread the deep link targets
setSelectedComment(selectedTabOptions ?? null, true)
}, [selectedTabOptions]) // oxlint-disable-line react-hooks/exhaustive-deps
return (
<>
<div className="flex-1 overflow-y-auto p-2 contents" ref={setCommentsListRef}>
{children}
<CommentsList {...logicProps} />
</div>
<div className="border-t px-3 pb-3">
<CommentComposer {...logicProps} />
</div>
</>
)
}