: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(signals): remove duplicate for you scope option (#106051)
Paul D'Ambra72d11f09d287
diff --git a/products/signals/frontend/inbox/components/shell/InboxScopeFilter.test.tsx b/products/signals/frontend/inbox/components/shell/InboxScopeFilter.test.tsxindex 250bf7e2f81a..93d1f154bc3a 100644--- a/products/signals/frontend/inbox/components/shell/InboxScopeFilter.test.tsx+++ b/products/signals/frontend/inbox/components/shell/InboxScopeFilter.test.tsx@@ -2,7 +2,7 @@ import { MOCK_DEFAULT_USER } from 'lib/api.mock'import '@testing-library/jest-dom'-import { cleanup, render, screen, waitFor } from '@testing-library/react'+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'import posthog from 'posthog-js'import { useMocks } from '~/mocks/jest'@@ -16,16 +16,38 @@ jest.mock('lib/components/MemberSelect', () => ({MemberSelect: ({options,children,+ defaultLabel,+ extraOptions = [],+ onChange,+ onSelectOption,}: {options: { uuid: string; name: string; trailing?: string }[]children: () => JSX.Element+ defaultLabel: string+ extraOptions?: { label: string; onClick: () => void }[]+ onChange: () => void+ onSelectOption: (uuid: string, label: string) => void}) => (<>{children()}<ul>+ {extraOptions.map((option) => (+ <li key={option.label}>+ <button type="button" role="menuitem" onClick={option.onClick}>+ {option.label}+ </button>+ </li>+ ))}+ <li>+ <button type="button" role="menuitem" onClick={onChange}>+ {defaultLabel}+ </button>+ </li>{options.map((person) => (<li key={person.uuid}>- {person.name} {person.trailing}+ <button type="button" role="menuitem" onClick={() => onSelectOption(person.uuid, person.name)}>+ {person.name} {person.trailing}+ </button></li>))}</ul>@@ -77,13 +99,20 @@ describe('InboxScopeFilter', () => {expect(screen.queryByLabelText('Report scope: Ada')).toBeNull()})- // "For you" resolves to whoever opens the link, so a URL that opens to *your* reports for a- // teammate can only come from your own roster row. Hiding that row as a duplicate of "For you"- // makes your view the one scope nobody can share.- it('keeps the signed-in user in the roster so their scope can be shared by URL', async () => {+ it('uses the signed-in user row to select For you without a duplicate menu item', async () => {inboxFiltersLogic.mount()render(<InboxScopeFilter />)- await waitFor(() => expect(screen.getByText(`${MOCK_DEFAULT_USER.first_name} (you)`)).toBeInTheDocument())+ await screen.findByText(`${MOCK_DEFAULT_USER.first_name} (you)`)+ expect(screen.queryByText('For you', { selector: '[role=menuitem]' })).not.toBeInTheDocument()++ fireEvent.click(screen.getByText('Entire project', { selector: '[role=menuitem]' }))+ await waitFor(() => expect(screen.getByLabelText('Report scope: Entire project')).toBeInTheDocument())++ inboxFiltersLogic.actions.loadAvailableReviewersSuccess([])+ await waitFor(() => expect(screen.queryByText('Ada', { selector: '[role=menuitem]' })).not.toBeInTheDocument())+ const fallbackRow = await screen.findByText(`${MOCK_DEFAULT_USER.first_name} (you)`)+ fireEvent.click(fallbackRow)+ await waitFor(() => expect(screen.getByLabelText('Report scope: For you')).toBeInTheDocument())})})diff --git a/products/signals/frontend/inbox/components/shell/InboxScopeFilter.tsx b/products/signals/frontend/inbox/components/shell/InboxScopeFilter.tsxindex 937eab203028..0eca5dc47213 100644--- a/products/signals/frontend/inbox/components/shell/InboxScopeFilter.tsx+++ b/products/signals/frontend/inbox/components/shell/InboxScopeFilter.tsx@@ -2,17 +2,43 @@ import { useActions, useValues } from 'kea'import { LemonButton } from '@posthog/lemon-ui'-import { MemberSelect } from 'lib/components/MemberSelect'+import { MemberSelect, type MemberSelectProps } from 'lib/components/MemberSelect'import { userLogic } from 'scenes/userLogic'+import type { UserType } from '~/types'+import { parseTeammateInboxScope, teammateInboxScope } from '../../inboxMembership'-import { inboxFiltersLogic } from '../../logics/inboxFiltersLogic'+import { type InboxReviewerOption, inboxFiltersLogic } from '../../logics/inboxFiltersLogic'import { INBOX_SCOPE_ENTIRE_PROJECT, INBOX_SCOPE_FOR_YOU, InboxScope } from '../../types'+function getReviewerOptions(+ reviewers: InboxReviewerOption[],+ user: UserType | null+): NonNullable<MemberSelectProps['options']> {+ const options = reviewers.map((reviewer) => ({+ uuid: reviewer.user_uuid,+ name: reviewer.name,+ email: reviewer.email,+ trailing: reviewer.user_uuid === user?.uuid ? '(you)' : undefined,+ }))+ if (!user || options.some((option) => option.uuid === user.uuid)) {+ return options+ }+ return [+ {+ uuid: user.uuid,+ name: `${user.first_name} ${user.last_name ?? ''}`.trim() || user.email,+ email: user.email,+ trailing: '(you)',+ },+ ...options,+ ]+}+/*** Single-dropdown reviewer scope for the flat Reports list: one trigger that names the current- * scope and opens the shared people picker with "For you" pinned on top, then "Entire project",- * then each teammate. "For you" is the default scope; a user with no reports suggested to them is+ * scope and opens the shared people picker with "Entire project" and each teammate. Selecting+ * yourself uses the "For you" scope. A user with no reports suggested to them is* auto-switched to "Entire project" (see `shouldDefaultToEntireProject`). The legacy layout keeps* the two-segment `InboxScopeSelect` until the redesign flag replaces it. Scope is persisted via* `inboxFiltersLogic`; teammates come from its shared `availableReviewers` loader.@@ -42,6 +68,8 @@ export function InboxScopeFilter(): JSX.Element {? (selectedTeammateLabel ?? cachedTeammateLabel ?? 'Teammate'): 'Entire project'+ const options = getReviewerOptions(reviewers, user)+const pick = (next: InboxScope, label?: string): void => {const nextUuid = parseTeammateInboxScope(next)if (label && nextUuid) {@@ -55,17 +83,13 @@ export function InboxScopeFilter(): JSX.Element {<MemberSelectvalue={selectedTeammateUuid}defaultLabel="Entire project"- extraOptions={[{ label: 'For you', onClick: () => pick(INBOX_SCOPE_FOR_YOU) }]}- options={reviewers.map((reviewer) => ({- uuid: reviewer.user_uuid,- name: reviewer.name,- email: reviewer.email,- trailing: reviewer.user_uuid === user?.uuid ? '(you)' : undefined,- }))}+ options={options}optionsLoading={availableReviewersLoading}onSearch={searchAvailableReviewers}onChange={() => pick(INBOX_SCOPE_ENTIRE_PROJECT)}- onSelectOption={(uuid, label) => pick(teammateInboxScope(uuid), label)}+ onSelectOption={(uuid, label) =>+ pick(uuid === user?.uuid ? INBOX_SCOPE_FOR_YOU : teammateInboxScope(uuid), label)+ }>{() => (<LemonButton