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.

3.7 KB
Raw Blame
import { useActions, useValues } from 'kea'

import { LemonBanner, LemonButton, LemonInput, LemonModal, LemonTextArea } from '@posthog/lemon-ui'

import { LemonLabel } from 'lib/lemon-ui/LemonLabel'

import {
    NotebookNodeGeneratedWidgetLogicProps,
    notebookNodeGeneratedWidgetLogic,
} from './notebookNodeGeneratedWidgetLogic'

export function NotebookWidgetPublishModal(props: NotebookNodeGeneratedWidgetLogicProps): JSX.Element {
    const logic = notebookNodeGeneratedWidgetLogic(props)
    const { publishDescription, publishError, publishInFlight, publishModalOpen, publishName, publishTags } =
        useValues(logic)
    const { closePublishModal, publishReusableWidget, setPublishDescription, setPublishName, setPublishTags } =
        useActions(logic)

    return (
        <LemonModal
            isOpen={publishModalOpen}
            onClose={closePublishModal}
            title="Make widget reusable"
            description="This publishes the widget to your project. Add sample rows in Demo data after publishing."
            footer={
                <>
                    <LemonButton onClick={closePublishModal}>Cancel</LemonButton>
                    <LemonButton
                        type="primary"
                        onClick={publishReusableWidget}
                        data-attr="reusable-widget-publish"
                        loading={publishInFlight}
                        disabledReason={!publishName.trim() ? 'Add a widget name.' : undefined}
                    >
                        Make reusable
                    </LemonButton>
                </>
            }
        >
            <div className="flex flex-col gap-4">
                <div>
                    <LemonLabel htmlFor={`reusable-widget-name-${props.nodeId}`}>Name</LemonLabel>
                    <LemonInput
                        id={`reusable-widget-name-${props.nodeId}`}
                        value={publishName}
                        onChange={setPublishName}
                        maxLength={400}
                        autoFocus
                        className="mt-1"
                    />
                </div>
                <div>
                    <LemonLabel htmlFor={`reusable-widget-description-${props.nodeId}`}>Description</LemonLabel>
                    <LemonTextArea
                        id={`reusable-widget-description-${props.nodeId}`}
                        value={publishDescription}
                        onChange={setPublishDescription}
                        placeholder="Describe what this widget shows and when to use it."
                        maxLength={2000}
                        minRows={3}
                        className="mt-1"
                    />
                </div>
                <div>
                    <LemonLabel htmlFor={`reusable-widget-tags-${props.nodeId}`}>Tags</LemonLabel>
                    <LemonInput
                        id={`reusable-widget-tags-${props.nodeId}`}
                        value={publishTags}
                        onChange={setPublishTags}
                        placeholder="Revenue, plans, comparison"
                        className="mt-1"
                    />
                    <div className="mt-1 text-xs text-muted">Separate tags with commas.</div>
                </div>
                <LemonBanner type="info">
                    Demo inputs start empty. Any sample rows you add will be shared with everyone who can access the
                    project catalog. Use invented data. Unpinned instances will follow new versions automatically.
                </LemonBanner>
                {publishError ? <LemonBanner type="error">{publishError}</LemonBanner> : null}
            </div>
        </LemonModal>
    )
}