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 ticket sort when a saved view is active (#73104)

Christian Rafferty489fcae91602
diff --git a/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.ts b/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.ts
index 73cd2de2661b..e9f29ad903e0 100644
--- a/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.ts
+++ b/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.test.ts
@@ -201,6 +201,38 @@ describe('supportTicketsSceneLogic', () => {
expect(router.values.searchParams.view).toBeUndefined()
})
+ it('keeps a new sort order applied when sorting while a saved view is active', async () => {
+ let lastOrderBy: string | null = null
+ useMocks({
+ get: {
+ '/api/projects/:team_id/conversations/tickets/': ({ request }) => {
+ lastOrderBy = new URL(request.url).searchParams.get('order_by')
+ return [200, { count: 0, results: [] }]
+ },
+ '/api/projects/:team_id/conversations/views/:short_id/': () => [
+ 200,
+ makeSavedView('view-a', { status: ['open'] }),
+ ],
+ },
+ })
+ router.actions.push(urls.supportTickets(), { view: 'view-a' })
+ logic = supportTicketsSceneLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.activeView?.short_id).toBe('view-a')
+
+ await expectLogic(logic, () => {
+ logic.actions.setSorting({ columnKey: 'sla_due_at', order: -1 })
+ }).toFinishAllListeners()
+
+ // Sorting detaches the view but the sort and the view's filters must stick, and the
+ // new order has to reach the API instead of snapping back to the default sort.
+ expect(logic.values.activeView).toBeNull()
+ expect(logic.values.sorting).toEqual({ columnKey: 'sla_due_at', order: -1 })
+ expect(logic.values.statusFilter).toEqual(['open'])
+ expect(lastOrderBy).toBe('-sla_due_at')
+ })
+
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.ts
index 6146fd576da6..898bebc8b3dc 100644
--- a/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.ts
+++ b/products/conversations/frontend/scenes/tickets/supportTicketsSceneLogic.ts
@@ -731,6 +731,11 @@ export const supportTicketsSceneLogic = kea<supportTicketsSceneLogicType>([
applyViewFilters: () => {
actions.setCurrentPage(1)
},
+ clearActiveView: () => {
+ // Once detached there's no view to fall back to, so a later param-less
+ // navigation shouldn't be treated as "leaving a saved view" and reset filters.
+ cache.latestViewShortId = null
+ },
applyUrlFilters: ({ filters }) => {
cache.applyingUrlFilters = true
cache.latestViewShortId = null
@@ -886,6 +891,12 @@ export const supportTicketsSceneLogic = kea<supportTicketsSceneLogicType>([
} else {
Object.assign(searchParams, filtersToUrlParams(values.currentFilters))
}
+ // Only URL changes we didn't originate should re-apply filters. Flag our own
+ // writes so urlToAction skips them; re-applying a URL we just wrote resets any
+ // state absent from it — e.g. the sort order while detaching a saved view.
+ if (!objectsEqual(searchParams, router.values.searchParams)) {
+ cache.selfNavigating = true
+ }
return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]
}
return {
@@ -911,6 +922,12 @@ export const supportTicketsSceneLogic = kea<supportTicketsSceneLogicType>([
if (props.distinctIds?.length) {
return
}
+ // A URL change we wrote ourselves already matches state — re-applying it would
+ // clobber filters not encoded in the URL. External navigations don't set this.
+ if (cache.selfNavigating) {
+ cache.selfNavigating = false
+ return
+ }
if (searchParams.search !== undefined) {
const sanitizedSearchParams = { ...searchParams }
delete sanitizedSearchParams.search