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(members): defer closed member picker work (#103966)

Arthur Moreira de Deuse04856c95fd5
diff --git a/docs/internal/customer-analytics/accounts-table.md b/docs/internal/customer-analytics/accounts-table.md
index 7a486bd4e64c..7931e46b0721 100644
--- a/docs/internal/customer-analytics/accounts-table.md
+++ b/docs/internal/customer-analytics/accounts-table.md
@@ -61,3 +61,11 @@ The `ManyColumns` story in `AccountsTab.stories.tsx` covers six added custom pro
Its browser assertions check content-dependent widths, the 200px cap, horizontal scrolling, and the row expansion control.
At narrow widths, it also covers custom-property inline editing: the input fits the available column width, and Save and Cancel stay together below it when needed, aligned to the right.
The row grows without widening the column.
+
+## Relationship member pickers
+
+Each editable single-holder relationship cell mounts a member picker.
+Closed pickers render the selected label but defer the searchable option list until opened.
+Opening still loads members and keeps the current user first.
+Closing through a selection, the trigger, or an outside click clears the search so the next open starts fresh.
+Mounting another closed cell does not clear an active picker's search.
diff --git a/frontend/src/lib/components/MemberSelect.test.tsx b/frontend/src/lib/components/MemberSelect.test.tsx
index 47e9ad822bc9..b42280690e2f 100644
--- a/frontend/src/lib/components/MemberSelect.test.tsx
+++ b/frontend/src/lib/components/MemberSelect.test.tsx
@@ -84,4 +84,30 @@ describe('MemberSelect', () => {
expect(onChange).toHaveBeenCalledWith(MOCK_SECOND_BASIC_USER)
})
+
+ it('preserves an open picker search when another picker mounts and clears it after closing', async () => {
+ const pickers = (showSecond: boolean): JSX.Element => (
+ <Provider>
+ <>
+ <MemberSelect value={null} onChange={onChange} />
+ {showSecond ? <MemberSelect value={null} onChange={onChange} /> : null}
+ <button type="button">Outside</button>
+ </>
+ </Provider>
+ )
+ const { rerender } = render(pickers(false))
+
+ await userEvent.click(screen.getByText('Any user'))
+ const searchInput = await screen.findByPlaceholderText('Search')
+ await userEvent.type(searchInput, 'Rose')
+
+ rerender(pickers(true))
+ expect(screen.getByPlaceholderText('Search')).toHaveValue('Rose')
+
+ await userEvent.click(screen.getByText('Outside'))
+ await waitFor(() => expect(screen.queryByPlaceholderText('Search')).not.toBeInTheDocument())
+ await userEvent.click(screen.getAllByText('Any user')[0])
+
+ expect(await screen.findByPlaceholderText('Search')).toHaveValue('')
+ })
})
diff --git a/frontend/src/lib/components/MemberSelect.tsx b/frontend/src/lib/components/MemberSelect.tsx
index 79108be63f20..8d06d0ec726d 100644
--- a/frontend/src/lib/components/MemberSelect.tsx
+++ b/frontend/src/lib/components/MemberSelect.tsx
@@ -1,5 +1,5 @@
import { useActions, useValues } from 'kea'
-import { useEffect, useMemo, useState } from 'react'
+import { useMemo, useState } from 'react'
import { LemonButton, LemonButtonProps, LemonDropdown, LemonDropdownProps, LemonInput } from '@posthog/lemon-ui'
@@ -42,20 +42,22 @@ export function MemberSelect({
return meFirstMembers.find((member) => member.user[propToCompare] === value)?.user ?? null
}, [value, meFirstMembers, propToCompare])
+ const handleVisibilityChange = (visible: boolean): void => {
+ setShowPopover(visible)
+ if (search) {
+ setSearch('')
+ }
+ if (visible) {
+ ensureAllMembersLoaded()
+ }
+ }
+
const _onChange = (value: UserBasicType | null): void => {
- setShowPopover(false)
+ handleVisibilityChange(false)
onChange(value)
}
- useEffect(() => {
- if (showPopover) {
- ensureAllMembersLoaded()
- } else {
- setSearch('')
- }
- }, [showPopover]) // oxlint-disable-line react-hooks/exhaustive-deps
-
- const members = selectableMembers(excludedMembers, propToCompare)
+ const members = showPopover ? selectableMembers(excludedMembers, propToCompare) : []
return (
<LemonDropdown
@@ -64,44 +66,46 @@ export function MemberSelect({
matchWidth={false}
placement="bottom-start"
actionable
- onVisibilityChange={(visible) => setShowPopover(visible)}
+ onVisibilityChange={handleVisibilityChange}
overlay={
- <div className="max-w-100 deprecated-space-y-2">
- <LemonInput
- type="search"
- placeholder="Search"
- autoFocus
- value={search}
- onChange={setSearch}
- fullWidth
- />
- <ul className="deprecated-space-y-px">
- {allowNone && (
- <li>
- <LemonButton fullWidth role="menuitem" size="small" onClick={() => _onChange(null)}>
- {defaultLabel}
- </LemonButton>
- </li>
- )}
+ showPopover ? (
+ <div className="max-w-100 deprecated-space-y-2">
+ <LemonInput
+ type="search"
+ placeholder="Search"
+ autoFocus
+ value={search}
+ onChange={setSearch}
+ fullWidth
+ />
+ <ul className="deprecated-space-y-px">
+ {allowNone && (
+ <li>
+ <LemonButton fullWidth role="menuitem" size="small" onClick={() => _onChange(null)}>
+ {defaultLabel}
+ </LemonButton>
+ </li>
+ )}
- {members.map((member) => (
- <MemberSelectRow
- key={member.user.uuid}
- member={member}
- isYou={member.user.uuid === me?.user.uuid}
- onClick={() => _onChange(member.user)}
- />
- ))}
+ {members.map((member) => (
+ <MemberSelectRow
+ key={member.user.uuid}
+ member={member}
+ isYou={member.user.uuid === me?.user.uuid}
+ onClick={() => _onChange(member.user)}
+ />
+ ))}
- {membersLoading ? (
- <div className="p-2 text-secondary italic truncate border-t">Loading...</div>
- ) : members.length === 0 ? (
- <div className="p-2 text-secondary italic truncate border-t">
- {search ? <span>No matches</span> : <span>No users</span>}
- </div>
- ) : null}
- </ul>
- </div>
+ {membersLoading ? (
+ <div className="p-2 text-secondary italic truncate border-t">Loading...</div>
+ ) : members.length === 0 ? (
+ <div className="p-2 text-secondary italic truncate border-t">
+ {search ? <span>No matches</span> : <span>No users</span>}
+ </div>
+ ) : null}
+ </ul>
+ </div>
+ ) : null
}
>
{children ? (
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
index 02450002c4e4..3bf72656e1cf 100644
--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md
+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
@@ -86,7 +86,7 @@ New saved views always store `assignmentStatus`; in the URL hash the default `al
Overview tiles run as a separate metrics-only `AccountsTableQuery` (`metrics` set and `columns: []`; `null` when there are no tiles or while definitions are loading). Count, sum, average, minimum, maximum, median, scaling, and threshold counts execute in Postgres. The "My accounts" checkbox resolves to the current user's explicit ID before either query is built, so shared URLs remain viewer-independent. Two cell shapes matter:
- **`name` column** (mandatory, `ACCOUNTS_NAME_COLUMN`) — read directly from the keyed row's `id`, `name`, `externalId`, and `logoDomain`. This is the row's identity: `id` (the account PK) drives expansion, scroll, and role updates; `externalId` is the copyable group key. `getNameCell()` in `AccountsTable.tsx` is the canonical accessor. `AccountNameCell.tsx` owns the shared name, deep link, and copyable external ID presentation. `AccountsTableNameCell.tsx` owns list selection behavior. The Accounts list passes `logoDomain`, which adds `AccountLogo`. Other account tables omit the logo and use normal deep-link navigation.
-- **relationship columns** — returned in `AccountsTableRow.relationships` as arrays of active assignee user ids keyed by definition id (`[]` when unassigned). The legacy names `csm`/`account_executive`/`account_owner` remain stored in defaults, saved views, and URL state, then translate into typed relationship columns matched by seeded definition name (`LEGACY_ROLE_COLUMNS`); a legacy column with no matching definition is dropped from the query. Other definitions are pickable from the "Relationships" column group with opaque `rel_<id>` aliases, resolved back via `aliasToRelationshipDefinition`. Cells render `RelationshipCell`: single-holder definitions get an editable `MemberSelect` (writes via the relationships assign/end endpoints — assign auto-ends the previous holder server-side); multi-holder definitions render read-only. User ids resolve to members via `membersLogic` (loaded up front in `accountsLogic.afterMount`). Sorting uses the alias directly (arrays of ids — deterministic but not email order).
+- **relationship columns** — returned in `AccountsTableRow.relationships` as arrays of active assignee user ids keyed by definition id (`[]` when unassigned). The legacy names `csm`/`account_executive`/`account_owner` remain stored in defaults, saved views, and URL state, then translate into typed relationship columns matched by seeded definition name (`LEGACY_ROLE_COLUMNS`); a legacy column with no matching definition is dropped from the query. Other definitions are pickable from the "Relationships" column group with opaque `rel_<id>` aliases, resolved back via `aliasToRelationshipDefinition`. Cells render `RelationshipCell`: single-holder definitions get an editable `MemberSelect` (writes via the relationships assign/end endpoints — assign auto-ends the previous holder server-side); multi-holder definitions render read-only. User ids resolve to members via `membersLogic` (loaded up front in `accountsLogic.afterMount`). Each `MemberSelect` builds its searchable member options only while open. Mounting closed table cells does not alter shared member search, and closing a picker clears its search before the next open. Sorting uses the alias directly (arrays of ids — deterministic but not email order).
### Account logos