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(inbox): share filters via URL params (#70699)

Andrew Maguire86858fa5901b
diff --git a/frontend/src/scenes/inbox/filterOptions.tsx b/frontend/src/scenes/inbox/filterOptions.tsx
index 2fe104f79116..3f7cd3c439a9 100644
--- a/frontend/src/scenes/inbox/filterOptions.tsx
+++ b/frontend/src/scenes/inbox/filterOptions.tsx
@@ -17,7 +17,7 @@ import {
} from '@posthog/icons'
import { LemonTagType } from '@posthog/lemon-ui'
-import { InboxSortDirection, InboxSortField } from './logics/inboxFiltersLogic'
+import type { InboxSortDirection, InboxSortField } from './logics/inboxFiltersLogic'
import { SignalReportPriority } from './types'
/**
diff --git a/frontend/src/scenes/inbox/inboxSceneLogic.ts b/frontend/src/scenes/inbox/inboxSceneLogic.ts
index 4fc7dcf7aa81..e2e3d198a078 100644
--- a/frontend/src/scenes/inbox/inboxSceneLogic.ts
+++ b/frontend/src/scenes/inbox/inboxSceneLogic.ts
@@ -21,6 +21,7 @@ import {
InboxReportOpenMethod,
} from './inboxAnalytics'
import type { inboxSceneLogicType } from './inboxSceneLogicType'
+import { inboxFiltersLogic } from './logics/inboxFiltersLogic'
import { INBOX_FLAT_TAB_LIST_PARAMS, reportListLogic } from './logics/reportListLogic'
import { scratchpadLogic } from './logics/scratchpadLogic'
import { signalSourcesLogic } from './signalSourcesLogic'
@@ -187,6 +188,9 @@ export const inboxSceneLogic = kea<inboxSceneLogicType>([
path(['scenes', 'inbox', 'inboxSceneLogic']),
connect(() => ({
+ // Mount inboxFiltersLogic with the scene so its URL sync (shareable filter params) applies on
+ // deep-link load, before the filter bar / list have rendered.
+ logic: [inboxFiltersLogic],
values: [signalSourcesLogic, ['isSessionAnalysisRunning'], userLogic, ['user']],
actions: [signalSourcesLogic, ['loadSourceConfigs']],
})),
diff --git a/frontend/src/scenes/inbox/logics/inboxFiltersLogic.test.ts b/frontend/src/scenes/inbox/logics/inboxFiltersLogic.test.ts
index 32ea6d38e432..b54b78a250e6 100644
--- a/frontend/src/scenes/inbox/logics/inboxFiltersLogic.test.ts
+++ b/frontend/src/scenes/inbox/logics/inboxFiltersLogic.test.ts
@@ -1,20 +1,91 @@
-import { buildSignalReportListOrdering } from './inboxFiltersLogic'
+import {
+ buildSignalReportListOrdering,
+ filterSearchParams,
+ InboxFilterState,
+ parseFilterSearchParams,
+} from './inboxFiltersLogic'
-describe('buildSignalReportListOrdering', () => {
- it('leads with the selected time field so "Newest first" surfaces the newest reports', () => {
- // The list is flat, so created_at must be the primary key — not a sub-sort within status buckets.
- expect(buildSignalReportListOrdering('created_at', 'desc')).toBe('-created_at,status,-updated_at')
- })
+const DEFAULT_STATE: InboxFilterState = {
+ scope: 'for-you',
+ sourceProductFilter: [],
+ priorityFilter: [],
+ sortField: 'priority',
+ sortDirection: 'asc',
+ searchQuery: '',
+}
- it('leads with created_at ascending for "Oldest first"', () => {
- expect(buildSignalReportListOrdering('created_at', 'asc')).toBe('created_at,status,-updated_at')
- })
+describe('inboxFiltersLogic', () => {
+ describe('buildSignalReportListOrdering', () => {
+ it('leads with the selected time field so "Newest first" surfaces the newest reports', () => {
+ // The list is flat, so created_at must be the primary key — not a sub-sort within status buckets.
+ expect(buildSignalReportListOrdering('created_at', 'desc')).toBe('-created_at,status,-updated_at')
+ })
+
+ it('leads with created_at ascending for "Oldest first"', () => {
+ expect(buildSignalReportListOrdering('created_at', 'asc')).toBe('created_at,status,-updated_at')
+ })
- it('leads with updated_at and drops the redundant tiebreak for "Last updated first"', () => {
- expect(buildSignalReportListOrdering('updated_at', 'desc')).toBe('-updated_at,status')
+ it('leads with updated_at and drops the redundant tiebreak for "Last updated first"', () => {
+ expect(buildSignalReportListOrdering('updated_at', 'desc')).toBe('-updated_at,status')
+ })
+
+ it('leads with priority for "Priority first"', () => {
+ expect(buildSignalReportListOrdering('priority', 'asc')).toBe('priority,status,-updated_at')
+ })
})
- it('leads with priority for "Priority first"', () => {
- expect(buildSignalReportListOrdering('priority', 'asc')).toBe('priority,status,-updated_at')
+ describe('filter URL params', () => {
+ // Keeps shared links clean: a default view must not carry any filter params.
+ it('omits all default filters from the URL', () => {
+ expect(filterSearchParams(DEFAULT_STATE)).toEqual({})
+ })
+
+ it.each<[string, InboxFilterState, Record<string, string>]>([
+ [
+ 'scope + sources + priorities + custom sort + search',
+ {
+ scope: 'entire-project',
+ sourceProductFilter: ['error_tracking', 'github'],
+ priorityFilter: ['P0', 'P2'],
+ sortField: 'created_at',
+ sortDirection: 'desc',
+ searchQuery: 'checkout crash',
+ },
+ {
+ scope: 'entire-project',
+ source: 'error_tracking,github',
+ priority: 'P0,P2',
+ sort: 'created_at:desc',
+ search: 'checkout crash',
+ },
+ ],
+ [
+ 'teammate scope only',
+ { ...DEFAULT_STATE, scope: 'teammate:0199ed4a-5c03-0000-3220-df21df612e95' },
+ { scope: 'teammate:0199ed4a-5c03-0000-3220-df21df612e95' },
+ ],
+ ])('round-trips %s through encode/decode', (_name, state, expectedParams) => {
+ expect(filterSearchParams(state)).toEqual(expectedParams)
+ expect(parseFilterSearchParams(expectedParams)).toEqual(state)
+ })
+
+ // A shared link is authoritative but untrusted: unknown values (a malformed teammate id, which would
+ // otherwise reach the report-list API as a bad reviewer UUID, and a syntactically valid but
+ // unsupported sort combination the Sort control can't display) must not leak into filter state.
+ it('drops unknown sources, priorities, malformed teammate scope and unsupported sort', () => {
+ expect(
+ parseFilterSearchParams({
+ scope: 'teammate:not-a-uuid',
+ source: 'error_tracking,bogus_source',
+ priority: 'P9,P1',
+ // priority:desc has a valid field and direction but is not one of the offered sort options.
+ sort: 'priority:desc',
+ })
+ ).toEqual({
+ ...DEFAULT_STATE,
+ sourceProductFilter: ['error_tracking'],
+ priorityFilter: ['P1'],
+ })
+ })
})
})
diff --git a/frontend/src/scenes/inbox/logics/inboxFiltersLogic.ts b/frontend/src/scenes/inbox/logics/inboxFiltersLogic.ts
index 498d560a21ad..028a90f8b41d 100644
--- a/frontend/src/scenes/inbox/logics/inboxFiltersLogic.ts
+++ b/frontend/src/scenes/inbox/logics/inboxFiltersLogic.ts
@@ -1,8 +1,12 @@
import { actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
+import { actionToUrl, router, urlToAction } from 'kea-router'
import api from 'lib/api'
+import { isUUIDLike } from 'lib/utils/guards'
+import { urls } from 'scenes/urls'
+import { INBOX_PRIORITY_OPTIONS, INBOX_SORT_OPTIONS, INBOX_SOURCE_OPTIONS } from '../filterOptions'
import { INBOX_SCOPE_FOR_YOU, InboxScope, SignalReportPriority } from '../types'
import type { inboxFiltersLogicType } from './inboxFiltersLogicType'
@@ -16,6 +20,106 @@ export interface InboxReviewerOption {
export type InboxSortField = 'priority' | 'created_at' | 'updated_at'
export type InboxSortDirection = 'asc' | 'desc'
+const DEFAULT_SORT_FIELD: InboxSortField = 'priority'
+const DEFAULT_SORT_DIRECTION: InboxSortDirection = 'asc'
+
+// Query-param keys that mirror the filter state so a view can be shared via URL.
+const FILTER_URL_KEYS = ['scope', 'source', 'priority', 'sort', 'search'] as const
+
+const VALID_SOURCE_VALUES = new Set(INBOX_SOURCE_OPTIONS.map((o) => o.value))
+const VALID_PRIORITIES = new Set<string>(INBOX_PRIORITY_OPTIONS)
+// Only the field/direction combinations the Sort control actually offers — validating the field and
+// direction independently would accept keys like `priority:desc` that have no matching UI option.
+const VALID_SORT_KEYS = new Set(INBOX_SORT_OPTIONS.map((o) => `${o.field}:${o.direction}`))
+
+export interface InboxFilterState {
+ scope: InboxScope
+ sourceProductFilter: string[]
+ priorityFilter: SignalReportPriority[]
+ sortField: InboxSortField
+ sortDirection: InboxSortDirection
+ searchQuery: string
+}
+
+function parseScopeParam(raw: unknown): InboxScope {
+ if (typeof raw === 'string') {
+ if (raw === 'entire-project') {
+ return raw
+ }
+ // Validate the teammate id so a malformed shared link falls back to the default scope
+ // instead of forwarding junk to the report-list API as a reviewer UUID.
+ if (raw.startsWith('teammate:') && isUUIDLike(raw.slice('teammate:'.length))) {
+ return raw as InboxScope
+ }
+ }
+ return INBOX_SCOPE_FOR_YOU
+}
+
+function parseListParam(raw: unknown, valid: Set<string>): string[] {
+ if (typeof raw !== 'string' || raw.length === 0) {
+ return []
+ }
+ return raw.split(',').filter((v) => valid.has(v))
+}
+
+/** Decode the filter query params into filter state, ignoring unknown/invalid values and falling back to defaults. */
+export function parseFilterSearchParams(searchParams: Record<string, any>): InboxFilterState {
+ let sortField = DEFAULT_SORT_FIELD
+ let sortDirection = DEFAULT_SORT_DIRECTION
+ if (typeof searchParams.sort === 'string' && VALID_SORT_KEYS.has(searchParams.sort)) {
+ const [field, direction] = searchParams.sort.split(':')
+ sortField = field as InboxSortField
+ sortDirection = direction as InboxSortDirection
+ }
+ return {
+ scope: parseScopeParam(searchParams.scope),
+ sourceProductFilter: parseListParam(searchParams.source, VALID_SOURCE_VALUES),
+ priorityFilter: parseListParam(searchParams.priority, VALID_PRIORITIES) as SignalReportPriority[],
+ sortField,
+ sortDirection,
+ searchQuery: typeof searchParams.search === 'string' ? searchParams.search : '',
+ }
+}
+
+function sameSet(a: string[], b: string[]): boolean {
+ return a.length === b.length && [...a].sort().join(',') === [...b].sort().join(',')
+}
+
+/** Build the query params that mirror the current (non-default) filter state. Defaults are omitted so a shared URL stays clean. */
+export function filterSearchParams(values: InboxFilterState): Record<string, string> {
+ const params: Record<string, string> = {}
+ if (values.scope !== INBOX_SCOPE_FOR_YOU) {
+ params.scope = values.scope
+ }
+ if (values.sourceProductFilter.length > 0) {
+ params.source = values.sourceProductFilter.join(',')
+ }
+ if (values.priorityFilter.length > 0) {
+ params.priority = values.priorityFilter.join(',')
+ }
+ if (values.sortField !== DEFAULT_SORT_FIELD || values.sortDirection !== DEFAULT_SORT_DIRECTION) {
+ params.sort = `${values.sortField}:${values.sortDirection}`
+ }
+ if (values.searchQuery.trim().length > 0) {
+ params.search = values.searchQuery
+ }
+ return params
+}
+
+/**
+ * Build the state-mirroring inbox URL for the current pathname: keep any non-filter query params,
+ * drop stale filter keys, then write the current non-default filter state back on. `replace: true`
+ * keeps filter toggles out of the browser history.
+ */
+function currentUrlWithFilters(values: InboxFilterState): [string, Record<string, any>, any, { replace: boolean }] {
+ const searchParams = { ...router.values.searchParams }
+ for (const key of FILTER_URL_KEYS) {
+ delete searchParams[key]
+ }
+ Object.assign(searchParams, filterSearchParams(values))
+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]
+}
+
/**
* Build the `ordering` query param. The list is a flat list (no status section
* headers), so the toolbar-selected field must lead — otherwise an explicit sort
@@ -45,6 +149,11 @@ export function buildSignalReportListOrdering(field: InboxSortField, direction:
* `sourceProductFilter`, `priorityFilter` (all persisted). `searchQuery` is NOT
* persisted on desktop, so it isn't here either.
*
+ * Filter state (scope, source, priority, sort) is also mirrored to the URL query
+ * string so a specific view can be shared via a link. The URL is authoritative on
+ * load whenever any filter param is present; a bare `/inbox` falls back to the
+ * persisted state (and is then reflected back into the URL so it stays shareable).
+ *
* The central `inboxSceneLogic` connects these values, maps them to list-API
* params (`source_product`, `priority`, `ordering`), and reloads on change.
*/
@@ -60,6 +169,9 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
setSort: (field: InboxSortField, direction: InboxSortDirection) => ({ field, direction }),
toggleSourceProduct: (source: string) => ({ source }),
togglePriority: (priority: SignalReportPriority) => ({ priority }),
+ // Atomically apply a full filter set. Used when hydrating from a shared URL so the whole view
+ // is restored in one action — one list refresh, no fan-out race between partial states.
+ setFilters: (filters: InboxFilterState) => ({ filters }),
clearFilters: true,
// Debounced server-side org-member search for the scope (teammate) picker.
searchAvailableReviewers: (query: string) => ({ query }),
@@ -93,37 +205,44 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
{
setScope: (_, { scope }) => scope,
applyDefaultScope: (_, { scope }) => scope,
+ setFilters: (_, { filters }) => filters.scope,
},
],
// Whether the user has explicitly picked a scope. Once true, the empty-inbox auto-default
// no longer fires, so a deliberate choice of "For you" is respected even with zero reports.
+ // A shared link is an explicit choice too, so hydrating from the URL sets it.
hasUserChosenScope: [
false,
{ persist: true },
{
setScope: () => true,
+ setFilters: () => true,
},
],
- // Not persisted – matches desktop (searchQuery is excluded from `partialize`).
+ // Not persisted – matches desktop (searchQuery is excluded from `partialize`). It is mirrored to
+ // the URL though, so a shared link reproduces the search too and hydration can reset it.
searchQuery: [
'',
{
setSearchQuery: (_, { searchQuery }) => searchQuery,
+ setFilters: (_, { filters }) => filters.searchQuery,
clearFilters: () => '',
},
],
sortField: [
- 'priority' as InboxSortField,
+ DEFAULT_SORT_FIELD as InboxSortField,
{ persist: true },
{
setSort: (_, { field }) => field,
+ setFilters: (_, { filters }) => filters.sortField,
},
],
sortDirection: [
- 'asc' as InboxSortDirection,
+ DEFAULT_SORT_DIRECTION as InboxSortDirection,
{ persist: true },
{
setSort: (_, { direction }) => direction,
+ setFilters: (_, { filters }) => filters.sortDirection,
},
],
sourceProductFilter: [
@@ -132,6 +251,7 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
{
toggleSourceProduct: (state, { source }) =>
state.includes(source) ? state.filter((s) => s !== source) : [...state, source],
+ setFilters: (_, { filters }) => filters.sourceProductFilter,
clearFilters: () => [],
},
],
@@ -141,6 +261,7 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
{
togglePriority: (state, { priority }) =>
state.includes(priority) ? state.filter((p) => p !== priority) : [...state, priority],
+ setFilters: (_, { filters }) => filters.priorityFilter,
clearFilters: () => [],
},
],
@@ -156,6 +277,66 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
],
}),
+ actionToUrl(({ values }) => {
+ // Every filter mutation rewrites the current URL from the full (non-default) filter state.
+ const toUrl = (): [string, Record<string, any>, any, { replace: boolean }] => currentUrlWithFilters(values)
+ // `setFilters` is intentionally absent: it only fires while hydrating from the URL, which is
+ // already the source of truth in that path, so re-deriving the URL from it would be redundant.
+ return {
+ setScope: toUrl,
+ applyDefaultScope: toUrl,
+ setSort: toUrl,
+ toggleSourceProduct: toUrl,
+ togglePriority: toUrl,
+ setSearchQuery: toUrl,
+ clearFilters: toUrl,
+ }
+ }),
+
+ urlToAction(({ actions, values }) => {
+ const applyFromUrl = (_: unknown, searchParams: Record<string, any>): void => {
+ const hasFilterParams = FILTER_URL_KEYS.some((key) => key in searchParams)
+ if (!hasFilterParams) {
+ // Bare inbox URL: keep the persisted state, but reflect any non-default filters back
+ // into the URL so the current view is immediately shareable.
+ const desired = filterSearchParams(values)
+ if (Object.keys(desired).length > 0) {
+ router.actions.replace(
+ router.values.location.pathname,
+ { ...router.values.searchParams, ...desired },
+ router.values.hashParams
+ )
+ }
+ return
+ }
+
+ // A shared link is authoritative: apply the params it carries and reset the rest to defaults.
+ // Only dispatch when something actually changed — urlToAction also fires on plain navigation
+ // (opening a report, switching tabs), and we don't want a redundant list refresh each time.
+ const parsed = parseFilterSearchParams(searchParams)
+ const changed =
+ values.scope !== parsed.scope ||
+ !sameSet(values.sourceProductFilter, parsed.sourceProductFilter) ||
+ !sameSet(values.priorityFilter, parsed.priorityFilter) ||
+ values.sortField !== parsed.sortField ||
+ values.sortDirection !== parsed.sortDirection ||
+ values.searchQuery !== parsed.searchQuery
+ if (changed) {
+ actions.setFilters(parsed)
+ }
+ }
+
+ return {
+ [urls.inbox()]: applyFromUrl,
+ [urls.inbox(':tab')]: applyFromUrl,
+ [urls.inboxScratchpad()]: applyFromUrl,
+ [urls.inboxFindings()]: applyFromUrl,
+ [urls.inboxScout(':skillName')]: applyFromUrl,
+ [urls.inboxScout(':skillName', ':findingId')]: applyFromUrl,
+ [urls.inboxReport(':tab', ':reportId')]: applyFromUrl,
+ }
+ }),
+
afterMount(({ actions }) => {
actions.loadAvailableReviewers()
}),
diff --git a/frontend/src/scenes/inbox/logics/reportListLogic.ts b/frontend/src/scenes/inbox/logics/reportListLogic.ts
index 6f048be25b2d..7ffcc7dd8f88 100644
--- a/frontend/src/scenes/inbox/logics/reportListLogic.ts
+++ b/frontend/src/scenes/inbox/logics/reportListLogic.ts
@@ -113,6 +113,7 @@ export const reportListLogic = kea<reportListLogicType>([
'togglePriority',
'setScope',
'applyDefaultScope',
+ 'setFilters',
'clearFilters',
],
],
@@ -257,6 +258,7 @@ export const reportListLogic = kea<reportListLogicType>([
togglePriority: () => actions.refresh(),
setScope: () => actions.refresh(),
applyDefaultScope: () => actions.refresh(),
+ setFilters: () => actions.refresh(),
clearFilters: () => actions.refresh(),
// For-you scope needs the current user's uuid; reload once it resolves.
[userLogic.actionTypes.loadUserSuccess]: () => {