: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 posthog from 'posthog-js'
import { useState } from 'react'
import { IconCopy } from '@posthog/icons'
import { LemonBanner, LemonButton, LemonDivider, LemonModal } from '@posthog/lemon-ui'
import { SHARING_MODAL_WIDTH, SharingModalContent } from 'lib/components/Sharing/SharingModal'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { urls } from 'scenes/urls'
import { AccessControlPopoutCTA } from '~/layout/navigation-3000/sidepanel/panels/access_control/AccessControlPopoutCTA'
import { AccessControlResourceType } from '~/types'
import { notebookLogic } from './notebookLogic'
export type NotebookShareModalProps = {
shortId: string
}
export function NotebookShareModal({ shortId }: NotebookShareModalProps): JSX.Element {
const { isShareModalOpen } = useValues(notebookLogic({ shortId }))
if (!isShareModalOpen) {
return <></>
}
return <OpenNotebookShareModal shortId={shortId} />
}
function OpenNotebookShareModal({ shortId }: NotebookShareModalProps): JSX.Element {
const { isLocalOnly, isShareModalOpen } = useValues(notebookLogic({ shortId }))
const { closeShareModal } = useActions(notebookLogic({ shortId }))
const externalSharingEnabled = useFeatureFlag('NOTEBOOK_SHARING')
const [interestTracked, setInterestTracked] = useState(false)
const notebookUrl = urls.absolute(urls.currentProject(urls.notebook(shortId)))
const trackInterest = (): void => {
posthog.capture('pressed interested in notebook sharing', { url: notebookUrl })
}
return (
<LemonModal
title="Share notebook"
onClose={() => closeShareModal()}
isOpen={isShareModalOpen}
width={SHARING_MODAL_WIDTH}
footer={
<LemonButton type="secondary" onClick={closeShareModal}>
Done
</LemonButton>
}
>
<div className="deprecated-space-y-4">
<AccessControlPopoutCTA
resourceType={AccessControlResourceType.Notebook}
callback={() => {
closeShareModal()
}}
/>
<LemonDivider />
<h3>Internal link</h3>
{!isLocalOnly ? (
<>
<p>
<b>Click the button below</b> to copy a direct link to this notebook. Make sure the person
you share it with has access to this PostHog project.
</p>
<LemonButton
type="secondary"
fullWidth
center
truncate
sideIcon={<IconCopy />}
onClick={() => void copyToClipboard(notebookUrl, 'notebook link')}
title={notebookUrl}
>
{notebookUrl}
</LemonButton>
</>
) : (
<LemonBanner type="info">
<p>This notebook cannot be shared directly with others as it is only visible to you.</p>
</LemonBanner>
)}
{!isLocalOnly &&
(externalSharingEnabled ? (
<>
<LemonDivider className="my-4" />
<SharingModalContent notebookShortId={shortId} />
</>
) : (
<>
<LemonDivider className="my-4" />
<h3>External sharing</h3>
<LemonBanner
type="warning"
action={{
children: !interestTracked ? 'I would like this!' : 'Thanks!',
onClick: () => {
if (!interestTracked) {
trackInterest()
setInterestTracked(true)
}
},
}}
>
We don't currently support sharing notebooks externally, but it's on our roadmap!
</LemonBanner>
</>
))}
</div>
</LemonModal>
)
}