: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 { IconTrash } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
import { LemonMenuOverlay } from 'lib/lemon-ui/LemonMenu/LemonMenu'
import { HogFunctionConfigurationLogicProps } from './hogFunctionConfigurationLogic'
import { hogFunctionDraftLogic } from './hogFunctionDraftLogic'
export function HogFunctionPublishDraftButton({
logicProps,
}: {
logicProps: HogFunctionConfigurationLogicProps
}): JSX.Element | null {
const logic = hogFunctionDraftLogic(logicProps)
const { hogFunction, hasStagedDraft, draftActionPending, draftActionDisabledReason } = useValues(logic)
const { publishDraft, discardDraft } = useActions(logic)
if (!hogFunction || !hasStagedDraft) {
return null
}
return (
<LemonButton
type="primary"
size="small"
onClick={publishDraft}
loading={draftActionPending === 'publish'}
disabledReason={draftActionPending === 'publish' ? undefined : draftActionDisabledReason}
tooltip="This has an unpublished draft. Publish to review the changes and send them live."
data-attr="hog-function-draft-publish"
// Discarding is rare and destructive, so it sits in the menu, as it does for workflows.
sideAction={{
'data-attr': 'hog-function-draft-actions',
'aria-label': 'More draft actions',
dropdown: {
placement: 'bottom-end',
overlay: (
<LemonMenuOverlay
items={[
{
label: 'Discard draft',
icon: <IconTrash />,
status: 'danger',
onClick: () => discardDraft(),
disabledReason: draftActionDisabledReason,
'data-attr': 'hog-function-draft-discard',
},
]}
/>
),
},
}}
>
Publish
</LemonButton>
)
}