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): restore filtering by source and individual scout (#125178)

posthog[bot]43497eaa9802
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index a965e912f4e2..2ed450eeb619 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -358,6 +358,7 @@ export const FEATURE_FLAGS = {
INBOX_MCP_USED: 'inbox-mcp-used', // owner: #team-self-driving, hides the MCP banner after confirmed Inbox tool use
INBOX_MODEL_SORT: 'inbox-model-sort', // owner: #team-self-driving, gates the ranking model sort options and the score tag on inbox cards
INBOX_REPORT_FEEDBACK_BANG: 'inbox-report-feedback-bang', // owner: #team-self-driving, gates the party hog that pops on a report thumbs-up in the inbox and on the Today home page
+ INBOX_SOURCE_FILTER: 'inbox-source-filter', // owner: #team-self-driving, gates the Source filter on the inbox report list
INBOX_SLACK_NOTIFICATIONS: 'inbox-slack-notifications', // owner: #team-self-driving, gates the Slack notifications config card in the inbox
INBOX_TIME_WINDOW: 'inbox-time-window', // owner: #team-self-driving, gates the created-in window filter on the inbox report list
INSIGHT_ALERTS_EMPTY_STATE_EXPERIMENT: 'insight-alerts-empty-state',
diff --git a/products/signals/frontend/inbox/components/shell/InboxReportFilters.tsx b/products/signals/frontend/inbox/components/shell/InboxReportFilters.tsx
index 20501734e6b9..774ba6d4bfa6 100644
--- a/products/signals/frontend/inbox/components/shell/InboxReportFilters.tsx
+++ b/products/signals/frontend/inbox/components/shell/InboxReportFilters.tsx
@@ -15,6 +15,7 @@ import {
} from '../../filterOptions'
import { InboxCreatedWindow, inboxFiltersLogic } from '../../logics/inboxFiltersLogic'
import { SignalReportPriority } from '../../types'
+import { InboxSourceFilter } from './InboxSourceFilter'
import { InboxStateFilter } from './InboxStateFilter'
const ALL_PRIORITIES = null
@@ -55,7 +56,7 @@ const CREATED_WINDOW_SELECT_OPTIONS: { value: InboxCreatedWindow | null; label:
]
/**
- * What narrows the report list: priority, then report state, then sort order, then the created-in window. Filter state is
+ * What narrows the report list: priority, then source, then report state, then sort order, then the created-in window. Filter state is
* persisted via `inboxFiltersLogic`, and the list reloads on change.
*
* Reviewer scope is deliberately not here. It sits with triage mode on the other side of the row,
@@ -69,6 +70,7 @@ export function InboxReportFilters(): JSX.Element {
modelSortAvailable,
timeWindowAvailable,
createdWindow,
+ sourceFilterAvailable,
} = useValues(inboxFiltersLogic)
const { setSort, setPriorityFilter, setCreatedWindow } = useActions(inboxFiltersLogic)
const sortOptions = modelSortAvailable ? ALL_SORT_OPTIONS : INBOX_SORT_OPTIONS
@@ -85,6 +87,7 @@ export function InboxReportFilters(): JSX.Element {
renderButtonContent={() => inboxPriorityFilterLabel(priorityFilter)}
data-attr="inbox-filter-priority"
/>
+ {sourceFilterAvailable && <InboxSourceFilter />}
<InboxStateFilter />
<LemonSelect
size="small"
diff --git a/products/signals/frontend/inbox/components/shell/InboxSourceFilter.tsx b/products/signals/frontend/inbox/components/shell/InboxSourceFilter.tsx
new file mode 100644
index 000000000000..d15b06a2fc1e
--- /dev/null
+++ b/products/signals/frontend/inbox/components/shell/InboxSourceFilter.tsx
@@ -0,0 +1,196 @@
+import { useActions, useValues } from 'kea'
+import { useState } from 'react'
+
+import { IconX } from '@posthog/icons'
+import { LemonButton, LemonDropdown, LemonInput, Spinner } from '@posthog/lemon-ui'
+
+import { inboxSourceFilterLabel } from '../../filterOptions'
+import { InboxSourceSelection, inboxFiltersLogic } from '../../logics/inboxFiltersLogic'
+import { scoutFleetLogic } from '../../logics/scoutFleetLogic'
+import { signalSourcesLogic } from '../../signalSourcesLogic'
+import {
+ InboxSourceChoice,
+ buildInboxSourceChoices,
+ matchesInboxSourceSearch,
+ singleInboxSourceSelection,
+} from '../../utils/inboxSourceFilter'
+
+function sameSelection(a: InboxSourceSelection | null, b: InboxSourceSelection): boolean {
+ return !!a && a.kind === b.kind && a.value === b.value
+}
+
+function ChoiceSection({
+ title,
+ choices,
+ loading,
+ failed,
+ emptyText,
+ selection,
+ onRetry,
+ onSelect,
+}: {
+ title: string
+ choices: InboxSourceChoice[]
+ loading: boolean
+ failed: boolean
+ emptyText: string
+ selection: InboxSourceSelection | null
+ onRetry: () => void
+ onSelect: (choice: InboxSourceChoice) => void
+}): JSX.Element {
+ return (
+ <div role="group" aria-label={title}>
+ <div className="px-2 pt-2 pb-1 text-xs font-semibold text-secondary">{title}</div>
+ {choices.map((choice) => (
+ <LemonButton
+ key={`${choice.kind}:${choice.value}`}
+ size="small"
+ fullWidth
+ active={sameSelection(selection, choice)}
+ onClick={() => onSelect(choice)}
+ tooltip={choice.unavailable ? 'This is no longer configured on this project' : undefined}
+ data-attr={`inbox-filter-source-${choice.kind}`}
+ >
+ <span className="truncate">
+ {choice.label}
+ {choice.unavailable && <span className="text-muted"> · unavailable</span>}
+ </span>
+ </LemonButton>
+ ))}
+ {loading ? (
+ <div className="flex items-center gap-2 px-2 py-1 text-xs text-muted">
+ <Spinner /> Loading…
+ </div>
+ ) : failed ? (
+ <div className="flex items-center gap-2 px-2 py-1 text-xs text-muted">
+ Couldn't load this list.
+ <LemonButton size="xsmall" type="tertiary" onClick={onRetry}>
+ Try again
+ </LemonButton>
+ </div>
+ ) : choices.length === 0 ? (
+ <div className="px-2 py-1 text-xs text-muted">{emptyText}</div>
+ ) : null}
+ </div>
+ )
+}
+
+/**
+ * Single-select Source filter for the Reports list: one configured product, or one scout. The choices
+ * come from the source and scout configs, not from the loaded reports, so every page is reachable.
+ */
+export function InboxSourceFilter(): JSX.Element {
+ const { sourceProductFilter, scoutFilter } = useValues(inboxFiltersLogic)
+ const { setSourceFilter } = useActions(inboxFiltersLogic)
+ const { sourceConfigs, sourceConfigsLoading } = useValues(signalSourcesLogic)
+ const { loadSourceConfigs } = useActions(signalSourcesLogic)
+ const { scoutConfigs, scoutConfigsLoading } = useValues(scoutFleetLogic)
+ const { loadScoutConfigs } = useActions(scoutFleetLogic)
+ const [visible, setVisible] = useState(false)
+ const [search, setSearch] = useState('')
+
+ const { sources, scouts } = buildInboxSourceChoices({
+ sourceConfigs,
+ scoutConfigs,
+ sourceProductFilter,
+ scoutFilter,
+ })
+ const selection = singleInboxSourceSelection(sourceProductFilter, scoutFilter)
+ const hasSelection = sourceProductFilter.length > 0 || scoutFilter.length > 0
+ const selectedChoice = selection
+ ? [...sources, ...scouts].find((choice) => sameSelection(selection, choice))
+ : undefined
+ const label = !selectedChoice
+ ? inboxSourceFilterLabel(sourceProductFilter, scoutFilter)
+ : selectedChoice.kind === 'scout'
+ ? `Scout · ${selectedChoice.label}`
+ : selectedChoice.label
+
+ const onVisibilityChange = (nextVisible: boolean): void => {
+ setVisible(nextVisible)
+ setSearch('')
+ if (nextVisible && sourceConfigs === null && !sourceConfigsLoading) {
+ loadSourceConfigs()
+ }
+ }
+ const pick = (next: InboxSourceSelection | null): void => {
+ setSourceFilter(next)
+ onVisibilityChange(false)
+ }
+
+ return (
+ <LemonDropdown
+ closeOnClickInside={false}
+ visible={visible}
+ onVisibilityChange={onVisibilityChange}
+ matchWidth={false}
+ actionable
+ placement="bottom-start"
+ overlay={
+ <div className="flex w-72 max-w-[calc(100vw-2rem)] flex-col">
+ <LemonInput
+ type="search"
+ size="small"
+ placeholder="Search sources and scouts"
+ autoFocus
+ value={search}
+ onChange={setSearch}
+ fullWidth
+ aria-label="Search sources and scouts"
+ />
+ <div className="mt-1 max-h-80 overflow-y-auto">
+ <LemonButton
+ size="small"
+ fullWidth
+ active={!hasSelection}
+ onClick={() => pick(null)}
+ data-attr="inbox-filter-source-all"
+ >
+ All sources
+ </LemonButton>
+ <ChoiceSection
+ title="Sources"
+ choices={sources.filter((choice) => matchesInboxSourceSearch(choice, search))}
+ loading={sourceConfigs === null && sourceConfigsLoading}
+ failed={sourceConfigs === null && !sourceConfigsLoading}
+ emptyText={search ? 'No matching sources' : 'No sources configured'}
+ selection={selection}
+ onRetry={loadSourceConfigs}
+ onSelect={pick}
+ />
+ <ChoiceSection
+ title="Scouts"
+ choices={scouts.filter((choice) => matchesInboxSourceSearch(choice, search))}
+ loading={scoutConfigs === null && scoutConfigsLoading}
+ failed={scoutConfigs === null && !scoutConfigsLoading}
+ emptyText={search ? 'No matching scouts' : 'No scouts configured'}
+ selection={selection}
+ onRetry={loadScoutConfigs}
+ onSelect={pick}
+ />
+ </div>
+ </div>
+ }
+ >
+ <LemonButton
+ size="small"
+ type="secondary"
+ aria-label={`Source: ${label}`}
+ sideAction={
+ hasSelection
+ ? {
+ icon: <IconX />,
+ tooltip: 'Show all sources',
+ 'aria-label': 'Show all sources',
+ onClick: () => setSourceFilter(null),
+ 'data-attr': 'inbox-filter-source-clear',
+ }
+ : undefined
+ }
+ data-attr="inbox-filter-source"
+ >
+ <span className="max-w-[200px] truncate">{label}</span>
+ </LemonButton>
+ </LemonDropdown>
+ )
+}
diff --git a/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx b/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
index 204a784014f8..013591397c26 100644
--- a/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
+++ b/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
@@ -108,7 +108,7 @@ function useSectionStates(): Record<InboxReportSectionKey, SectionListState> {
* One event per visit, carrying the whole loaded list.
*/
function useInboxViewedEvent(sections: Record<CountedSectionKey, SectionListState>): void {
- const { hasActiveFilters, sourceProductFilter, priorityFilter, visibleStateFilter, scope } =
+ const { hasActiveFilters, activeSourceProductFilter, priorityFilter, visibleStateFilter, scope } =
useValues(inboxFiltersLogic)
// The list stays mounted (hidden) while a report/scout detail is open, so gate the view event on
// the list actually being the visible surface — otherwise a deep-link to a report fires a phantom
@@ -142,7 +142,7 @@ function useInboxViewedEvent(sections: Record<CountedSectionKey, SectionListStat
pullsTabCount: sections.monitoring.count,
reportsTabCount: sections['needs-decision'].count,
hasActiveFilters,
- sourceProductFilter,
+ sourceProductFilter: activeSourceProductFilter,
priorityFilter,
stateFilter: visibleStateFilter,
scope,
@@ -152,7 +152,7 @@ function useInboxViewedEvent(sections: Record<CountedSectionKey, SectionListStat
settled,
sections,
hasActiveFilters,
- sourceProductFilter,
+ activeSourceProductFilter,
priorityFilter,
visibleStateFilter,
scope,
diff --git a/products/signals/frontend/inbox/logics/inboxFiltersLogic.test.ts b/products/signals/frontend/inbox/logics/inboxFiltersLogic.test.ts
index c648a48ea4b1..55b485d50dd8 100644
--- a/products/signals/frontend/inbox/logics/inboxFiltersLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/inboxFiltersLogic.test.ts
@@ -124,7 +124,8 @@ describe('inboxFiltersLogic', () => {
expect(
parseFilterSearchParams({
scope: 'teammate:not-a-uuid',
- source: 'error_tracking,bogus_source',
+ // `logs` has no entry in the old toolbar list, but the Source filter can offer it.
+ source: 'error_tracking,logs,bogus_source',
priority: 'P9,P1',
state: 'monitoring,closed,bogus-state',
// priority:desc has a valid field and direction but is not one of the offered sort options.
@@ -132,7 +133,7 @@ describe('inboxFiltersLogic', () => {
})
).toEqual({
...DEFAULT_STATE,
- sourceProductFilter: ['error_tracking'],
+ sourceProductFilter: ['error_tracking', 'logs'],
priorityFilter: ['P1'],
stateFilter: ['monitoring'],
})
@@ -270,6 +271,60 @@ describe('inboxFiltersLogic', () => {
})
})
+ // The API combines `source_product` and `scout` as AND, so a leftover value from the other
+ // dimension would silently narrow the list to reports that match both.
+ it.each([
+ [{ kind: 'source_product', value: 'logs' }, ['logs'], [], 'logs', undefined],
+ [{ kind: 'scout', value: 'my-custom-scout' }, [], ['my-custom-scout'], undefined, 'my-custom-scout'],
+ [null, [], [], undefined, undefined],
+ ] as const)(
+ 'replaces the whole source selection with %p and keeps the other filters',
+ (selection, sourceProductFilter, scoutFilter, sourceParam, scoutParam) => {
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_SOURCE_FILTER], {
+ [FEATURE_FLAGS.INBOX_SOURCE_FILTER]: true,
+ })
+ logic.actions.setFilters({
+ ...DEFAULT_STATE,
+ sourceProductFilter: ['error_tracking', 'github'],
+ scoutFilter: ['signals-scout-error-tracking'],
+ priorityFilter: ['P1'],
+ searchQuery: 'checkout',
+ })
+
+ logic.actions.setSourceFilter(selection)
+
+ expect(logic.values).toMatchObject({
+ sourceProductFilter,
+ scoutFilter,
+ activeSourceProductFilter: sourceProductFilter,
+ activeScoutFilter: scoutFilter,
+ priorityFilter: ['P1'],
+ searchQuery: 'checkout',
+ })
+ expect(router.values.searchParams.source).toBe(sourceParam)
+ expect(router.values.searchParams.scout).toBe(scoutParam)
+ expect(router.values.searchParams.priority).toBe('P1')
+ }
+ )
+
+ it('ignores a stored source selection while the flag is off and reloads when the flag changes', async () => {
+ logic.actions.setFilters({ ...DEFAULT_STATE, scoutFilter: ['my-custom-scout'] })
+
+ expect(logic.values).toMatchObject({
+ scoutFilter: ['my-custom-scout'],
+ activeScoutFilter: [],
+ hasActiveFilters: false,
+ })
+
+ await expectLogic(logic, () => {
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_SOURCE_FILTER], {
+ [FEATURE_FLAGS.INBOX_SOURCE_FILTER]: true,
+ })
+ })
+ .toDispatchActions(['sourceFilterAvailabilityChanged'])
+ .toMatchValues({ activeScoutFilter: ['my-custom-scout'], hasActiveFilters: true })
+ })
+
it.each([
[
'keeps a stored model sort for staff with the flag',
diff --git a/products/signals/frontend/inbox/logics/inboxFiltersLogic.ts b/products/signals/frontend/inbox/logics/inboxFiltersLogic.ts
index 92caebbf50f2..02724fb8493c 100644
--- a/products/signals/frontend/inbox/logics/inboxFiltersLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxFiltersLogic.ts
@@ -31,6 +31,7 @@ import {
InboxReportSectionKey,
InboxScope,
SignalReportPriority,
+ SignalSourceProduct,
} from '../types'
/** A teammate who can be scoped to / suggested as a reviewer. Matches the `available_reviewers` API row. */
@@ -46,6 +47,16 @@ export type InboxSortDirection = 'asc' | 'desc'
/** Preset for the created-in window filter. Null means any time. */
export type InboxCreatedWindow = '24h' | '3d' | '7d' | '14d'
+/**
+ * One choice in the Source filter. The API combines `source_product` and `scout` as AND, so one
+ * choice sets one of the two and clears the other.
+ */
+export interface InboxSourceSelection {
+ kind: 'source_product' | 'scout'
+ /** The raw `source_product` value, or the exact scout `skill_name`. */
+ value: string
+}
+
/** The window a model sort picks when none is set: the ranking sweep only scores reports from the last 7 days. */
const MODEL_SORT_DEFAULT_WINDOW: InboxCreatedWindow = '7d'
@@ -78,7 +89,12 @@ export function isDefaultStateFilter(stateFilter: InboxReportSectionKey[]): bool
// Query-param keys that mirror the filter state so a view can be shared via URL.
const FILTER_URL_KEYS = ['scope', 'source', 'scout', 'priority', 'state', 'sort', 'search', 'created'] as const
-const VALID_SOURCE_VALUES = new Set(INBOX_SOURCE_OPTIONS.map((o) => o.value))
+// Every product the backend knows, because the Source filter offers each configured product and not
+// only the products with a toolbar entry.
+const VALID_SOURCE_VALUES = new Set<string>([
+ ...Object.values(SignalSourceProduct),
+ ...INBOX_SOURCE_OPTIONS.map((o) => o.value),
+])
const VALID_PRIORITIES = new Set<string>(INBOX_PRIORITY_OPTIONS)
const VALID_STATE_VALUES = new Set<string>(INBOX_REPORT_SECTION_KEYS)
// Only the field/direction combinations the Sort control actually offers — validating the field and
@@ -300,8 +316,10 @@ export interface inboxFiltersLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
user: UserType | null // userLogic
activeCreatedWindow: InboxCreatedWindow | null
+ activeScoutFilter: string[]
activeSortDirection: InboxSortDirection
activeSortField: InboxSortField
+ activeSourceProductFilter: string[]
availableReviewers: InboxReviewerOption[]
availableReviewersLoading: boolean
createdWindow: InboxCreatedWindow | null
@@ -320,6 +338,7 @@ export interface inboxFiltersLogicValues {
searchQuery: string
sortDirection: InboxSortDirection
sortField: InboxSortField
+ sourceFilterAvailable: boolean
sourceProductFilter: string[]
stateFilter: ('dismissed' | 'held-back' | 'monitoring' | 'needs-decision' | 'not-actionable' | 'resolved')[]
timeWindowAvailable: boolean
@@ -407,6 +426,12 @@ export interface inboxFiltersLogicActions {
direction: InboxSortDirection
field: InboxSortField
}
+ setSourceFilter: (selection: InboxSourceSelection | null) => {
+ selection: InboxSourceSelection | null
+ }
+ sourceFilterAvailabilityChanged: () => {
+ value: true
+ }
togglePriority: (priority: SignalReportPriority) => {
priority: SignalReportPriority
}
@@ -426,8 +451,8 @@ export interface inboxFiltersLogicMeta {
__keaTypeGenInternalSelectorTypes: {
hasActiveFilters: (
searchQuery: string,
- sourceProductFilter: string[],
- scoutFilter: string[],
+ activeSourceProductFilter: string[],
+ activeScoutFilter: string[],
priorityFilter: SignalReportPriority[],
activeCreatedWindow: InboxCreatedWindow | null
) => boolean
@@ -448,6 +473,9 @@ export interface inboxFiltersLogicMeta {
createdWindow: InboxCreatedWindow | null,
timeWindowAvailable: boolean
) => InboxCreatedWindow | null
+ sourceFilterAvailable: (featureFlags: FeatureFlagsSet) => boolean
+ activeSourceProductFilter: (sourceProductFilter: string[], sourceFilterAvailable: boolean) => string[]
+ activeScoutFilter: (scoutFilter: string[], sourceFilterAvailable: boolean) => string[]
visibleStateFilter: (
stateFilter: (
| 'dismissed'
@@ -510,6 +538,11 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
toggleSourceProduct: (source: string) => ({ source }),
toggleScout: (scout: string) => ({ scout }),
clearScoutFilter: true,
+ // Replace the source and scout selection in one step. Null clears both.
+ setSourceFilter: (selection: InboxSourceSelection | null) => ({ selection }),
+ // Fires when the Source filter flag changes while a stored selection exists, so the lists
+ // reload with or without that selection.
+ sourceFilterAvailabilityChanged: true,
togglePriority: (priority: SignalReportPriority) => ({ priority }),
// The report states (Needs decision, Review and merge, …) shown in the flat Reports list.
// Multi-select: the open-work states are selected by default (DEFAULT_STATE_FILTER), and an
@@ -553,8 +586,8 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
scope: values.scope,
sortField: values.activeSortField,
sortDirection: values.activeSortDirection,
- sourceProductFilter: values.sourceProductFilter,
- scoutFilter: values.scoutFilter,
+ sourceProductFilter: values.activeSourceProductFilter,
+ scoutFilter: values.activeScoutFilter,
priorityFilter: values.priorityFilter,
stateFilter: values.stateFilter,
searchQuery: values.searchQuery,
@@ -592,6 +625,8 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
toggleSourceProduct: () => captureQueryChange('source_product'),
toggleScout: () => captureQueryChange('scout'),
clearScoutFilter: () => captureQueryChange('scout'),
+ setSourceFilter: ({ selection }) =>
+ captureQueryChange(selection?.kind === 'scout' ? 'scout' : 'source_product'),
togglePriority: () => captureQueryChange('priority'),
setPriorityFilter: () => captureQueryChange('priority'),
toggleState: () => captureQueryChange('state'),
@@ -691,6 +726,7 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
{
toggleSourceProduct: (state, { source }) =>
state.includes(source) ? state.filter((s) => s !== source) : [...state, source],
+ setSourceFilter: (_, { selection }) => (selection?.kind === 'source_product' ? [selection.value] : []),
setFilters: (_, { filters }) => filters.sourceProductFilter,
clearFilters: () => [],
},
@@ -704,6 +740,7 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
toggleScout: (state, { scout }) =>
state.includes(scout) ? state.filter((s) => s !== scout) : [...state, scout],
clearScoutFilter: () => [],
+ setSourceFilter: (_, { selection }) => (selection?.kind === 'scout' ? [selection.value] : []),
setFilters: (_, { filters }) => filters.scoutFilter,
clearFilters: () => [],
},
@@ -738,7 +775,13 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
// Reports list renders (client-side), so the surfaces that need it check
// `stateFilter` directly.
hasActiveFilters: [
- (s) => [s.searchQuery, s.sourceProductFilter, s.scoutFilter, s.priorityFilter, s.activeCreatedWindow],
+ (s) => [
+ s.searchQuery,
+ s.activeSourceProductFilter,
+ s.activeScoutFilter,
+ s.priorityFilter,
+ s.activeCreatedWindow,
+ ],
(
searchQuery: string,
sourceProductFilter: string[],
@@ -798,6 +841,23 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
(createdWindow: InboxCreatedWindow | null, timeWindowAvailable: boolean): InboxCreatedWindow | null =>
timeWindowAvailable ? createdWindow : null,
],
+ sourceFilterAvailable: [
+ (s) => [s.featureFlags],
+ (featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.INBOX_SOURCE_FILTER],
+ ],
+ // The source and scout selection the lists request with. Like the created window, a stored or
+ // shared selection does nothing while its flag is off, so it cannot narrow a list that has no
+ // control for it. The raw values stay stored and in the URL.
+ activeSourceProductFilter: [
+ (s) => [s.sourceProductFilter, s.sourceFilterAvailable],
+ (sourceProductFilter: string[], sourceFilterAvailable: boolean): string[] =>
+ sourceFilterAvailable ? sourceProductFilter : [],
+ ],
+ activeScoutFilter: [
+ (s) => [s.scoutFilter, s.sourceFilterAvailable],
+ (scoutFilter: string[], sourceFilterAvailable: boolean): string[] =>
+ sourceFilterAvailable ? scoutFilter : [],
+ ],
// The stored state filter can name states the current user cannot see: a staff-only state
// from a shared link, or one persisted before staff access changed. The list and the filter
// control read this narrowed view, so a hidden state can never strand the list on a
@@ -820,6 +880,12 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
actions.resetUnavailableSort()
}
},
+ sourceFilterAvailable: (available: boolean, wasAvailable: boolean | undefined) => {
+ const hasSelection = values.sourceProductFilter.length > 0 || values.scoutFilter.length > 0
+ if (wasAvailable !== undefined && available !== wasAvailable && hasSelection) {
+ actions.sourceFilterAvailabilityChanged()
+ }
+ },
})),
// Before `urlToAction`, so a shared link still wins over the migrated sort.
@@ -844,6 +910,7 @@ export const inboxFiltersLogic = kea<inboxFiltersLogicType>([
toggleSourceProduct: toUrl,
toggleScout: toUrl,
clearScoutFilter: toUrl,
+ setSourceFilter: toUrl,
togglePriority: toUrl,
setPriorityFilter: toUrl,
toggleState: toUrl,
diff --git a/products/signals/frontend/inbox/logics/reportListLogic.test.ts b/products/signals/frontend/inbox/logics/reportListLogic.test.ts
index 4294128f8591..3b7c645c9861 100644
--- a/products/signals/frontend/inbox/logics/reportListLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/reportListLogic.test.ts
@@ -20,6 +20,7 @@ import {
SignalReportStatus,
} from '../types'
import { inboxBulkActionsLogic } from './inboxBulkActionsLogic'
+import { inboxFiltersLogic } from './inboxFiltersLogic'
import { INBOX_REPORT_SECTION_LIST_PARAMS, reportListLogic, shouldDefaultToEntireProject } from './reportListLogic'
const REPORTS_URL = '/api/projects/:team_id/signals/reports/'
@@ -360,7 +361,7 @@ describe('reportListLogic', () => {
'/api/projects/:team_id/signals/reports/available_reviewers': {},
[REPORTS_URL]: async ({ request }) => {
const params = new URL(request.url).searchParams
- if (params.get('assignee') === 'mine') {
+ if (params.get('assignee') === 'mine' || params.get('scout') === 'my-custom-scout') {
return [200, { count: MINE.length, next: null, previous: null, results: MINE }]
}
if (params.get('offset') === heldOffset) {
@@ -390,17 +391,26 @@ describe('reportListLogic', () => {
afterEach(() => logic.unmount())
it.each([
- { request: 'first page', offset: '0' },
- { request: 'next page', offset: String(ALL.length) },
- ])('drops the late $request of the old query', async ({ offset }) => {
+ { request: 'first page', offset: '0', change: 'scope' },
+ { request: 'next page', offset: String(ALL.length), change: 'scope' },
+ { request: 'first page', offset: '0', change: 'source' },
+ { request: 'next page', offset: String(ALL.length), change: 'source' },
+ ])('drops the late $request of the old query after a $change change', async ({ offset, change }) => {
heldOffset = offset
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_SOURCE_FILTER], {
+ [FEATURE_FLAGS.INBOX_SOURCE_FILTER]: true,
+ })
logic.actions.ensureLoaded()
if (offset !== '0') {
await expectLogic(logic).toDispatchActions(['loadReportsSuccess'])
logic.actions.loadMore()
}
- logic.actions.setScope(INBOX_SCOPE_CLAIMED_BY_YOU)
+ if (change === 'scope') {
+ logic.actions.setScope(INBOX_SCOPE_CLAIMED_BY_YOU)
+ } else {
+ inboxFiltersLogic.actions.setSourceFilter({ kind: 'scout', value: 'my-custom-scout' })
+ }
await expectLogic(logic).toDispatchActions(['loadReportsSuccess'])
releaseOldQuery()
await expectLogic(logic).toFinishAllListeners()
diff --git a/products/signals/frontend/inbox/logics/reportListLogic.ts b/products/signals/frontend/inbox/logics/reportListLogic.ts
index 77f1e34aa4a6..6134344acd23 100644
--- a/products/signals/frontend/inbox/logics/reportListLogic.ts
+++ b/products/signals/frontend/inbox/logics/reportListLogic.ts
@@ -118,8 +118,8 @@ function teammateUuidFromScope(scope: string): string | undefined {
function requestContextFromValues(values: {
scope: InboxScope
searchQuery: string
- sourceProductFilter: string[]
- scoutFilter: string[]
+ activeSourceProductFilter: string[]
+ activeScoutFilter: string[]
priorityFilter: SignalReportPriority[]
activeSortField: InboxSortField
activeSortDirection: InboxSortDirection
@@ -129,8 +129,8 @@ function requestContextFromValues(values: {
scope: values.scope,
hasActiveFilters:
values.searchQuery.trim().length > 0 ||
- values.sourceProductFilter.length > 0 ||
- values.scoutFilter.length > 0 ||
+ values.activeSourceProductFilter.length > 0 ||
+ values.activeScoutFilter.length > 0 ||
values.priorityFilter.length > 0 ||
values.activeCreatedWindow !== null,
sortField: values.activeSortField,
@@ -166,15 +166,15 @@ export function shouldDefaultToEntireProject(input: {
export interface reportListLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
activeCreatedWindow: InboxCreatedWindow | null // inboxFiltersLogic
+ activeScoutFilter: string[] // inboxFiltersLogic
activeSortDirection: InboxSortDirection // inboxFiltersLogic
activeSortField: InboxSortField // inboxFiltersLogic
+ activeSourceProductFilter: string[] // inboxFiltersLogic
hasUserChosenScope: boolean // inboxFiltersLogic
isScopedToMe: boolean // inboxFiltersLogic
priorityFilter: SignalReportPriority[] // inboxFiltersLogic
scope: InboxScope // inboxFiltersLogic
- scoutFilter: string[] // inboxFiltersLogic
searchQuery: string // inboxFiltersLogic
- sourceProductFilter: string[] // inboxFiltersLogic
currentTeamId: number | null // teamLogic
user: UserType | null // userLogic
claimSavingReportIds: string[]
@@ -236,6 +236,12 @@ export interface reportListLogicActions {
direction: InboxSortDirection
field: InboxSortField
} // inboxFiltersLogic
+ setSourceFilter: (selection: null | import('./inboxFiltersLogic').InboxSourceSelection) => {
+ selection: null | import('./inboxFiltersLogic').InboxSourceSelection
+ } // inboxFiltersLogic
+ sourceFilterAvailabilityChanged: () => {
+ value: true
+ } // inboxFiltersLogic
togglePriority: (priority: SignalReportPriority) => {
priority: SignalReportPriority
} // inboxFiltersLogic
@@ -394,8 +400,8 @@ export interface reportListLogicMeta {
searchQuery: string,
activeSortField: InboxSortField,
activeSortDirection: InboxSortDirection,
- sourceProductFilter: string[],
- scoutFilter: string[],
+ activeSourceProductFilter: string[],
+ activeScoutFilter: string[],
priorityFilter: SignalReportPriority[],
scopeReviewerUuid: string | undefined,
scopeAssignee: 'mine' | undefined,
@@ -450,8 +456,8 @@ export const reportListLogic = kea<reportListLogicType>([
'searchQuery',
'activeSortField',
'activeSortDirection',
- 'sourceProductFilter',
- 'scoutFilter',
+ 'activeSourceProductFilter',
+ 'activeScoutFilter',
'priorityFilter',
'activeCreatedWindow',
],
@@ -470,6 +476,8 @@ export const reportListLogic = kea<reportListLogicType>([
'resetUnavailableSort',
'toggleSourceProduct',
'toggleScout',
+ 'setSourceFilter',
+ 'sourceFilterAvailabilityChanged',
'togglePriority',
'setPriorityFilter',
'setScope',
@@ -693,8 +701,8 @@ export const reportListLogic = kea<reportListLogicType>([
s.searchQuery,
s.activeSortField,
s.activeSortDirection,
- s.sourceProductFilter,
- s.scoutFilter,
+ s.activeSourceProductFilter,
+ s.activeScoutFilter,
s.priorityFilter,
s.scopeReviewerUuid,
s.scopeAssignee,
@@ -923,6 +931,8 @@ export const reportListLogic = kea<reportListLogicType>([
applyDefaultCreatedWindow: () => actions.refresh(),
toggleSourceProduct: () => actions.refresh(),
toggleScout: () => actions.refresh(),
+ setSourceFilter: () => actions.refresh(),
+ sourceFilterAvailabilityChanged: () => actions.refresh(),
togglePriority: () => actions.refresh(),
setPriorityFilter: () => actions.refresh(),
setScope: () => actions.refresh(),
diff --git a/products/signals/frontend/inbox/utils/inboxSourceFilter.test.ts b/products/signals/frontend/inbox/utils/inboxSourceFilter.test.ts
new file mode 100644
index 000000000000..055f7af94357
--- /dev/null
+++ b/products/signals/frontend/inbox/utils/inboxSourceFilter.test.ts
@@ -0,0 +1,42 @@
+import { buildInboxSourceChoices, singleInboxSourceSelection } from './inboxSourceFilter'
+
+describe('inboxSourceFilter', () => {
+ it('lists configured products and every scout, and keeps stale selections visible', () => {
+ const choices = buildInboxSourceChoices({
+ sourceConfigs: [
+ { source_product: 'error_tracking' },
+ { source_product: 'error_tracking' },
+ { source_product: 'signals_scout' },
+ ],
+ scoutConfigs: [
+ { skill_name: 'signals-scout-error-tracking' },
+ { skill_name: 'team-checkout-a', display_name: 'Checkout' },
+ { skill_name: 'team-checkout-b', display_name: 'Checkout' },
+ ],
+ sourceProductFilter: ['zendesk'],
+ scoutFilter: ['deleted-scout'],
+ })
+
+ expect(choices.sources.map(({ value, label, unavailable }) => [value, label, unavailable])).toEqual([
+ ['error_tracking', 'Error tracking', false],
+ ['zendesk', 'Zendesk', true],
+ ])
+ expect(choices.scouts.map(({ value, label, unavailable }) => [value, label, unavailable])).toEqual([
+ ['team-checkout-a', 'Checkout (team-checkout-a)', false],
+ ['team-checkout-b', 'Checkout (team-checkout-b)', false],
+ ['deleted-scout', 'Deleted scout', true],
+ ['signals-scout-error-tracking', 'Error tracking', false],
+ ])
+ })
+
+ it.each([
+ [['logs'], [], { kind: 'source_product', value: 'logs' }],
+ [[], ['my-scout'], { kind: 'scout', value: 'my-scout' }],
+ [[], [], null],
+ // An old shared link can combine several values. No single choice represents it.
+ [['logs', 'github'], [], null],
+ [['logs'], ['my-scout'], null],
+ ])('reads %p and %p as one selection: %p', (sourceProductFilter, scoutFilter, expected) => {
+ expect(singleInboxSourceSelection(sourceProductFilter, scoutFilter)).toEqual(expected)
+ })
+})
diff --git a/products/signals/frontend/inbox/utils/inboxSourceFilter.ts b/products/signals/frontend/inbox/utils/inboxSourceFilter.ts
new file mode 100644
index 000000000000..c75011808a84
--- /dev/null
+++ b/products/signals/frontend/inbox/utils/inboxSourceFilter.ts
@@ -0,0 +1,103 @@
+import { getSourceProductMeta } from '../components/badges/sourceProductIcons'
+import type { InboxSourceSelection } from '../logics/inboxFiltersLogic'
+import { SignalSourceProduct } from '../types'
+import { prettifyScoutSkillName, scoutDisplayName } from './scoutRunsWindow'
+
+export interface InboxSourceChoice extends InboxSourceSelection {
+ label: string
+ /** The stored selection names a source or scout that the loaded configuration no longer has. */
+ unavailable: boolean
+}
+
+export interface InboxSourceChoices {
+ sources: InboxSourceChoice[]
+ scouts: InboxSourceChoice[]
+}
+
+export function sourceProductLabel(sourceProduct: string): string {
+ return getSourceProductMeta(sourceProduct)?.label ?? sourceProduct
+}
+
+function byLabel(a: InboxSourceChoice, b: InboxSourceChoice): number {
+ return a.label.localeCompare(b.label)
+}
+
+/**
+ * The Source filter choices: one per configured non-scout product, and one per scout config. Paused
+ * sources and scouts stay in the list because their old reports still exist. A selected value that the
+ * configuration does not contain stays in the list too, so the user can see it and clear it.
+ */
+export function buildInboxSourceChoices({
+ sourceConfigs,
+ scoutConfigs,
+ sourceProductFilter,
+ scoutFilter,
+}: {
+ sourceConfigs: { source_product: string }[] | null
+ scoutConfigs: { skill_name: string; display_name?: string }[] | null
+ sourceProductFilter: string[]
+ scoutFilter: string[]
+}): InboxSourceChoices {
+ const configuredProducts = new Set(
+ (sourceConfigs ?? [])
+ .map((config) => config.source_product)
+ .filter((product) => product !== SignalSourceProduct.SignalsScout)
+ )
+ const sources: InboxSourceChoice[] = [...configuredProducts].map((value) => ({
+ kind: 'source_product',
+ value,
+ label: sourceProductLabel(value),
+ unavailable: false,
+ }))
+ for (const value of sourceProductFilter) {
+ if (!configuredProducts.has(value)) {
+ sources.push({ kind: 'source_product', value, label: sourceProductLabel(value), unavailable: true })
+ }
+ }
+
+ const labelCounts = new Map<string, number>()
+ for (const config of scoutConfigs ?? []) {
+ const label = scoutDisplayName(config)
+ labelCounts.set(label, (labelCounts.get(label) ?? 0) + 1)
+ }
+ const scouts: InboxSourceChoice[] = (scoutConfigs ?? []).map((config) => {
+ const label = scoutDisplayName(config)
+ return {
+ kind: 'scout',
+ value: config.skill_name,
+ // Two scouts can share a display name. The skill name is unique, so it tells them apart.
+ label: (labelCounts.get(label) ?? 0) > 1 ? `${label} (${config.skill_name})` : label,
+ unavailable: false,
+ }
+ })
+ const configuredScouts = new Set(scouts.map((scout) => scout.value))
+ for (const value of scoutFilter) {
+ if (!configuredScouts.has(value)) {
+ scouts.push({ kind: 'scout', value, label: prettifyScoutSkillName(value), unavailable: true })
+ }
+ }
+
+ return { sources: sources.sort(byLabel), scouts: scouts.sort(byLabel) }
+}
+
+/**
+ * The one choice the stored selection represents, or null. A shared link from the old toolbar can
+ * carry several products or scouts, and no single choice represents that.
+ */
+export function singleInboxSourceSelection(
+ sourceProductFilter: string[],
+ scoutFilter: string[]
+): InboxSourceSelection | null {
+ if (sourceProductFilter.length === 1 && scoutFilter.length === 0) {
+ return { kind: 'source_product', value: sourceProductFilter[0] }
+ }
+ if (scoutFilter.length === 1 && sourceProductFilter.length === 0) {
+ return { kind: 'scout', value: scoutFilter[0] }
+ }
+ return null
+}
+
+export function matchesInboxSourceSearch(choice: InboxSourceChoice, search: string): boolean {
+ const query = search.trim().toLowerCase()
+ return !query || choice.label.toLowerCase().includes(query) || choice.value.toLowerCase().includes(query)
+}