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.

fix(conversations): keep the active view when using a ticket's back arrow (#73289)

Christiaan Hendriksen4b1410f45187
diff --git a/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx b/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx
index 7c177234af95..0c6b87c303b4 100644
--- a/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx
+++ b/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx
@@ -1,4 +1,5 @@
import { useActions, useValues } from 'kea'
+import { combineUrl, router } from 'kea-router'
import { useRef } from 'react'
import { IconChevronDown } from '@posthog/icons'
@@ -19,6 +20,7 @@ import { userLogic } from 'scenes/userLogic'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { ProductKey } from '~/queries/schema/schema-general'
+import { Breadcrumb } from '~/types'
import { AssigneeIconDisplay, AssigneeLabelDisplay, AssigneeSelect } from '../../components/Assignee'
import { ChannelsTag, getChannelThreadUrl } from '../../components/Channels/ChannelsTag'
@@ -37,6 +39,18 @@ import { StaffActionsPanel } from './StaffActionsPanel'
import { supportTicketSceneLogic } from './supportTicketSceneLogic'
import { TicketActivityPanel } from './TicketActivityPanel'
+// The list's filters / saved view ride along in the ticket page's query string
+// (the ticket row carries them through on navigation). Rebuild the list URL from
+// them so the back arrow returns to the view the user came from rather than the
+// unfiltered ticket list.
+export function ticketListBackTo(searchParams: Record<string, any>): Breadcrumb {
+ return {
+ name: 'Ticket list',
+ path: combineUrl(urls.supportTickets(), searchParams).url,
+ key: 'supportTickets',
+ }
+}
+
export const scene: SceneExport<{ ticketId: string; id: string }> = {
component: SupportTicketScene,
logic: supportTicketSceneLogic,
@@ -85,6 +99,11 @@ export function SupportTicketScene({ ticketId }: { ticketId: string }): JSX.Elem
latestAiMessage,
feedbackByMessageId,
} = useValues(logic)
+ // The list's filters / saved view ride along in this page's query string
+ // (the ticket row carries them through on navigation). Preserve them on the
+ // back arrow so it returns to the view the user came from rather than the
+ // unfiltered ticket list (see ticketListBackTo).
+ const { searchParams } = useValues(router)
const {
setStatus,
setPriority,
@@ -178,11 +197,7 @@ export function SupportTicketScene({ ticketId }: { ticketId: string }): JSX.Elem
}
description=""
resourceType={{ type: 'conversation' }}
- forceBackTo={{
- name: 'Ticket list',
- path: urls.supportTickets(),
- key: 'supportTickets',
- }}
+ forceBackTo={ticketListBackTo(searchParams)}
/>
<div className="flex flex-col lg:flex-row items-start lg:min-h-0 lg:flex-1">
diff --git a/products/conversations/frontend/scenes/tickets/SupportTicketsScene.test.tsx b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.test.tsx
index 833fe6fc7496..23e4d8db2181 100644
--- a/products/conversations/frontend/scenes/tickets/SupportTicketsScene.test.tsx
+++ b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.test.tsx
@@ -3,11 +3,15 @@ import '@testing-library/jest-dom'
import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
+import { router } from 'kea-router'
+
+import { urls } from 'scenes/urls'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { Ticket } from '../../types'
+import { ticketListBackTo } from '../ticket/SupportTicketScene'
import { SupportTicketsTable, SupportTicketsTableFilters } from './SupportTicketsScene'
import { supportTicketsSceneLogic } from './supportTicketsSceneLogic'
@@ -97,6 +101,75 @@ describe('SupportTicketsTable selection', () => {
await waitFor(() => expect(getRowCheckbox()).not.toBeChecked())
expect(logic.values.selectedTicketIds).toEqual([])
})
+
+ // Regression: opening a ticket from a filtered list dropped the filters, so the ticket's
+ // back arrow returned to the unfiltered "all tickets" list instead of the view the user
+ // was on. The row now carries the list's query string onto the ticket URL so the back
+ // arrow can restore it.
+ it('carries the active filters onto the ticket URL when a row is opened', async () => {
+ act(() => {
+ logic.actions.setStatusFilter(['open'])
+ })
+ // The filter is reflected in the list URL first.
+ await waitFor(() => expect(router.values.searchParams.status).not.toBeUndefined())
+
+ render(
+ <Provider>
+ <SupportTicketsTable />
+ </Provider>
+ )
+
+ // Click the ticket row itself (not the selection checkbox). The router pathname is
+ // project-scoped (e.g. /project/997/...), so match on the ticket path suffix.
+ const rows = screen.getAllByRole('row')
+ await userEvent.click(rows[rows.length - 1])
+
+ await waitFor(() =>
+ expect(router.values.location.pathname).toContain(urls.supportTicketDetail(TICKET.ticket_number))
+ )
+ // Filters ride along on the ticket URL so the back arrow returns to this view.
+ expect(router.values.searchParams.status).not.toBeUndefined()
+ })
+
+ // Regression (the back half): the ticket's back arrow rebuilds the list URL from the
+ // filters carried in the ticket page's query string via `ticketListBackTo`. If that
+ // construction drops the filters, the arrow lands on the unfiltered "all tickets" list
+ // — the actual bug. This follows the round trip: open a filtered ticket, then the back
+ // arrow, and confirm it lands back on the filtered list.
+ it('sends the ticket back arrow to the filtered list', async () => {
+ act(() => {
+ logic.actions.setStatusFilter(['open'])
+ })
+ await waitFor(() => expect(router.values.searchParams.status).not.toBeUndefined())
+
+ render(
+ <Provider>
+ <SupportTicketsTable />
+ </Provider>
+ )
+
+ // Open the ticket from the filtered list; the row carries the filters onto its URL.
+ // (Router pathnames are project-scoped, so match on the path suffix.)
+ const rows = screen.getAllByRole('row')
+ await userEvent.click(rows[rows.length - 1])
+ await waitFor(() =>
+ expect(router.values.location.pathname).toContain(urls.supportTicketDetail(TICKET.ticket_number))
+ )
+
+ // The back arrow's target is built from the ticket page's live query string. It must
+ // point back at the ticket list and keep the status filter.
+ const backPath = ticketListBackTo(router.values.searchParams).path ?? ''
+ expect(backPath.split('?')[0]).toBe(urls.supportTickets())
+ expect(backPath).toContain('status')
+
+ // Follow the back arrow: it lands on the filtered ticket list, not the unfiltered
+ // "all tickets" view.
+ act(() => {
+ router.actions.push(backPath)
+ })
+ await waitFor(() => expect(router.values.location.pathname).toContain(urls.supportTickets()))
+ expect(router.values.searchParams.status).not.toBeUndefined()
+ })
})
describe('SupportTicketsTableFilters count', () => {
diff --git a/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsx b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsx
index 48dee05de283..2b44ac4ae3a4 100644
--- a/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsx
+++ b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsx
@@ -1,6 +1,6 @@
import clsx from 'clsx'
import { useActions, useMountedLogic, useValues } from 'kea'
-import { router } from 'kea-router'
+import { combineUrl, router } from 'kea-router'
import { useEffect, useMemo, useRef } from 'react'
import { IconChevronDown, IconRefresh } from '@posthog/icons'
@@ -110,6 +110,7 @@ export function SupportTicketsTable({ embedded = false }: SupportTicketsTablePro
const { setCurrentPage, setSorting, setSelectedTicketIds, clearFiltersKeepingSearch } = useActions(logic)
const { visibleColumns } = useValues(ticketColumnsLogic)
const { push } = useActions(router)
+ const { searchParams } = useValues(router)
const { currentTeam } = useValues(teamLogic)
const aiEnabled = !!currentTeam?.conversations_settings?.ai_suggestions_enabled
@@ -216,7 +217,14 @@ export function SupportTicketsTable({ embedded = false }: SupportTicketsTablePro
: undefined,
}}
onRow={(ticket) => {
- const ticketUrl = urls.supportTicketDetail(ticket.ticket_number)
+ // Carry the active filters / saved view (the list's query string) onto the
+ // ticket URL so the ticket's back arrow can return to this exact view. Skip it
+ // when embedded (e.g. the person side panel), where the host page's query
+ // string isn't the ticket filters.
+ const ticketUrl = combineUrl(
+ urls.supportTicketDetail(ticket.ticket_number),
+ embedded ? {} : searchParams
+ ).url
return {
onClick: (e: React.MouseEvent) => {
if (e.metaKey || e.ctrlKey) {