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.

feat(subscriptions): surface test delivery on detail-page header (#66786)

Vasco de Krijgerbff9b0cd71aa
diff --git a/frontend/src/scenes/subscriptions/SubscriptionScene.tsx b/frontend/src/scenes/subscriptions/SubscriptionScene.tsx
index d00b30fbb310..878d8854445b 100644
--- a/frontend/src/scenes/subscriptions/SubscriptionScene.tsx
+++ b/frontend/src/scenes/subscriptions/SubscriptionScene.tsx
@@ -22,10 +22,11 @@ import { subscriptionsSceneLogic } from './subscriptionsSceneLogic'
function SubscriptionDetailActions({ sub }: { sub: SubscriptionApi }): JSX.Element {
const { push } = useActions(router)
- const { setEnabled } = useActions(subscriptionSceneLogic)
- const { subscriptionLoading } = useValues(subscriptionSceneLogic)
+ const { setEnabled, deliverSubscription } = useActions(subscriptionSceneLogic)
+ const { subscriptionLoading, deliveringSubscriptionId } = useValues(subscriptionSceneLogic)
const editHref = subscriptionEditHref(sub)
const enabled = isSubscriptionEnabled(sub)
+ const isDelivering = deliveringSubscriptionId === sub.id
const deleteSubscription = (): void => {
const name = subscriptionName(sub)
@@ -60,6 +61,15 @@ function SubscriptionDetailActions({ sub }: { sub: SubscriptionApi }): JSX.Eleme
Edit subscription
</LemonButton>
) : null}
+ <LemonButton
+ type="primary"
+ onClick={() => deliverSubscription(sub.id)}
+ loading={isDelivering}
+ disabledReason={isDelivering ? 'Sending test delivery…' : null}
+ data-attr="subscription-detail-header-test-delivery"
+ >
+ Test delivery
+ </LemonButton>
<LemonButton
type="secondary"
status="danger"
@@ -114,6 +124,8 @@ export function SubscriptionScene(): JSX.Element {
loadDeliveriesPage={loadDeliveriesPage}
deliveryStatusFilter={deliveryStatusFilter}
onDeliveryStatusFilterChange={setDeliveryStatusFilter}
+ // Empty-state CTA intentionally coexists with the header Test delivery button:
+ // it's the discoverable first-run nudge when a subscription has no deliveries yet.
onTestDelivery={subscription ? () => deliverSubscription(subscription.id) : undefined}
testDeliveryLoading={Boolean(subscription && deliveringSubscriptionId === subscription.id)}
onDeliveryFeedback={
diff --git a/frontend/src/scenes/subscriptions/components/SubscriptionDeliveryHistory.tsx b/frontend/src/scenes/subscriptions/components/SubscriptionDeliveryHistory.tsx
index a0c28b6178dc..051aa07e3f3c 100644
--- a/frontend/src/scenes/subscriptions/components/SubscriptionDeliveryHistory.tsx
+++ b/frontend/src/scenes/subscriptions/components/SubscriptionDeliveryHistory.tsx
@@ -362,32 +362,18 @@ export function SubscriptionDeliveryHistory({
<div className="flex flex-col gap-2">
<div className="flex flex-wrap items-end justify-between gap-x-4 gap-y-2">
<h2 className="text-lg font-semibold">Delivery history</h2>
- {showTable && (showStatusFilter || onTestDelivery) ? (
+ {showTable && showStatusFilter ? (
<div className="flex flex-wrap items-center gap-3 shrink-0">
- {onTestDelivery ? (
- <LemonButton
- type="tertiary"
+ <div className="flex items-center gap-2">
+ <span className="text-sm text-secondary">Status</span>
+ <LemonSelect<DeliveryListStatusFilter | null>
size="small"
- onClick={onTestDelivery}
- loading={testDeliveryLoading}
- disabledReason={testDeliveryLoading ? 'Sending test delivery…' : null}
- data-attr="subscription-detail-manual-deliver"
- >
- Test delivery
- </LemonButton>
- ) : null}
- {showStatusFilter ? (
- <div className="flex items-center gap-2">
- <span className="text-sm text-secondary">Status</span>
- <LemonSelect<DeliveryListStatusFilter | null>
- size="small"
- options={DELIVERY_STATUS_FILTER_OPTIONS}
- value={deliveryStatusFilter}
- onChange={onDeliveryStatusFilterChange}
- data-attr="subscription-deliveries-status-filter"
- />
- </div>
- ) : null}
+ options={DELIVERY_STATUS_FILTER_OPTIONS}
+ value={deliveryStatusFilter}
+ onChange={onDeliveryStatusFilterChange}
+ data-attr="subscription-deliveries-status-filter"
+ />
+ </div>
</div>
) : null}
</div>
diff --git a/frontend/src/scenes/subscriptions/subscriptionSceneLogic.test.ts b/frontend/src/scenes/subscriptions/subscriptionSceneLogic.test.ts
index e0e4cd8526e3..7fe8679cdf53 100644
--- a/frontend/src/scenes/subscriptions/subscriptionSceneLogic.test.ts
+++ b/frontend/src/scenes/subscriptions/subscriptionSceneLogic.test.ts
@@ -129,6 +129,45 @@ describe('subscriptionSceneLogic', () => {
logic.unmount()
})
+ // The failure path matters too: the header button's double-submit guard would stick
+ // if deliveringSubscriptionId reset only on success.
+ it.each([
+ { name: 'success', status: 202, terminalAction: 'deliverSubscriptionSuccess' },
+ { name: 'failure', status: 500, terminalAction: 'deliverSubscriptionFailure' },
+ ])('test delivery ($name) flips deliveringSubscriptionId then resets it', async ({ status, terminalAction }) => {
+ let testDeliveryCalls = 0
+ useMocks({
+ get: {
+ [`/api/projects/${MOCK_TEAM_ID}/subscriptions/1/`]: [200, MOCK_SUBSCRIPTION],
+ [`/api/projects/${MOCK_TEAM_ID}/subscriptions/1/deliveries/`]: [
+ 200,
+ { results: [], next: null, previous: null },
+ ],
+ },
+ post: {
+ [`/api/projects/${MOCK_TEAM_ID}/subscriptions/1/test-delivery/`]: () => {
+ testDeliveryCalls += 1
+ return [status, {}]
+ },
+ },
+ })
+ initKeaTests()
+
+ const logic = subscriptionSceneLogic({ id: '1' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ await expectLogic(logic, () => {
+ logic.actions.deliverSubscription(1)
+ }).toMatchValues({ deliveringSubscriptionId: 1 })
+
+ await expectLogic(logic).toDispatchActions([terminalAction]).toMatchValues({
+ deliveringSubscriptionId: null,
+ })
+ expect(testDeliveryCalls).toEqual(1)
+ logic.unmount()
+ })
+
it('loads an AI prompt subscription and its deliveries', async () => {
useMocks({
get: {