: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): restore the saved ticket view on reopen (#121954)
Alex V3a616f1888fe
diff --git a/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.ts b/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.tsindex 16d28ea0b4c5..3f5ef91d2917 100644--- a/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.ts+++ b/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.ts@@ -324,6 +324,149 @@ describe('supportTicketsSceneLogic', () => {expect(lastOrderBy).toBe('-sla_due_at')})+ const persistedViewMocks = {+ get: {+ '/api/projects/:team_id/conversations/tickets/': () => [200, { count: 0, results: [] }],+ '/api/projects/:team_id/conversations/views/:short_id/': () => [+ 200,+ makeSavedView('view-a', { status: ['open'], dateFrom: '-24h' }),+ ],+ },+ }++ async function reopenTickets(+ searchParams: Record<string, any> = {}+ ): Promise<ReturnType<typeof supportTicketsSceneLogic.build>> {+ router.actions.push(urls.supportTickets())+ const first = supportTicketsSceneLogic()+ first.mount()+ await expectLogic(first, () => {+ first.actions.applyView(makeSavedView('view-a', { status: ['open'], dateFrom: '-24h' }))+ }).toFinishAllListeners()+ first.unmount()++ // A new kea context reads the persisted view the way a reopened page does.+ initKeaTests()+ router.actions.push(urls.supportTickets(), searchParams)+ const reopened = supportTicketsSceneLogic()+ reopened.mount()+ await expectLogic(reopened).toFinishAllListeners()+ return reopened+ }++ it('reapplies a persisted saved view when the ticket list opens without a view param', async () => {+ useMocks(persistedViewMocks)+ logic = await reopenTickets()++ expect(logic.values.activeView?.short_id).toBe('view-a')+ expect(logic.values.statusFilter).toEqual(['open'])+ expect(logic.values.dateFrom).toBe('-24h')+ expect(router.values.searchParams.view).toBe('view-a')+ })++ it('keeps the list loading while a persisted view is still reloading', async () => {+ const pending: Record<string, { resolve: (view: SavedTicketView) => void }> = {}+ useMocks({+ get: {+ '/api/projects/:team_id/conversations/tickets/': () => [200, { count: 0, results: [] }],+ '/api/projects/:team_id/conversations/views/:short_id/': () =>+ new Promise((resolve) => {+ pending['view-a'] = { resolve: (view) => resolve([200, view]) }+ }),+ },+ })+ router.actions.push(urls.supportTickets())+ const first = supportTicketsSceneLogic()+ first.mount()+ await expectLogic(first, () => {+ first.actions.applyView(makeSavedView('view-a', { status: ['open'] }))+ }).toFinishAllListeners()+ first.unmount()++ initKeaTests()+ router.actions.push(urls.supportTickets())+ logic = supportTicketsSceneLogic()+ logic.mount()++ expect(logic.values.ticketsLoading).toBe(true)+ expect(logic.values.tickets).toEqual([])++ await waitUntilPending(pending, 'view-a')+ pending['view-a'].resolve(makeSavedView('view-a', { status: ['open'] }))+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.ticketsLoading).toBe(false)+ expect(logic.values.activeView?.short_id).toBe('view-a')+ })++ it('ignores a restore response after another saved view is selected', async () => {+ const pending: Record<string, { resolve: (view: SavedTicketView) => void }> = {}+ useMocks({+ get: {+ '/api/projects/:team_id/conversations/tickets/': () => [200, { count: 0, results: [] }],+ '/api/projects/:team_id/conversations/views/:short_id/': () =>+ new Promise((resolve) => {+ pending['view-a'] = { resolve: (view) => resolve([200, view]) }+ }),+ },+ })+ router.actions.push(urls.supportTickets())+ const first = supportTicketsSceneLogic()+ first.mount()+ await expectLogic(first, () => {+ first.actions.applyView(makeSavedView('view-a', { status: ['open'] }))+ }).toFinishAllListeners()+ first.unmount()++ initKeaTests()+ router.actions.push(urls.supportTickets())+ logic = supportTicketsSceneLogic()+ logic.mount()+ await waitUntilPending(pending, 'view-a')++ logic.actions.applyView(makeSavedView('view-b', { status: ['pending'] }))+ pending['view-a'].resolve(makeSavedView('view-a', { status: ['open'] }))+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.activeView?.short_id).toBe('view-b')+ expect(logic.values.statusFilter).toEqual(['pending'])+ expect(router.values.searchParams.view).toBe('view-b')+ })++ it('drops an in-flight view link when the list opens with nothing persisted', async () => {+ const pending: Record<string, { resolve: (view: SavedTicketView) => void }> = {}+ useMocks({+ get: {+ '/api/projects/:team_id/conversations/tickets/': () => [200, { count: 0, results: [] }],+ '/api/projects/:team_id/conversations/views/:short_id/': () =>+ new Promise((resolve) => {+ pending['view-a'] = { resolve: (view) => resolve([200, view]) }+ }),+ },+ })+ router.actions.push(urls.supportTickets(), { view: 'view-a' })+ logic = supportTicketsSceneLogic()+ logic.mount()+ await waitUntilPending(pending, 'view-a')++ router.actions.push(urls.supportTickets())+ pending['view-a'].resolve(makeSavedView('view-a', { status: ['open'] }))+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.activeView).toBeNull()+ expect(logic.values.statusFilter).toEqual([])+ expect(router.values.searchParams.view).toBeUndefined()+ })++ it('lets an explicit filter link override a persisted saved view', async () => {+ useMocks(persistedViewMocks)+ logic = await reopenTickets({ status: ['pending'] })++ expect(logic.values.activeView).toBeNull()+ expect(logic.values.statusFilter).toEqual(['pending'])+ expect(logic.values.dateFrom).toBe('-7d')+ expect(router.values.searchParams.view).toBeUndefined()+ })+it('resets stale view filters when a linked view is missing', async () => {router.actions.push(urls.supportTickets())logic = supportTicketsSceneLogic()diff --git a/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.ts b/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.tsindex 7e9160392ba5..6498c6ddae05 100644--- a/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.ts+++ b/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.ts@@ -855,6 +855,8 @@ export const supportTicketsSceneLogic = kea<supportTicketsSceneLogicType>([actions.setCurrentPage(1)},applyView: ({ view }) => {+ // This selection is newer than an in-flight restore of another view.+ cache.latestViewShortId = view.short_id// Snapshot the user's own date selection the first time a view overwrites it.// The snapshot survives view switches and detaches (a detached view's dates// remain applied and persisted, so the snapshot is the only copy of the@@ -1002,10 +1004,22 @@ export const supportTicketsSceneLogic = kea<supportTicketsSceneLogicType>([}return}- const leavingSavedView = !!values.activeView || !!cache.latestViewShortId+ if (!hasFilterParams(searchParams)) {+ if (values.activeView) {+ // The tickets nav link is bare `/support/tickets`. Reload the persisted+ // view here, or the next visit drops it. Filter params below still detach.+ actions.loadSavedView(values.activeView.short_id)+ } else if (cache.latestViewShortId) {+ // A view link that has not loaded yet has no persisted selection behind it.+ // Drop the response, or it puts the view back after the user leaves the link.+ actions.applyUrlFilters(urlParamsToFilters(searchParams))+ }+ return+ }if (- leavingSavedView ||- (hasFilterParams(searchParams) && !urlFiltersMatchState(searchParams, values.currentFilters))+ values.activeView ||+ cache.latestViewShortId ||+ !urlFiltersMatchState(searchParams, values.currentFilters)) {actions.applyUrlFilters(urlParamsToFilters(searchParams))}@@ -1018,6 +1032,9 @@ export const supportTicketsSceneLogic = kea<supportTicketsSceneLogicType>([const embedded = !!props.distinctIds?.lengthconst { searchParams } = router.valuesif (!embedded && searchParams.view) {+ // The table has no rows until this request finishes. Mark it loading first,+ // or the empty state flashes.+ actions.setTicketsLoading(true)actions.loadSavedView(String(searchParams.view))return}@@ -1028,6 +1045,12 @@ export const supportTicketsSceneLogic = kea<supportTicketsSceneLogicType>([actions.applyUrlFilters(urlParamsToFilters(searchParams))return}+ } else if (values.activeView) {+ // Writing these filters into the query string looks like an explicit filter+ // link and detaches the view. Keep the empty table loading until the view loads.+ actions.setTicketsLoading(true)+ actions.loadSavedView(values.activeView.short_id)+ return} else {// No filters in the URL — reflect the persisted selection so the page is shareable on open.const currentFilterParams = filtersToUrlParams(values.currentFilters)