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(signals): drop inbox row when its scoped reviewer is removed (#106801)

Alex Lebedevca02ad9644c8
diff --git a/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts b/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts
index a744b7bbbdcc..1819c8a41c4f 100644
--- a/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts
@@ -60,6 +60,13 @@ export interface inboxBulkActionsLogicActions {
clearSelection: () => {
value: true
}
+ reportReviewersChanged: (
+ reportId: string,
+ reviewerUuids: string[]
+ ) => {
+ reportId: string
+ reviewerUuids: string[]
+ }
reportStateChanged: () => {
value: true
}
@@ -126,6 +133,9 @@ export const inboxBulkActionsLogic = kea<inboxBulkActionsLogicType>([
* the detail pane), so every mounted list reconciles itself. Persisting the change is the
* caller's responsibility. */
reportStateChanged: true,
+ /** Broadcast that a report's suggested reviewers were saved, with the PostHog user uuids now on
+ * it, so a list scoped to a reviewer who is no longer on the report drops the row in place. */
+ reportReviewersChanged: (reportId: string, reviewerUuids: string[]) => ({ reportId, reviewerUuids }),
}),
reducers({
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
index cc942e19393b..49bdf67677cb 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
@@ -76,6 +76,7 @@ import {
} from '../types'
import { ChartPlacements, resolveChartPlacements } from '../utils/chartPlacement'
import { reportPullRequests, primaryReportPullRequest, type ReportPullRequest } from '../utils/reportPullRequests'
+import { inboxBulkActionsLogic } from './inboxBulkActionsLogic'
/** Run statuses that count as terminal. Mirrors desktop `isTerminalStatus` / `ReportTasksSection`. */
const TERMINAL_RUN_STATUSES: TaskRunStatus[] = [TaskRunStatus.COMPLETED, TaskRunStatus.FAILED, TaskRunStatus.CANCELLED]
@@ -1447,9 +1448,11 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
// Persist a reviewer add/remove. The optimistic list is already in place (set by the action's
// reducer); on success reload the artefact so we converge on the server's enriched data, and on
// failure clear the optimistic override so the UI snaps back. Mirrors desktop `useUpdateSuggestedReviewers`.
- updateReviewers: async ({ content }) => {
+ updateReviewers: async ({ content, optimistic }) => {
+ let saved = false
try {
await api.signalReports.setReviewers(props.reportId, content)
+ saved = true
await asyncActions.loadReportArtefacts()
} catch (error: any) {
lemonToast.error(error?.detail || error?.message || 'Failed to update reviewers')
@@ -1457,6 +1460,14 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
// Clear the optimistic override; the freshly-loaded artefact is now the source of truth.
actions.setOptimisticReviewers(null)
}
+ // Broadcast last: the list can drop the row that hosts this logic (the context menu picker),
+ // which unmounts it, and kea throws on an action dispatched through an unmounted logic.
+ if (saved) {
+ const reviewerUuids = optimistic
+ .map((reviewer) => reviewer.user?.uuid ?? reviewer.user_uuid)
+ .filter((uuid): uuid is string => !!uuid)
+ inboxBulkActionsLogic.findMounted()?.actions.reportReviewersChanged(props.reportId, reviewerUuids)
+ }
},
// Post an inline review comment as the user. The comment is inserted optimistically (marked
// `pending: 'sending'`) and the composer/draft closes immediately, so nothing vanishes during
diff --git a/products/signals/frontend/inbox/logics/reportListLogic.test.ts b/products/signals/frontend/inbox/logics/reportListLogic.test.ts
index 26f52026e98f..2bd306fe2084 100644
--- a/products/signals/frontend/inbox/logics/reportListLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/reportListLogic.test.ts
@@ -15,6 +15,7 @@ import {
SignalReport,
SignalReportStatus,
} from '../types'
+import { inboxBulkActionsLogic } from './inboxBulkActionsLogic'
import { INBOX_REPORT_SECTION_LIST_PARAMS, reportListLogic, shouldDefaultToEntireProject } from './reportListLogic'
const REPORTS_URL = '/api/projects/:team_id/signals/reports/'
@@ -188,6 +189,82 @@ describe('reportListLogic', () => {
expect(logic.values.pageLoadFailed).toBe(false)
expect(logic.values.reports).toHaveLength(FIRST_PAGE.length + SECOND_PAGE.length)
})
+
+ it('keeps a row removed while the next page is in flight out of the appended list', async () => {
+ let releasePage: () => void = () => {}
+ const heldPage = new Promise<void>((resolve) => {
+ releasePage = resolve
+ })
+ useMocks({
+ get: {
+ [REPORTS_URL]: async () => {
+ await heldPage
+ return [
+ 200,
+ {
+ count: FIRST_PAGE.length + SECOND_PAGE.length,
+ next: null,
+ previous: null,
+ results: SECOND_PAGE,
+ },
+ ]
+ },
+ },
+ })
+
+ logic.actions.loadMore()
+ logic.actions.removeReport(FIRST_PAGE[3].id)
+ releasePage()
+ await expectLogic(logic).toDispatchActions(['loadMoreReportsSuccess'])
+
+ expect(logic.values.reports.map((r) => r.id)).toEqual([
+ ...FIRST_PAGE.filter((r) => r.id !== FIRST_PAGE[3].id).map((r) => r.id),
+ ...SECOND_PAGE.map((r) => r.id),
+ ])
+ })
+
+ // A refetch reloads only the first page, so a reviewer edit must drop the row in place or the
+ // reader loses their scroll position in a long list.
+ it.each([
+ {
+ name: 'drops the row once the scoped reviewer is removed',
+ scope: 'teammate:t-1',
+ after: [],
+ dropped: true,
+ },
+ {
+ name: 'keeps the row while the scoped reviewer stays',
+ scope: 'teammate:t-1',
+ after: ['t-1'],
+ dropped: false,
+ },
+ {
+ name: 'keeps the row when no reviewer scope applies',
+ scope: INBOX_SCOPE_ENTIRE_PROJECT,
+ after: [],
+ dropped: false,
+ },
+ ] as { name: string; scope: InboxScope; after: string[]; dropped: boolean }[])(
+ '$name',
+ async ({ scope, after, dropped }) => {
+ const bulkLogic = inboxBulkActionsLogic()
+ bulkLogic.mount()
+ logic.actions.setScope(scope)
+ await expectLogic(logic).toFinishAllListeners()
+ logic.actions.loadMore()
+ await expectLogic(logic).toFinishAllListeners()
+ requestedOffsets = []
+
+ bulkLogic.actions.reportReviewersChanged(FIRST_PAGE[3].id, after)
+ await expectLogic(logic).toFinishAllListeners()
+
+ const loadedCount = FIRST_PAGE.length + SECOND_PAGE.length
+ expect(logic.values.reports.map((r) => r.id).includes(FIRST_PAGE[3].id)).toBe(!dropped)
+ expect(logic.values.reports).toHaveLength(dropped ? loadedCount - 1 : loadedCount)
+ expect(requestedOffsets).toEqual([])
+ bulkLogic.unmount()
+ }
+ )
})
// Which rows get a CI glyph, and which pull requests the batch endpoint is asked about. A landed
diff --git a/products/signals/frontend/inbox/logics/reportListLogic.ts b/products/signals/frontend/inbox/logics/reportListLogic.ts
index 316688701f4b..6fb8fe0c41df 100644
--- a/products/signals/frontend/inbox/logics/reportListLogic.ts
+++ b/products/signals/frontend/inbox/logics/reportListLogic.ts
@@ -167,6 +167,7 @@ export interface reportListLogicValues {
reportsLoadFailed: boolean
reportsResponse: ReportListResponse | null
reportsResponseLoading: boolean
+ scopeReviewerUuid: string | undefined
staleMetricReportIds: string[]
totalCount: number | null
}
@@ -307,6 +308,7 @@ export interface reportListLogicMeta {
key: 'dismissed' | 'monitoring' | 'needs-decision' | 'not-actionable' | 'resolved'
__keaTypeGenInternalSelectorTypes: {
primarySectionKey: (featureFlags: FeatureFlagsSet) => InboxReportSectionKey
+ scopeReviewerUuid: (scope: InboxScope, user: UserType | null) => string | undefined
listApiParams: (
searchQuery: string,
sortField: InboxSortField,
@@ -314,8 +316,7 @@ export interface reportListLogicMeta {
sourceProductFilter: string[],
scoutFilter: string[],
priorityFilter: SignalReportPriority[],
- scope: InboxScope,
- user: UserType | null,
+ scopeReviewerUuid: string | undefined,
arg: any
) => any
reports: (reportsResponse: ReportListResponse | null) => SignalReport[]
@@ -408,7 +409,7 @@ export const reportListLogic = kea<reportListLogicType>([
applyReportMetricSnapshots: (snapshots: SignalReportMetricSnapshotsApi[]) => ({ snapshots }),
}),
- loaders(({ values }) => ({
+ loaders(({ values, cache }) => ({
// Cheap count-only request – populates the state's count before its rows load. `count_only`
// lets the backend answer with one `COUNT(*)`, skipping ordering, row serialization, and
// the per-row metadata lookups.
@@ -441,6 +442,10 @@ export const reportListLogic = kea<reportListLogicType>([
const params = values.listApiParams
const requestContext = requestContextFromValues(values)
const current = values.reportsResponse?.results ?? []
+ // `removeReport` records ids here while the request is in flight. `current` predates
+ // those removals, so filter them out or a removed report comes back when the page lands.
+ const removedWhilePending = new Set<string>()
+ cache.removedWhilePageLoads = removedWhilePending
const response = await api.signalReports.list({
...params,
offset: current.length,
@@ -448,7 +453,7 @@ export const reportListLogic = kea<reportListLogicType>([
})
return {
...response,
- results: [...current, ...response.results],
+ results: [...current.filter((r) => !removedWhilePending.has(r.id)), ...response.results],
requestParams: params,
requestContext,
}
@@ -517,6 +522,12 @@ export const reportListLogic = kea<reportListLogicType>([
? INBOX_PRIMARY_REPORT_SECTION_KEY
: INBOX_LEGACY_PRIMARY_REPORT_SECTION_KEY,
],
+ // The PostHog user the reviewer scope narrows the list to. Undefined for Entire project.
+ scopeReviewerUuid: [
+ (s) => [s.scope, s.user],
+ (scope: InboxScope, user: UserType | null): string | undefined =>
+ scope === INBOX_SCOPE_FOR_YOU ? (user?.uuid ?? undefined) : teammateUuidFromScope(scope),
+ ],
// The section's fixed filter merged with the user-driven chrome + reviewer scope (server-side).
listApiParams: [
(s) => [
@@ -526,8 +537,7 @@ export const reportListLogic = kea<reportListLogicType>([
s.sourceProductFilter,
s.scoutFilter,
s.priorityFilter,
- s.scope,
- s.user,
+ s.scopeReviewerUuid,
(_, p) => p.listParams,
],
(
@@ -537,12 +547,9 @@ export const reportListLogic = kea<reportListLogicType>([
sourceProductFilter: string[],
scoutFilter: string[],
priorityFilter: import('../types').SignalReportPriority[],
- scope: InboxScope,
- user: null | import('~/types').UserType,
+ suggestedReviewer: string | undefined,
listParams
) => {
- const suggestedReviewer =
- scope === INBOX_SCOPE_FOR_YOU ? (user?.uuid ?? undefined) : teammateUuidFromScope(scope)
return {
...listParams,
search: searchQuery.trim() || undefined,
@@ -618,7 +625,7 @@ export const reportListLogic = kea<reportListLogicType>([
],
}),
- listeners(({ actions, values, props }) => ({
+ listeners(({ actions, values, props, cache }) => ({
// Announce this section's open pull requests so their CI state is resolved in one batch. Both
// loaders report: the first page and each appended page bring rows that need painting. An
// empty announcement matters too, because it retires the rows a narrowed filter dropped.
@@ -630,6 +637,9 @@ export const reportListLogic = kea<reportListLogicType>([
actions.trackReports(props.sectionKey, values.livePrReportIds)
actions.refreshReportMetrics(values.staleMetricReportIds)
},
+ removeReport: ({ reportId }) => {
+ cache.removedWhilePageLoads?.add(reportId)
+ },
// One page of ids per request, sent one after the other so a page open never fans out into
// parallel query bursts. A newer page load supersedes an in-flight refresh at the breakpoint.
refreshReportMetrics: async ({ reportIds }, breakpoint) => {
@@ -766,6 +776,14 @@ export const reportListLogic = kea<reportListLogicType>([
// this section against the server so the report leaves its section and joins Resolved or
// Dismissed, counts included.
[inboxBulkActionsLogic.actionTypes.reportStateChanged]: () => actions.refresh(),
+ // A reviewer edit can take a report out of this list's reviewer scope. Drop the row in place
+ // rather than refetch: a refetch reloads only the first page, which loses the scroll position.
+ [inboxBulkActionsLogic.actionTypes.reportReviewersChanged]: ({ reportId, reviewerUuids }) => {
+ const scopeUuid = values.scopeReviewerUuid
+ if (scopeUuid && !reviewerUuids.includes(scopeUuid) && values.reports.some((r) => r.id === reportId)) {
+ actions.removeReport(reportId)
+ }
+ },
})),
events(({ actions }) => ({