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(customer-analytics): add "My accounts" filter to accounts list (#63453)

Arthur Moreira de Deus4f67598e3013
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index eba28d9f4b37..18c6fa8db76a 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4447,13 +4447,13 @@ snapshots:
scenes-app-batchexports--runs-with-data--light:
hash: v1.k794b7964.144b41b97a76df864203804f6bf0b956998d6f0e6e4d81c4102c52dadce11813.DeXap8kCLxs-8UrwnfoTk5PIbkan4hrzxPCfyN_htME
scenes-app-customer-analytics-accounts--default--dark:
- hash: v1.k794b7964.2cfaa8253c84fdcf8c83cc7ba5a19ad9e23c94d53e22f56e283b70fdfaeba7ec.X3Et3UqSsRTSoIs_gmsFbWBV4l6eneKs60wf-rTmcTM
+ hash: v1.k794b7964.2d4fb8c374e2995fe8dcd196a365881710b6af22a0b9c2c70710b3cc1bed8eb2.96Xx2DJB6NG4b9N0J-fEsBLxgbYI2TWTdlo4CwZPEVg
scenes-app-customer-analytics-accounts--default--light:
- hash: v1.k794b7964.fc3d8055ff98049e433f274d3349666d00ecc4614fb75251f607fdcb4ce77909.j110JmmyfW52OY83n8BUvVElUT_CRdVQTz6VQNg99Ho
+ hash: v1.k794b7964.d78be4615c5ddafa7376704b215ebefd4d58a8e1b24603347212f3c14f4e06ba.K4frA5u_W62G7d511pwXgXiPgcS6Ja45IXbHv8lMOT4
scenes-app-customer-analytics-accounts--empty--dark:
- hash: v1.k794b7964.73491757bada1620aa713372c9e8d46abc53a2af573d0268705bb5b1cbe74c53.2YMX56dsIKrVY1sCeeqQ48PwemBOqeMDhE3Etu75OHo
+ hash: v1.k794b7964.1664f952be582a86b8afb9cc695dd4d332b18aedbd963f91e23e01490140f771.FISvQ9Ymsjkt3xJ1CpAmESHzEmt4t3iVBe5luBKyNGU
scenes-app-customer-analytics-accounts--empty--light:
- hash: v1.k794b7964.68c2dcb3162cb3778596874e67fec954404912ce39785ad745e4c374b973d7a4.U0ZTB2P50b7MO9p9sY_-wpJPizpxMBjNAq7CCh43Jxs
+ hash: v1.k794b7964.ce312c4142788e7fb8516bf31d360eab0d5df20b603d9ee855b4fcff0b27fee3.e8nTVdSI2d5Wu7W0giB9bYN47DCFgYGLyxq_9leuNLw
scenes-app-customer-analytics-accounts--feature-gate-off--dark:
hash: v1.k794b7964.7750bce37ad591ab773135ad1a9b8738ac790727774c03d3aa7b5abbfc42fab0.KbXf74dR5pSVh6Wc8mSjrNGqL8LbTcsMl78W7WVvTXU
scenes-app-customer-analytics-accounts--feature-gate-off--light:
@@ -4463,17 +4463,17 @@ snapshots:
scenes-app-customer-analytics-accounts--row-expanded-empty--light:
hash: v1.k794b7964.904bd5b939f99d43408ae3a8a814a3c299bd57bf13a0fd1d98ff6033fd66e343.K1Z16ICEF6-O9kIej8kGnYyarloq2oZH5rdtmx-8Hu0
scenes-app-customer-analytics-accounts--row-expanded-links-disabled--dark:
- hash: v1.k794b7964.db477f267006ea1a7c62dcc6650babdb05173670d274cb6e2c13eb7d507efdee.u0g7FlaBy1aMwj2qdxZtZwbP5SbJrJAQ_8yzC13I6Ps
+ hash: v1.k794b7964.9b18ad0a8cbe107cc03f82a4fd248ad31b951987a64f347aaf9a5e4ff4263f44.XB-umE74AEB4_9bUMCOhcvMXwShZL5OtLy1dwgec9bc
scenes-app-customer-analytics-accounts--row-expanded-links-disabled--light:
- hash: v1.k794b7964.b351959bb62bd40e5bcf62b774dc9d22484ae233784b67b7b64c29fc22c5e90a.pkRs8TqG9UAOhgvNduTlGYGfkoG9UGg35yf77xuRh6A
+ hash: v1.k794b7964.182d3d5e83e0eadd483d7294e94a990895edd7dbdd467e4180f1520dfcb3290c.LoRDMlmPuUagvXvOr4stvShG9-5GuDCK5MpR1S8Jbrc
scenes-app-customer-analytics-accounts--row-expanded-usage-not-found--dark:
- hash: v1.k794b7964.9d3e9c149633e6f1677c52086eab4923d9154084843bc072f09c1ea49191c81e.lN_ygX8-IRvnUCJMJxSorgYUrIBxplHmxr0zRhbH7Dw
+ hash: v1.k794b7964.eba558ef304111974792b634bfe75c19aae4a86e2edc37dd6797b9c1830d8f27._lCVn78wbVioIgfhyGOcm-BSV9mcwEIe207dPM3fG6Q
scenes-app-customer-analytics-accounts--row-expanded-usage-not-found--light:
- hash: v1.k794b7964.dbed81a9f646d861c5fea01fbb66409ca2134d052126c83910f0d48cc7c229b9.NTmSJa7n10fuCNA-jmRnxjcAV6Na8sJSdTOwg0LZb7M
+ hash: v1.k794b7964.cbb11987b4cd1ba8dd9e8bca4c3db8045008ab42b84530e53963e7a8b268b566.B8yb2ysrOlCwYdPiXW1B5t1p_Lx1tVz0hT87w2PQfr4
scenes-app-customer-analytics-accounts--row-expanded-usage-populated--dark:
- hash: v1.k794b7964.d04d40247868d79a631943192b59d6770129069130c7c01c218174297ea8e211.RdxB2mQsJYtXUNAhwCxybVGkPS9s-Y4rIV5-_PiJsbk
+ hash: v1.k794b7964.7b361d8434af412d51759866d0707a4de3a5b780c675488bf989ec3b637cdbaf.5av0Uc5JwMOyBT9EoCWnSy-F7fXll3NEIF2VduZoV_M
scenes-app-customer-analytics-accounts--row-expanded-usage-populated--light:
- hash: v1.k794b7964.6ba35c84f16d06a3a8e664519ac1d4cbe045069e459be8cd8752cdcb9e1f51fc.-7O2_Vcw9A-mDb_FWHgDylXVMLolYP3xzcf0X_oNUQI
+ hash: v1.k794b7964.15485ed4d97f6e62a78f4117109d28bce2853b7c8d46807bad3baffb7cb34183.GCGEjmwlM6b9aAvleOYdoCSAnlth8nU9NcmlNCYUV8Q
scenes-app-customer-analytics-accounts--row-expanded-with-note--dark:
hash: v1.k794b7964.3c9ce002ecb9931c56ef82618cc1625ee847a7f8df2a35c490006e4b356e6fb5.bK3yVZfb-U4TUMJHKvLemkMdqx6YNKdkFC2lnrWBgYg
scenes-app-customer-analytics-accounts--row-expanded-with-note--light:
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index d4dcf6a72d64..dfecb7c72f51 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -38,6 +38,13 @@
"allRolesUnassigned": {
"type": "boolean"
},
+ "assignedToUserIds": {
+ "description": "Match accounts where any of these user ids is the CSM or the account executive (OR over both roles). Drives the \"My accounts\" shortcut (the current user's id) and the shareable \"Assigned to\" filter — the ids are explicit so a shared URL resolves identically for every viewer.",
+ "items": {
+ "$ref": "#/definitions/integer"
+ },
+ "type": "array"
+ },
"csm": {
"description": "Match accounts whose CSM is any of these user ids (OR semantics).",
"items": {
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 48c298976807..9be34e653ec6 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -2334,6 +2334,8 @@ export interface AccountsQuery extends DataNode<AccountsQueryResponse> {
accountExecutive?: integer[]
/** Match accounts whose account owner is any of these user ids (OR semantics). */
accountOwner?: integer[]
+ /** Match accounts where any of these user ids is the CSM or the account executive (OR over both roles). Drives the "My accounts" shortcut (the current user's id) and the shareable "Assigned to" filter — the ids are explicit so a shared URL resolves identically for every viewer. */
+ assignedToUserIds?: integer[]
allRolesUnassigned?: boolean
/** Optional HogQL boolean expression AND-ed into the WHERE clause. Used by the overview tile click-to-filter affordance. */
filterExpression?: HogQLExpression
diff --git a/posthog/schema.py b/posthog/schema.py
index 2cb65f0d3f8c..d0a33972ad33 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -20503,6 +20503,15 @@ class AccountsQuery(BaseModel):
description=("Match accounts whose account owner is any of these user ids (OR semantics)."),
)
allRolesUnassigned: bool | None = None
+ assignedToUserIds: list[int] | None = Field(
+ default=None,
+ description=(
+ "Match accounts where any of these user ids is the CSM or the account"
+ ' executive (OR over both roles). Drives the "My accounts" shortcut (the'
+ ' current user\'s id) and the shareable "Assigned to" filter — the ids are'
+ " explicit so a shared URL resolves identically for every viewer."
+ ),
+ )
csm: list[int] | None = Field(
default=None,
description="Match accounts whose CSM is any of these user ids (OR semantics).",
diff --git a/products/customer_analytics/backend/hogql_queries/accounts_query_runner.py b/products/customer_analytics/backend/hogql_queries/accounts_query_runner.py
index e254fa5529a6..8197ca897644 100644
--- a/products/customer_analytics/backend/hogql_queries/accounts_query_runner.py
+++ b/products/customer_analytics/backend/hogql_queries/accounts_query_runner.py
@@ -32,6 +32,10 @@ ROLE_FIELDS = {
"accountOwner": "account_owner",
}
+# Roles that count as "assigned" for the `assignedToUserIds` filter — an account
+# is assigned to a user if they are its CSM or account executive.
+ASSIGNED_ROLE_KEYS = ("csm", "account_executive")
+
class AccountsQueryRunner(AnalyticsQueryRunner[AccountsQueryResponse]):
query: AccountsQuery
@@ -120,6 +124,9 @@ class AccountsQueryRunner(AnalyticsQueryRunner[AccountsQueryResponse]):
for json_key in ROLE_FIELDS.values():
where_exprs.append(self._role_id_isnull(json_key))
+ if self.query.assignedToUserIds:
+ where_exprs.append(self._assigned_to_users_expr(self.query.assignedToUserIds))
+
if self.query.filterExpression and self.query.filterExpression.strip():
where_exprs.append(parse_expr(self.query.filterExpression))
@@ -192,6 +199,20 @@ class AccountsQueryRunner(AnalyticsQueryRunner[AccountsQueryResponse]):
{"role_key": ast.Constant(value=json_key)},
)
+ def _assigned_to_users_expr(self, user_ids: list[int]) -> ast.Expr:
+ # OR over the CSM/AE roles, reusing the same IN-list shape as the
+ # per-role filters: an account is "assigned to" a user if they hold
+ # either role. Explicit ids (not the requester) so a shared URL filtered
+ # by "my accounts" resolves to the same accounts for every viewer.
+ role_exprs: list[ast.Expr] = []
+ for json_key in ASSIGNED_ROLE_KEYS:
+ role_expr = self._role_filter_expr(json_key, user_ids)
+ if role_expr is not None:
+ role_exprs.append(role_expr)
+ if not role_exprs:
+ return ast.Constant(value=False)
+ return ast.Or(exprs=role_exprs)
+
def _calculate(self) -> AccountsQueryResponse:
metrics_results = self._compute_metrics_results(self.query.metrics) if self.query.metrics else None
diff --git a/products/customer_analytics/backend/hogql_queries/test/test_accounts_query_runner.py b/products/customer_analytics/backend/hogql_queries/test/test_accounts_query_runner.py
index f402cb61bf49..6e8427644484 100644
--- a/products/customer_analytics/backend/hogql_queries/test/test_accounts_query_runner.py
+++ b/products/customer_analytics/backend/hogql_queries/test/test_accounts_query_runner.py
@@ -11,7 +11,7 @@ from posthog.hogql.errors import ExposedHogQLError
from posthog.api.tagged_item import set_tags_on_object
from posthog.constants import AvailableFeature
-from posthog.models import Tag
+from posthog.models import Tag, User
from posthog.models.team import Team
from posthog.rbac.user_access_control import UserAccessControlError
@@ -27,12 +27,12 @@ except ImportError:
@override_settings(IN_UNIT_TESTING=True)
class TestAccountsQueryRunner(ClickhouseTestMixin, NonAtomicBaseTest):
- def _run_query(self, **query_kwargs) -> tuple[AccountsQueryRunner, AccountsQueryResponse]:
- runner = AccountsQueryRunner(query=AccountsQuery(**query_kwargs), team=self.team)
+ def _run_query(self, user: User | None = None, **query_kwargs) -> tuple[AccountsQueryRunner, AccountsQueryResponse]:
+ runner = AccountsQueryRunner(query=AccountsQuery(**query_kwargs), team=self.team, user=user)
return runner, runner.calculate()
- def _ids(self, **query_kwargs) -> list[str]:
- runner, response = self._run_query(**query_kwargs)
+ def _ids(self, user: User | None = None, **query_kwargs) -> list[str]:
+ runner, response = self._run_query(user=user, **query_kwargs)
name_idx = runner.columns.index("name")
return [row[name_idx]["id"] for row in response.results]
@@ -197,6 +197,104 @@ class TestAccountsQueryRunner(ClickhouseTestMixin, NonAtomicBaseTest):
mine = create_account(team_id=self.team.id, name="Mine", _properties={"csm": {"id": 7, "email": "[email protected]"}})
self.assertEqual(self._ids(csm=[7]), [str(mine.id)])
+ @parameterized.expand(
+ [
+ ("csm", "csm"),
+ ("account_executive", "account_executive"),
+ ]
+ )
+ def test_assigned_to_user_matches_when_user_holds_role(self, _name, role_key):
+ mine = create_account(
+ team_id=self.team.id,
+ name="Mine",
+ _properties={role_key: {"id": 7, "email": "[email protected]"}},
+ )
+ create_account(
+ team_id=self.team.id,
+ name="Someone else's",
+ _properties={role_key: {"id": 8, "email": "[email protected]"}},
+ )
+ self.assertEqual(self._ids(assignedToUserIds=[7]), [str(mine.id)])
+
+ def test_assigned_to_user_unions_csm_and_account_executive_but_not_owner(self):
+ as_csm = create_account(team_id=self.team.id, name="As CSM", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ as_ae = create_account(
+ team_id=self.team.id,
+ name="As AE",
+ _properties={"account_executive": {"id": 7, "email": "[email protected]"}},
+ )
+ create_account(
+ team_id=self.team.id,
+ name="As owner only",
+ _properties={"account_owner": {"id": 7, "email": "[email protected]"}},
+ )
+ create_account(team_id=self.team.id, name="Unassigned")
+
+ self.assertEqual(
+ set(self._ids(assignedToUserIds=[7])),
+ {str(as_csm.id), str(as_ae.id)},
+ )
+
+ def test_assigned_to_user_matches_any_of_multiple_ids(self):
+ as_csm = create_account(team_id=self.team.id, name="CSM 7", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ as_ae = create_account(
+ team_id=self.team.id, name="AE 9", _properties={"account_executive": {"id": 9, "email": "[email protected]"}}
+ )
+ create_account(team_id=self.team.id, name="CSM 11", _properties={"csm": {"id": 11, "email": "[email protected]"}})
+ self.assertEqual(set(self._ids(assignedToUserIds=[7, 9])), {str(as_csm.id), str(as_ae.id)})
+
+ def test_assigned_to_user_is_independent_of_requesting_user(self):
+ # The ids are explicit, not the requester — a shared "my accounts" link
+ # resolves to the same accounts no matter which user opens it.
+ target = create_account(team_id=self.team.id, name="Target", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ create_account(team_id=self.team.id, name="Other", _properties={"csm": {"id": 8, "email": "[email protected]"}})
+ as_user = self._ids(user=self.user, assignedToUserIds=[7])
+ anonymous = self._ids(user=None, assignedToUserIds=[7])
+ self.assertEqual(as_user, [str(target.id)])
+ self.assertEqual(as_user, anonymous)
+
+ def test_assigned_to_user_unknown_id_matches_nothing(self):
+ create_account(team_id=self.team.id, name="Has CSM", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ self.assertEqual(self._ids(assignedToUserIds=[999999]), [])
+
+ def test_assigned_to_user_empty_ids_is_a_noop(self):
+ a = create_account(team_id=self.team.id, name="Has CSM", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ self.assertEqual(self._ids(assignedToUserIds=[]), [str(a.id)])
+
+ def test_assigned_to_user_combines_with_search(self):
+ match = create_account(team_id=self.team.id, name="Acme", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ create_account(team_id=self.team.id, name="Globex", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ self.assertEqual(self._ids(assignedToUserIds=[7], search="acme"), [str(match.id)])
+
+ def test_assigned_to_user_respects_team_isolation(self):
+ other_team = Team.objects.create(organization=self.organization)
+ create_account(team_id=other_team.id, name="Theirs", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ mine = create_account(team_id=self.team.id, name="Mine", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ self.assertEqual(self._ids(assignedToUserIds=[7]), [str(mine.id)])
+
+ def test_assigned_to_user_metrics_mode_counts_only_matching_accounts(self):
+ create_account(team_id=self.team.id, name="Mine", _properties={"csm": {"id": 7, "email": "[email protected]"}})
+ create_account(team_id=self.team.id, name="Theirs", _properties={"csm": {"id": 8, "email": "[email protected]"}})
+ runner = AccountsQueryRunner(
+ query=AccountsQuery(metrics=["count()"], select=[], assignedToUserIds=[7]),
+ team=self.team,
+ user=self.user,
+ )
+ response = runner.calculate()
+ self.assertEqual(response.metricsResults, [1])
+
+ def test_assigned_to_user_id_is_part_of_the_cache_key(self):
+ # Regression: "my accounts" must not collide in the query cache across users.
+ # The user id that selects the accounts rides in the query (assignedToUserIds),
+ # so it lands in get_cache_payload()["query"] and therefore in get_cache_key().
+ # (Pre-fix, the boolean assignedToCurrentUser was identical across users while
+ # the results differed by the server-resolved self.user.id, so one user's cached
+ # accounts could be served to another.)
+ runner_a = AccountsQueryRunner(query=AccountsQuery(assignedToUserIds=[1]), team=self.team, user=self.user)
+ runner_b = AccountsQueryRunner(query=AccountsQuery(assignedToUserIds=[2]), team=self.team, user=self.user)
+ self.assertEqual(runner_a.get_cache_payload()["query"]["assignedToUserIds"], [1])
+ self.assertNotEqual(runner_a.get_cache_key(), runner_b.get_cache_key())
+
def test_ordering_by_name_asc(self):
banana = create_account(team_id=self.team.id, name="Banana")
apple = create_account(team_id=self.team.id, name="Apple")
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
index b3b2f5f86a82..aa6ffb785e41 100644
--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md
+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
@@ -19,7 +19,7 @@ The scene renders `AccountsTabContent`, which binds one `dataNodeLogic` (key `AC
```text
AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, accountsLogic.hogqlQuery.source)
├── AccountsMaxTools registers the `open_account` Max contextual tool → accountsLogic.openAccount
-├── AccountsTabFilters search / tags / role filters / "unassigned only"
+├── AccountsTabFilters search / tags / role filters / "my accounts" / "unassigned only"
├── AccountsOverviewTilesButton + AccountsColumnConfigurator
├── AccountsOverviewTiles metric tiles across the filtered set
└── AccountsHogQLTable the DataTable; per-column renderers; controlled row expansion
@@ -44,7 +44,7 @@ AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, acc
## Data & query model
-`accountsLogic.hogqlQuery` builds a `DataTableNode` wrapping an `AccountsQuery` (`select`, plus optional `search`, `tagNames`, role filters, `allRolesUnassigned`, `filterExpression`, `metrics`, `orderBy`). The backend runner (`accounts_query_runner`) returns **rows as arrays** aligned to `visibleColumnNames`. Two cell shapes matter:
+`accountsLogic.hogqlQuery` builds a `DataTableNode` wrapping an `AccountsQuery` (`select`, plus optional `search`, `tagNames`, role filters, `allRolesUnassigned`, `assignedToUserIds`, `filterExpression`, `metrics`, `orderBy`). The backend runner (`accounts_query_runner`) returns **rows as arrays** aligned to `visibleColumnNames`. `assignedToUserIds` is the "assigned to" filter — a list of user ids the runner expands into `csm IN ids OR account_executive IN ids`. The "My accounts" checkbox is a client-side shortcut: `accountsLogic` resolves it to `[currentUserId]` (from `userLogic`) before the query is sent, so the backend only ever receives explicit ids and a shared URL resolves to the same accounts for every viewer. Two cell shapes matter:
- **`name` column** (mandatory, `ACCOUNTS_NAME_COLUMN`) — emitted as `tuple(name, external_id, id)`, read as `{ name, external_id, id }`. This is the row's identity: `id` (the account PK) drives expansion/scroll/role updates; `external_id` is the copy-able group key. `getNameCell()` in `AccountsHogQLTable.tsx` is the canonical accessor; never assume a column index.
- **role columns** (`csm`, `account_executive`, `account_owner`) — emitted as `tuple(id, email)`, rendered with `MemberSelect`. Sorting these uses `tupleElement(col, 2)` (email) so visual order matches.
@@ -61,7 +61,7 @@ The Usage tab renders an existing saved billing-usage insight — **point users
## Shareable view state
-`accountsLogic` mirrors the full view (search, tags, roles, unassigned, sort, columns, tile filter) into the URL hash `#view=...` via `actionToUrl`/`urlToAction`, so a copied URL reproduces the exact list. Only non-default values are serialized. A shared link's `columns` win over the per-user saved column config (`accountsColumnConfigLogic` enforces this when its async saved-config load resolves by checking the live URL).
+`accountsLogic` mirrors the full view (search, tags, roles, unassigned, assigned-to, sort, columns, tile filter) into the URL hash `#view=...` via `actionToUrl`/`urlToAction`, so a copied URL reproduces the exact list. Only non-default values are serialized. The "assigned to" filter persists as concrete `assignedTo` ids (not a `mine` flag), so a link shared with a colleague resolves to the **same** accounts for them as for the sharer; the legacy `mine: true` hash is still read and resolved to the current user's id for backward compatibility. A shared link's `columns` win over the per-user saved column config (`accountsColumnConfigLogic` enforces this when its async saved-config load resolves by checking the live URL).
## Max / agent integration
@@ -103,20 +103,20 @@ We track user actions on the Accounts list with `posthog.capture()`. Conventions
### Tracked events
-| Event | Fires from | Properties |
-| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `customer analytics accounts list viewed` | `accountsLogic` `afterMount` | _(none — funnel anchor; account count and saved-config aren't loaded at mount)_ |
-| `customer analytics accounts filter changed` | `accountsLogic` `reportFilterChange` listener (dispatched by the filter controls) | `filter_type` (`tag` \| `csm` \| `account_executive` \| `account_owner` \| `unassigned_only`), `value`, `is_cleared`, `active_filter_count`; for `tag` also `tag_count` |
-| `customer analytics accounts searched` | `accountsLogic` `setSearchInput` listener (post-debounce) | `query_length`, `has_query`, `active_filter_count` |
-| `customer analytics accounts refreshed` | `accountsLogic` `refresh` | `has_search`, `active_filter_count`, `sort_column` |
-| `customer analytics accounts sorted` | `accountsLogic` `toggleSort` | `column`, `direction` (`asc` \| `desc` \| `cleared`) |
-| `customer analytics accounts columns saved` | `accountsColumnConfigLogic` `saveColumns` (success, only when changed) | `column_count`, `columns`, `added_count`, `removed_count`, `reordered` |
-| `customer analytics accounts overview tiles edited` | `accountsOverviewTilesLogic` editor close (diffed vs open snapshot, only when changed) | `tiles_added`, `tiles_removed`, `tiles_updated`, `reordered`, `tile_count_before`, `tile_count_after` |
-| `customer analytics account role assigned` | `accountsLogic` `updateAccountRole` | `role` (`csm` \| `account_executive` \| `account_owner`), `is_assigned`, `assigned_user_id`, `source` (always `list_row` today) |
-| `customer analytics account link clicked` | `AccountNotebooksExpansion.tsx` useful-link `onClick` | `link_key`, `has_destination` |
-| `customer analytics account note clicked` | `AccountNotebooksExpansion.tsx` note `<Link>` `onClick` | `notebook_short_id` |
-| `customer analytics account tab viewed` | `accountsExpansionLogic` `setActiveTab` listener (genuine tab clicks only; programmatic `openAccountTab` navigation does not fire it) | `tab` (`notes` \| `users` \| `usage`) |
-| `customer analytics account related user clicked` | `AccountRelatedUsersExpansion.tsx` user `<Link>` `onClick` | _(none — customer end-user PII kept out)_ |
+| Event | Fires from | Properties |
+| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `customer analytics accounts list viewed` | `accountsLogic` `afterMount` | _(none — funnel anchor; account count and saved-config aren't loaded at mount)_ |
+| `customer analytics accounts filter changed` | `accountsLogic` `reportFilterChange` listener (dispatched by the filter controls) | `filter_type` (`tag` \| `csm` \| `account_executive` \| `account_owner` \| `unassigned_only` \| `my_accounts`), `value`, `is_cleared`, `active_filter_count`; for `tag` also `tag_count` |
+| `customer analytics accounts searched` | `accountsLogic` `setSearchInput` listener (post-debounce) | `query_length`, `has_query`, `active_filter_count` |
+| `customer analytics accounts refreshed` | `accountsLogic` `refresh` | `has_search`, `active_filter_count`, `sort_column` |
+| `customer analytics accounts sorted` | `accountsLogic` `toggleSort` | `column`, `direction` (`asc` \| `desc` \| `cleared`) |
+| `customer analytics accounts columns saved` | `accountsColumnConfigLogic` `saveColumns` (success, only when changed) | `column_count`, `columns`, `added_count`, `removed_count`, `reordered` |
+| `customer analytics accounts overview tiles edited` | `accountsOverviewTilesLogic` editor close (diffed vs open snapshot, only when changed) | `tiles_added`, `tiles_removed`, `tiles_updated`, `reordered`, `tile_count_before`, `tile_count_after` |
+| `customer analytics account role assigned` | `accountsLogic` `updateAccountRole` | `role` (`csm` \| `account_executive` \| `account_owner`), `is_assigned`, `assigned_user_id`, `source` (always `list_row` today) |
+| `customer analytics account link clicked` | `AccountNotebooksExpansion.tsx` useful-link `onClick` | `link_key`, `has_destination` |
+| `customer analytics account note clicked` | `AccountNotebooksExpansion.tsx` note `<Link>` `onClick` | `notebook_short_id` |
+| `customer analytics account tab viewed` | `accountsExpansionLogic` `setActiveTab` listener (genuine tab clicks only; programmatic `openAccountTab` navigation does not fire it) | `tab` (`notes` \| `users` \| `usage`) |
+| `customer analytics account related user clicked` | `AccountRelatedUsersExpansion.tsx` user `<Link>` `onClick` | _(none — customer end-user PII kept out)_ |
> **Keep this table up to date.** Whenever you add, rename, or remove a `posthog.capture()` event in the Accounts area — or change its properties — update this table in the same change. An agent reading this file should be able to trust it as the source of truth for what the Accounts list reports.
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.test.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.test.tsx
index 8153bf7d5307..461b4d5219ef 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.test.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.test.tsx
@@ -1,11 +1,14 @@
import '@testing-library/jest-dom'
-import { cleanup, render, screen } from '@testing-library/react'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { BindLogic, Provider } from 'kea'
+import { userLogic } from 'scenes/userLogic'
+
import { useMocks } from '~/mocks/jest'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { initKeaTests } from '~/test/init'
+import type { UserType } from '~/types'
import { ACCOUNTS_HOGQL_DATA_NODE_KEY } from '../../constants'
import { accountsLogic } from './accountsLogic'
@@ -68,4 +71,46 @@ describe('AccountsTabFilters', () => {
expect(screen.getByText('Any Owner')).toBeInTheDocument()
})
+
+ function myAccountsCheckbox(): HTMLInputElement {
+ return screen.getByText('My accounts').closest('.LemonCheckbox')!.querySelector('input')!
+ }
+
+ it('renders the "My accounts" checkbox', () => {
+ renderFilters()
+
+ expect(screen.getByText('My accounts')).toBeInTheDocument()
+ expect(myAccountsCheckbox().checked).toBe(false)
+ })
+
+ it('reflects a restored my-accounts filter as checked', () => {
+ userLogic.actions.loadUserSuccess({ id: 42 } as unknown as UserType)
+ logic.actions.setAssignedToCurrentUser(true)
+ renderFilters()
+
+ expect(myAccountsCheckbox().checked).toBe(true)
+ })
+
+ it('clicking it enables the my-accounts filter (resolved to the current user id)', () => {
+ userLogic.actions.loadUserSuccess({ id: 42 } as unknown as UserType)
+ renderFilters()
+
+ fireEvent.click(myAccountsCheckbox())
+
+ expect(logic.values.assignedToFilter).toEqual([42])
+ expect(logic.values.assignedToCurrentUser).toBe(true)
+ })
+
+ it('renders the "Assigned to" picker with its default label', () => {
+ renderFilters()
+
+ expect(screen.getByText('Assigned to anyone')).toBeInTheDocument()
+ })
+
+ it('reflects a restored assigned-to filter as a count', () => {
+ logic.actions.setAssignedToFilter([1, 2])
+ renderFilters()
+
+ expect(screen.getByText('Assigned to 2 people')).toBeInTheDocument()
+ })
})
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsx
index f8c9dbb18ac3..88d20ec8c2eb 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsx
@@ -11,13 +11,23 @@ import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { accountsLogic, RoleFilterValue } from './accountsLogic'
export function AccountsTabFilters(): JSX.Element {
- const { searchInput, tagsFilter, allRolesUnassigned, csmFilter, accountExecutiveFilter, accountOwnerFilter } =
- useValues(accountsLogic)
+ const {
+ searchInput,
+ tagsFilter,
+ allRolesUnassigned,
+ assignedToCurrentUser,
+ assignedToFilter,
+ csmFilter,
+ accountExecutiveFilter,
+ accountOwnerFilter,
+ } = useValues(accountsLogic)
const { responseLoading: accountsLoading } = useValues(dataNodeLogic)
const {
setSearchInput,
setTagsFilter,
setAllRolesUnassigned,
+ setAssignedToCurrentUser,
+ setAssignedToFilter,
setCsmFilter,
setAccountExecutiveFilter,
setAccountOwnerFilter,
@@ -103,6 +113,33 @@ export function AccountsTabFilters(): JSX.Element {
}}
dataAttr="accounts-owner-filter"
/>
+ <RolePicker
+ label="Assigned to"
+ value={assignedToFilter}
+ onChange={(value) => {
+ setAssignedToFilter(value)
+ reportFilterChange('assigned_to')
+ }}
+ dataAttr="accounts-assigned-to-filter"
+ formatButtonLabel={(count) =>
+ count === 0
+ ? 'Assigned to anyone'
+ : count === 1
+ ? 'Assigned to 1 person'
+ : `Assigned to ${count} people`
+ }
+ />
+ <LemonCheckbox
+ checked={assignedToCurrentUser}
+ onChange={(value) => {
+ setAssignedToCurrentUser(value)
+ reportFilterChange('my_accounts')
+ }}
+ label="My accounts"
+ info="Shortcut for Assigned to: you — accounts where you are the CSM or account executive"
+ disabledReason={accountsLoading ? 'Loading…' : undefined}
+ data-attr="accounts-my-accounts-filter"
+ />
<LemonCheckbox
checked={allRolesUnassigned}
onChange={(value) => {
@@ -136,14 +173,21 @@ function RolePicker({
value,
onChange,
dataAttr,
+ formatButtonLabel,
}: {
label: string
value: RoleFilterValue
onChange: (value: RoleFilterValue) => void
dataAttr: string
+ formatButtonLabel?: (count: number) => string
}): JSX.Element {
- const buttonLabel =
- value.length === 0 ? `Any ${label}` : value.length === 1 ? `1 ${label}` : `${value.length} ${label}s`
+ const buttonLabel = formatButtonLabel
+ ? formatButtonLabel(value.length)
+ : value.length === 0
+ ? `Any ${label}`
+ : value.length === 1
+ ? `1 ${label}`
+ : `${value.length} ${label}s`
return (
<div className="flex gap-1 items-center" data-attr={dataAttr}>
<LemonDropdown
diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts
index c0abcaecf33b..2b79754a1d62 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts
@@ -4,10 +4,11 @@ import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
import { urls } from 'scenes/urls'
+import { userLogic } from 'scenes/userLogic'
import type { AccountsQuery } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import type { UserBasicType } from '~/types'
+import type { UserBasicType, UserType } from '~/types'
import { accountsPartialUpdate, accountsRetrieve } from 'products/customer_analytics/frontend/generated/api'
import type { AccountApi } from 'products/customer_analytics/frontend/generated/api.schemas'
@@ -138,6 +139,139 @@ describe('accountsLogic', () => {
expect(logic.values.accountOwnerFilter).toEqual([])
})
+ describe('assignedTo filter and "my accounts" shortcut', () => {
+ const CURRENT_USER_ID = 42
+
+ beforeEach(() => {
+ userLogic.actions.loadUserSuccess(buildUser({ id: CURRENT_USER_ID }) as unknown as UserType)
+ })
+
+ it('starts disabled and adds nothing to the query', () => {
+ expect(logic.values.assignedToCurrentUser).toBe(false)
+ expect(logic.values.assignedToFilter).toEqual([])
+ expect((logic.values.hogqlQuery.source as AccountsQuery).assignedToUserIds).toBeUndefined()
+ })
+
+ it('the "My accounts" checkbox resolves to the current user id', () => {
+ logic.actions.setAssignedToCurrentUser(true)
+ expect(logic.values.assignedToFilter).toEqual([CURRENT_USER_ID])
+ expect(logic.values.assignedToCurrentUser).toBe(true)
+ expect((logic.values.hogqlQuery.source as AccountsQuery).assignedToUserIds).toEqual([CURRENT_USER_ID])
+ })
+
+ it('"My accounts" is checked only when the filter is exactly the current user', () => {
+ logic.actions.setAssignedToFilter([CURRENT_USER_ID])
+ expect(logic.values.assignedToCurrentUser).toBe(true)
+ logic.actions.setAssignedToFilter([99])
+ expect(logic.values.assignedToCurrentUser).toBe(false)
+ logic.actions.setAssignedToFilter([CURRENT_USER_ID, 99])
+ expect(logic.values.assignedToCurrentUser).toBe(false)
+ })
+
+ it('toggling the checkbox off clears the filter', () => {
+ logic.actions.setAssignedToCurrentUser(true)
+ logic.actions.setAssignedToCurrentUser(false)
+ expect(logic.values.assignedToFilter).toEqual([])
+ expect((logic.values.hogqlQuery.source as AccountsQuery).assignedToUserIds).toBeUndefined()
+ })
+
+ it('the Assigned to picker accepts explicit ids', () => {
+ logic.actions.setAssignedToFilter([7, 9])
+ expect(logic.values.assignedToFilter).toEqual([7, 9])
+ expect((logic.values.hogqlQuery.source as AccountsQuery).assignedToUserIds).toEqual([7, 9])
+ })
+
+ it('counts toward activeFilterCount', () => {
+ expect(logic.values.activeFilterCount).toBe(0)
+ logic.actions.setAssignedToFilter([7])
+ expect(logic.values.activeFilterCount).toBe(1)
+ })
+
+ it('enabling it clears the unassigned flag', async () => {
+ logic.actions.setAllRolesUnassigned(true)
+ logic.actions.setAssignedToFilter([7])
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.assignedToFilter).toEqual([7])
+ expect(logic.values.allRolesUnassigned).toBe(false)
+ })
+
+ it('enabling it clears the CSM and AE pickers but keeps the owner filter', async () => {
+ logic.actions.setCsmFilter([7])
+ logic.actions.setAccountExecutiveFilter([8])
+ logic.actions.setAccountOwnerFilter([9])
+ logic.actions.setAssignedToFilter([CURRENT_USER_ID])
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.assignedToFilter).toEqual([CURRENT_USER_ID])
+ expect(logic.values.csmFilter).toEqual([])
+ expect(logic.values.accountExecutiveFilter).toEqual([])
+ expect(logic.values.accountOwnerFilter).toEqual([9])
+ })
+
+ it('enabling the unassigned flag clears the assigned-to filter', async () => {
+ logic.actions.setAssignedToFilter([7])
+ logic.actions.setAllRolesUnassigned(true)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.allRolesUnassigned).toBe(true)
+ expect(logic.values.assignedToFilter).toEqual([])
+ })
+
+ it('selecting a CSM clears the assigned-to filter', async () => {
+ logic.actions.setAssignedToFilter([CURRENT_USER_ID])
+ logic.actions.setCsmFilter([7])
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.csmFilter).toEqual([7])
+ expect(logic.values.assignedToFilter).toEqual([])
+ })
+
+ it('selecting an AE clears the assigned-to filter', async () => {
+ logic.actions.setAssignedToFilter([CURRENT_USER_ID])
+ logic.actions.setAccountExecutiveFilter([8])
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.accountExecutiveFilter).toEqual([8])
+ expect(logic.values.assignedToFilter).toEqual([])
+ })
+
+ it('selecting an owner leaves the assigned-to filter intact', async () => {
+ logic.actions.setAssignedToFilter([CURRENT_USER_ID])
+ logic.actions.setAccountOwnerFilter([9])
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.accountOwnerFilter).toEqual([9])
+ expect(logic.values.assignedToFilter).toEqual([CURRENT_USER_ID])
+ })
+
+ it('persists concrete ids in the view hash (shareable, not viewer-relative)', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.setAssignedToCurrentUser(true)
+ }).toFinishAllListeners()
+ expect(router.values.hashParams.view).toEqual({ assignedTo: [CURRENT_USER_ID] })
+ })
+
+ it('restores the assigned-to filter from the view hash, independent of the viewer', async () => {
+ // A link shared by user 7 resolves to user 7's accounts for everyone —
+ // the checkbox is unchecked (not the current user) but the filter applies.
+ router.actions.push(urls.customerAnalyticsAccounts(), {}, { view: { assignedTo: [7] } })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.assignedToFilter).toEqual([7])
+ expect(logic.values.assignedToCurrentUser).toBe(false)
+ expect((logic.values.hogqlQuery.source as AccountsQuery).assignedToUserIds).toEqual([7])
+ })
+
+ it('restores a legacy mine=true link as the current user', async () => {
+ router.actions.push(urls.customerAnalyticsAccounts(), {}, { view: { mine: true } })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.assignedToFilter).toEqual([CURRENT_USER_ID])
+ expect(logic.values.assignedToCurrentUser).toBe(true)
+ })
+ })
+
describe('sortOrder', () => {
it('starts unset and produces no orderBy on the AccountsQuery', () => {
expect(logic.values.sortOrder).toBeNull()
diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts
index 2faaef84e07b..14d990fa17bc 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts
@@ -6,6 +6,7 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { objectsEqual } from 'lib/utils'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
+import { userLogic } from 'scenes/userLogic'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { AccountsQuery, DataTableNode, NodeKind } from '~/queries/schema/schema-general'
@@ -72,7 +73,14 @@ function normalizeRoleFilter(value: unknown): RoleFilterValue {
export type AccountRoleKey = 'csm' | 'account_executive' | 'account_owner'
-export type AccountFilterType = 'tag' | 'csm' | 'account_executive' | 'account_owner' | 'unassigned_only'
+export type AccountFilterType =
+ | 'tag'
+ | 'csm'
+ | 'account_executive'
+ | 'account_owner'
+ | 'unassigned_only'
+ | 'my_accounts'
+ | 'assigned_to'
// `column` matches the visible column name (alias-stripped) so any selected
// column can drive the sort.
@@ -113,6 +121,12 @@ export interface AccountsViewUrlState {
search?: string
tags?: string[]
unassigned?: boolean
+ /** Concrete user ids for the "Assigned to" / "My accounts" filter — explicit
+ * (not viewer-relative) so a shared link resolves identically for everyone. */
+ assignedTo?: number[]
+ /** @deprecated Legacy viewer-relative flag; still read so old shared links
+ * resolve to the opener's own id. Never written. */
+ mine?: boolean
csm?: number[]
accountExecutive?: number[]
accountOwner?: number[]
@@ -127,6 +141,8 @@ export const accountsLogic = kea<accountsLogicType>([
values: [
teamLogic,
['currentTeamId'],
+ userLogic,
+ ['user'],
accountsColumnConfigLogic,
['selectColumns', 'visibleColumnNames'],
accountsOverviewTilesLogic,
@@ -146,6 +162,10 @@ export const accountsLogic = kea<accountsLogicType>([
setSearchQuery: (query: string) => ({ query }),
setTagsFilter: (tags: string[]) => ({ tags }),
setAllRolesUnassigned: (value: boolean) => ({ value }),
+ setAssignedToFilter: (value: RoleFilterValue) => ({ value }),
+ // Shortcut for the "My accounts" checkbox — resolves to the current
+ // user's id and routes through setAssignedToFilter.
+ setAssignedToCurrentUser: (value: boolean) => ({ value }),
setCsmFilter: (value: RoleFilterValue) => ({ value }),
setAccountExecutiveFilter: (value: RoleFilterValue) => ({ value }),
setAccountOwnerFilter: (value: RoleFilterValue) => ({ value }),
@@ -197,6 +217,12 @@ export const accountsLogic = kea<accountsLogicType>([
setAllRolesUnassigned: (_, { value }) => value,
},
],
+ assignedToFilter: [
+ [] as RoleFilterValue,
+ {
+ setAssignedToFilter: (_, { value }) => value,
+ },
+ ],
csmFilter: [
[] as RoleFilterValue,
{
@@ -243,6 +269,15 @@ export const accountsLogic = kea<accountsLogicType>([
],
}),
selectors({
+ currentUserId: [(s) => [s.user], (user): number | null => user?.id ?? null],
+ // The "My accounts" checkbox is checked exactly when the assigned-to
+ // filter is just the current user — i.e. the user-agnostic id filter
+ // happens to point at you.
+ assignedToCurrentUser: [
+ (s) => [s.assignedToFilter, s.currentUserId],
+ (assignedToFilter: RoleFilterValue, currentUserId: number | null): boolean =>
+ currentUserId !== null && assignedToFilter.length === 1 && assignedToFilter[0] === currentUserId,
+ ],
isRoleSaving: [
(s) => [s.savingRoles],
(savingRoles: Record<string, true>) =>
@@ -257,6 +292,7 @@ export const accountsLogic = kea<accountsLogicType>([
s.accountExecutiveFilter,
s.accountOwnerFilter,
s.allRolesUnassigned,
+ s.assignedToFilter,
],
(
searchQuery: string,
@@ -264,7 +300,8 @@ export const accountsLogic = kea<accountsLogicType>([
csmFilter: RoleFilterValue,
accountExecutiveFilter: RoleFilterValue,
accountOwnerFilter: RoleFilterValue,
- allRolesUnassigned: boolean
+ allRolesUnassigned: boolean,
+ assignedToFilter: RoleFilterValue
): number =>
[
!!searchQuery.trim(),
@@ -273,6 +310,7 @@ export const accountsLogic = kea<accountsLogicType>([
accountExecutiveFilter.length > 0,
accountOwnerFilter.length > 0,
allRolesUnassigned,
+ assignedToFilter.length > 0,
].filter(Boolean).length,
],
viewUrlState: [
@@ -280,6 +318,7 @@ export const accountsLogic = kea<accountsLogicType>([
s.searchQuery,
s.tagsFilter,
s.allRolesUnassigned,
+ s.assignedToFilter,
s.csmFilter,
s.accountExecutiveFilter,
s.accountOwnerFilter,
@@ -291,6 +330,7 @@ export const accountsLogic = kea<accountsLogicType>([
searchQuery: string,
tagsFilter: string[],
allRolesUnassigned: boolean,
+ assignedToFilter: RoleFilterValue,
csmFilter: RoleFilterValue,
accountExecutiveFilter: RoleFilterValue,
accountOwnerFilter: RoleFilterValue,
@@ -309,6 +349,9 @@ export const accountsLogic = kea<accountsLogicType>([
if (allRolesUnassigned) {
state.unassigned = true
}
+ if (assignedToFilter.length > 0) {
+ state.assignedTo = assignedToFilter
+ }
if (csmFilter.length > 0) {
state.csm = csmFilter
}
@@ -335,6 +378,7 @@ export const accountsLogic = kea<accountsLogicType>([
s.searchQuery,
s.tagsFilter,
s.allRolesUnassigned,
+ s.assignedToFilter,
s.csmFilter,
s.accountExecutiveFilter,
s.accountOwnerFilter,
@@ -347,6 +391,7 @@ export const accountsLogic = kea<accountsLogicType>([
searchQuery: string,
tagsFilter: string[],
allRolesUnassigned: boolean,
+ assignedToFilter: RoleFilterValue,
csmFilter: RoleFilterValue,
accountExecutiveFilter: RoleFilterValue,
accountOwnerFilter: RoleFilterValue,
@@ -373,6 +418,9 @@ export const accountsLogic = kea<accountsLogicType>([
if (allRolesUnassigned) {
source.allRolesUnassigned = true
}
+ if (assignedToFilter.length > 0) {
+ source.assignedToUserIds = assignedToFilter
+ }
if (csmFilter.length > 0) {
source.csm = csmFilter
}
@@ -443,11 +491,23 @@ export const accountsLogic = kea<accountsLogicType>([
properties.value = values.allRolesUnassigned
properties.is_cleared = !values.allRolesUnassigned
break
+ case 'my_accounts':
+ properties.value = values.assignedToCurrentUser
+ properties.is_cleared = !values.assignedToCurrentUser
+ break
+ case 'assigned_to':
+ properties.value = values.assignedToFilter
+ properties.role_count = values.assignedToFilter.length
+ properties.is_cleared = values.assignedToFilter.length === 0
+ break
}
posthog.capture(AccountsEvents.FilterChanged, properties)
},
setAllRolesUnassigned: ({ value }) => {
if (value) {
+ if (values.assignedToFilter.length > 0) {
+ actions.setAssignedToFilter([])
+ }
if (values.csmFilter.length > 0) {
actions.setCsmFilter([])
}
@@ -459,14 +519,47 @@ export const accountsLogic = kea<accountsLogicType>([
}
}
},
+ // "My accounts" is a shortcut: filter by the current user's own id. The
+ // user-agnostic id then rides in the URL, so a shared link shows the
+ // sharer's accounts to whoever opens it (not the opener's own).
+ setAssignedToCurrentUser: ({ value }) => {
+ actions.setAssignedToFilter(value && values.currentUserId !== null ? [values.currentUserId] : [])
+ },
+ // "Assigned to" (an account's CSM or AE is one of these users) clears the
+ // unassigned flag (a genuine contradiction) and the CSM/AE pickers
+ // (ANDing an OR-over-both-roles shortcut with an explicit single-role
+ // pick is more confusing than useful). The owner picker stays orthogonal.
+ setAssignedToFilter: ({ value }) => {
+ if (value.length > 0) {
+ if (values.allRolesUnassigned) {
+ actions.setAllRolesUnassigned(false)
+ }
+ if (values.csmFilter.length > 0) {
+ actions.setCsmFilter([])
+ }
+ if (values.accountExecutiveFilter.length > 0) {
+ actions.setAccountExecutiveFilter([])
+ }
+ }
+ },
setCsmFilter: ({ value }) => {
- if (value.length > 0 && values.allRolesUnassigned) {
- actions.setAllRolesUnassigned(false)
+ if (value.length > 0) {
+ if (values.allRolesUnassigned) {
+ actions.setAllRolesUnassigned(false)
+ }
+ if (values.assignedToFilter.length > 0) {
+ actions.setAssignedToFilter([])
+ }
}
},
setAccountExecutiveFilter: ({ value }) => {
- if (value.length > 0 && values.allRolesUnassigned) {
- actions.setAllRolesUnassigned(false)
+ if (value.length > 0) {
+ if (values.allRolesUnassigned) {
+ actions.setAllRolesUnassigned(false)
+ }
+ if (values.assignedToFilter.length > 0) {
+ actions.setAssignedToFilter([])
+ }
}
},
setAccountOwnerFilter: ({ value }) => {
@@ -554,6 +647,9 @@ export const accountsLogic = kea<accountsLogicType>([
if (values.allRolesUnassigned) {
actions.setAllRolesUnassigned(false)
}
+ if (values.assignedToFilter.length > 0) {
+ actions.setAssignedToFilter([])
+ }
if (values.csmFilter.length > 0) {
actions.setCsmFilter([])
}
@@ -610,6 +706,7 @@ export const accountsLogic = kea<accountsLogicType>([
setSearchQuery: toUrl,
setTagsFilter: toUrl,
setAllRolesUnassigned: toUrl,
+ setAssignedToFilter: toUrl,
setCsmFilter: toUrl,
setAccountExecutiveFilter: toUrl,
setAccountOwnerFilter: toUrl,
@@ -642,6 +739,16 @@ export const accountsLogic = kea<accountsLogicType>([
actions.setAllRolesUnassigned(unassigned)
}
+ const assignedTo = normalizeRoleFilter(view.assignedTo)
+ // Back-compat: legacy links encoded the viewer-relative `mine: true`;
+ // resolve it to the opener's own id so old shared links still work.
+ const legacyMine =
+ !assignedTo.length && view.mine && values.currentUserId !== null ? [values.currentUserId] : []
+ const nextAssignedTo = assignedTo.length ? assignedTo : legacyMine
+ if (!objectsEqual(nextAssignedTo, values.assignedToFilter)) {
+ actions.setAssignedToFilter(nextAssignedTo)
+ }
+
const csm = normalizeRoleFilter(view.csm)
if (!objectsEqual(csm, values.csmFilter)) {
actions.setCsmFilter(csm)
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index e5cba3601828..2f6098a437ce 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -7192,6 +7192,8 @@ export interface AccountsQueryApi {
/** Match accounts whose account owner is any of these user ids (OR semantics). */
accountOwner?: number[] | null
allRolesUnassigned?: boolean | null
+ /** Match accounts where any of these user ids is the CSM or the account executive (OR over both roles). Drives the "My accounts" shortcut (the current user's id) and the shareable "Assigned to" filter — the ids are explicit so a shared URL resolves identically for every viewer. */
+ assignedToUserIds?: number[] | null
/** Match accounts whose CSM is any of these user ids (OR semantics). */
csm?: number[] | null
/** Optional HogQL boolean expression AND-ed into the WHERE clause. Used by the overview tile click-to-filter affordance. */
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index 01031e2e03e6..2a55c928e4ba 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -6727,6 +6727,8 @@ export interface AccountsQueryApi {
/** Match accounts whose account owner is any of these user ids (OR semantics). */
accountOwner?: number[] | null
allRolesUnassigned?: boolean | null
+ /** Match accounts where any of these user ids is the CSM or the account executive (OR over both roles). Drives the "My accounts" shortcut (the current user's id) and the shareable "Assigned to" filter — the ids are explicit so a shared URL resolves identically for every viewer. */
+ assignedToUserIds?: number[] | null
/** Match accounts whose CSM is any of these user ids (OR semantics). */
csm?: number[] | null
/** Optional HogQL boolean expression AND-ed into the WHERE clause. Used by the overview tile click-to-filter affordance. */
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 7f01eefe0cdd..72e6c9b7cbfc 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -514,6 +514,8 @@ export namespace Schemas {
/** Match accounts whose account owner is any of these user ids (OR semantics). */
accountOwner?: number[] | null;
allRolesUnassigned?: boolean | null;
+ /** Match accounts where any of these user ids is the CSM or the account executive (OR over both roles). Drives the "My accounts" shortcut (the current user's id) and the shareable "Assigned to" filter — the ids are explicit so a shared URL resolves identically for every viewer. */
+ assignedToUserIds?: number[] | null;
/** Match accounts whose CSM is any of these user ids (OR semantics). */
csm?: number[] | null;
/** Optional HogQL boolean expression AND-ed into the WHERE clause. Used by the overview tile click-to-filter affordance. */