: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
fix(conversations): align composer with private note mode (#72603)
Xandercfe05fc2483f
diff --git a/products/conversations/frontend/components/Chat/ChatView.tsx b/products/conversations/frontend/components/Chat/ChatView.tsxindex b3e0251f2b1a..6d89783769ea 100644--- a/products/conversations/frontend/components/Chat/ChatView.tsx+++ b/products/conversations/frontend/components/Chat/ChatView.tsx@@ -49,7 +49,7 @@ export interface ChatViewProps {/** Recipient description shown in the draft-mode send confirmation */sendConfirmationMessage?: string/** When provided, renders a dropdown next to the send button to send and set the ticket status in one go */- sendAndSetStatusOptions?: { value: TicketStatus; label: string }[]+ sendAndSetStatusOptions?: { value: TicketStatus; statusLabel: string }[]/** Other unsaved ticket edits that sending with a status would also persist */unsavedTicketChanges?: string[]latestAiMessageId?: string | nulldiff --git a/products/conversations/frontend/components/Chat/MessageInput.test.tsx b/products/conversations/frontend/components/Chat/MessageInput.test.tsxnew file mode 100644index 000000000000..2d653bb40e08--- /dev/null+++ b/products/conversations/frontend/components/Chat/MessageInput.test.tsx@@ -0,0 +1,79 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'++import { initKeaTests } from '~/test/init'++import type { TicketStatus } from '../../types'+import { MessageInput } from './MessageInput'++// The real SupportEditor pulls in tiptap, mentions, and uploads; the behavior under test is+// MessageInput's own wiring, which only needs an editor exposing getJSON().+jest.mock('../Editor', () => {+ const React = jest.requireActual<typeof import('react')>('react')+ return {+ SupportEditor: ({ onCreate }: { onCreate: (editor: unknown) => void }) => {+ React.useEffect(() => {+ onCreate({ getJSON: () => ({ type: 'doc' }), clear: () => {} })+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [])+ return React.createElement('div')+ },+ serializeToMarkdown: (): string => 'hello',+ }+})++const SEND_AND_SET_STATUS_OPTIONS: { value: TicketStatus; statusLabel: string }[] = [+ { value: 'pending', statusLabel: 'pending' },+ { value: 'on_hold', statusLabel: 'on hold' },+ { value: 'resolved', statusLabel: 'resolved' },+]++describe('MessageInput send-and-set-status dropdown', () => {+ beforeEach(() => {+ initKeaTests()+ })++ afterEach(() => {+ cleanup()+ })++ // Guards the private-note flag through the dropdown path: dropping it would deliver an+ // internal note to the customer as a real reply.+ test.each<[string, boolean, string]>([+ ['regular mode', false, 'Send'],+ ['private note mode', true, 'Attach'],+ ])('in %s the dropdown labels use the mode verb and preserve the private flag', async (_name, isPrivate, verb) => {+ const onSendMessage = jest.fn()++ render(+ <Provider>+ <MessageInput+ onSendMessage={onSendMessage}+ messageSending={false}+ showPrivateOption+ isPrivate={isPrivate}+ onPrivateChange={jest.fn()}+ draftMode={false}+ onDraftModeChange={jest.fn()}+ draftContent={{ type: 'doc', content: [] }}+ sendAndSetStatusOptions={SEND_AND_SET_STATUS_OPTIONS}+ />+ </Provider>+ )++ // Draft mode has no effect on private notes, so its switch is disabled in private note mode+ expect(screen.getByRole('switch')).toHaveProperty('disabled', isPrivate)++ await userEvent.click(screen.getByLabelText(`${verb} and set ticket status`))+ expect(await screen.findByText(`${verb} and set pending`)).toBeInTheDocument()+ expect(screen.getByText(`${verb} and set on hold`)).toBeInTheDocument()+ expect(screen.getByText(`${verb} and set resolved`)).toBeInTheDocument()++ await userEvent.click(screen.getByText(`${verb} and set pending`))+ expect(onSendMessage).toHaveBeenCalledTimes(1)+ expect(onSendMessage).toHaveBeenCalledWith('hello', { type: 'doc' }, isPrivate, expect.any(Function), 'pending')+ })+})diff --git a/products/conversations/frontend/components/Chat/MessageInput.tsx b/products/conversations/frontend/components/Chat/MessageInput.tsxindex 4495ca121947..d80b3784f8da 100644--- a/products/conversations/frontend/components/Chat/MessageInput.tsx+++ b/products/conversations/frontend/components/Chat/MessageInput.tsx@@ -43,7 +43,7 @@ export interface MessageInputProps {/** Recipient description shown in the draft-mode send confirmation (e.g. "This will send to ...") */sendConfirmationMessage?: string/** When provided, renders a dropdown next to the send button to send and set the ticket status in one go */- sendAndSetStatusOptions?: { value: TicketStatus; label: string }[]+ sendAndSetStatusOptions?: { value: TicketStatus; statusLabel: string }[]/** Other unsaved ticket edits that sending with a status would also persist; when non-empty, asks for confirmation first */unsavedTicketChanges?: string[]}@@ -80,6 +80,8 @@ export function MessageInput({const isPrivate = controlledIsPrivate ?? localIsPrivateconst setIsPrivate = onPrivateChange ?? setLocalIsPrivate+ const sendVerb = isPrivate ? 'Attach' : 'Send'+const handleSubmit = (statusAfterSend?: TicketStatus): void => {// These guard the Cmd+Enter path, which bypasses the (disabled) button.if (replyDisabledReason && !isPrivate) {@@ -112,10 +114,12 @@ export function MessageInput({// Sending with a status saves the whole ticket, so surface any other unsaved edits first.if (statusAfterSend && unsavedTicketChanges && unsavedTicketChanges.length > 0) {LemonDialog.open({- title: 'Send and save other changes?',+ title: `${sendVerb} and save other changes?`,description: (<>- <p>Sending will also save your other unsaved ticket changes:</p>+ <p>+ {isPrivate ? 'Attaching' : 'Sending'} will also save your other unsaved ticket changes:+ </p><ul className="list-disc pl-5">{unsavedTicketChanges.map((change) => (<li key={change}>{change}</li>@@ -126,7 +130,7 @@ export function MessageInput({) : null}</>),- primaryButton: { children: 'Send and save', type: 'primary', onClick: doSend },+ primaryButton: { children: `${sendVerb} and save`, type: 'primary', onClick: doSend },secondaryButton: { children: 'Cancel' },})} else if (draftMode && !isPrivate && sendConfirmationMessage) {@@ -204,9 +208,16 @@ export function MessageInput({)}<div className="flex items-center gap-2">{onDraftModeChange && (- <Tooltip title="In draft mode, sending asks you to confirm the recipient first.">+ <Tooltip+ title={isPrivate ? null : 'In draft mode, sending asks you to confirm the recipient first.'}+ ><span>- <LemonSwitch checked={draftMode} onChange={onDraftModeChange} label="Draft mode" />+ <LemonSwitch+ checked={draftMode}+ onChange={onDraftModeChange}+ label="Draft mode"+ disabledReason={isPrivate ? 'Draft mode has no effect on private notes' : undefined}+ /></span></Tooltip>)}@@ -219,7 +230,7 @@ export function MessageInput({sideAction={sendAndSetStatusOptions?.length? {- 'aria-label': 'Send and set ticket status',+ 'aria-label': `${sendVerb} and set ticket status`,disabled: messageSending,disabledReason: sendBlockedReason,dropdown: {@@ -231,7 +242,7 @@ export function MessageInput({size="small"onClick={() => handleSubmit(option.value)}>- {option.label}+ {`${sendVerb} and set ${option.statusLabel}`}</LemonButton>)),},diff --git a/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx b/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsxindex 12a83a534d9b..7e93b6832380 100644--- a/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx+++ b/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx@@ -58,10 +58,11 @@ function getChannelThreadUrl(ticket: Ticket | null): string | undefined {return undefined}-const SEND_AND_SET_STATUS_OPTIONS: { value: TicketStatus; label: string }[] = [- { value: 'pending', label: 'Send and set pending' },- { value: 'on_hold', label: 'Send and set on hold' },- { value: 'resolved', label: 'Send and set resolved' },+// The rendered label is "<Send|Attach> and set <statusLabel>", depending on the private note checkbox+const SEND_AND_SET_STATUS_OPTIONS: { value: TicketStatus; statusLabel: string }[] = [+ { value: 'pending', statusLabel: 'pending' },+ { value: 'on_hold', statusLabel: 'on hold' },+ { value: 'resolved', statusLabel: 'resolved' },]export function SupportTicketScene({ ticketId }: { ticketId: string }): JSX.Element {