[fix] Switch organizations, not workspaces, in the mobile switcher [AGE-4181] - #6247
[fix] Switch organizations, not workspaces, in the mobile switcher [AGE-4181]#6247ardaerzin wants to merge 4 commits into
Conversation
…itcher Every organization's default workspace is named "Default", so the /m drawer's second panel rendered one indistinguishable "Default" row per org. A multi-org account had no way to tell them apart, which read as "the organization does not switch on mobile" — the trigger already named the org, only the list did not. Group by organization instead (groupByOrganization), label rows with the org name, and say "Switch organization" like the desktop rail. The workspace stays in the URL: each project row now routes with its OWN workspace id, so an org with several workspaces switches correctly too. Fixes #6228
The desktop hides demo projects everywhere (projectsAtom) and prefers a non-demo project post-login. /m applied neither, so an account with a demo org could sign in on a phone and be resolved straight into a demo project the desktop never offers, with the demo org sitting in the switcher next to the real ones. Move filterOutDemoProjects into @agenta/entities/project — one implementation both shells share, rather than a second copy — and apply it at /m's fetch boundary, so the context resolver, the switcher, and post-sign-in landing all agree with the desktop. Refs #6228
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughSummary by CodeRabbit
WalkthroughThe change adds shared demo-project filtering and changes mobile project switching from workspace groups to organization groups. Organization groups aggregate projects across workspaces and preserve workspace-aware project routing. ChangesMobile project navigation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The mobile switcher now groups projects by organization, preserves workspace-specific routing, and hides demo projects consistently with desktop behavior. No actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant MobileProjectContext
participant groupByOrganization
participant DrawerProjectSwitcher
participant ProjectOrgSwitcherView
MobileProjectContext->>groupByOrganization: provide filtered projects
groupByOrganization->>DrawerProjectSwitcher: return organization groups
DrawerProjectSwitcher->>ProjectOrgSwitcherView: render organization entries
ProjectOrgSwitcherView->>DrawerProjectSwitcher: select organization or project
DrawerProjectSwitcher->>MobileProjectContext: navigate with project and workspace IDs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: c7066b37-dc12-4647-bde8-d7578198d3e9
📒 Files selected for processing (7)
web/mobile/src/features/context/workspaceGroups.tsweb/mobile/src/features/nav/DrawerProjectSwitcher.tsxweb/mobile/src/lib/context.tsweb/mobile/tests/unit/workspaceGroups.test.tsweb/oss/src/state/project/selectors/project.tsweb/packages/agenta-entities/src/project/demo.tsweb/packages/agenta-entities/src/project/index.ts
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Railway Preview Environment
|
Review catch: an organization whose FIRST project row carried no name kept the
fallback label even when a later row supplied the real one. Reproduced in a
test, along with a second case the same shape — a blank name ("") slipped past
`??` and rendered an empty switcher row.
Both come from one habit: group-level fields were read off whichever row
happened to arrive first. Restructure so grouping buckets the rows first, then
resolves every group field across the WHOLE bucket. Names go through a
firstNonBlank helper, so blank is treated as missing rather than as a name.
Along the way:
- RoutableProject makes "has a workspace, so it can be routed to" a type, not a
guard repeated per grouper. Project rows no longer need a workspace_id
fallback at the call site.
- OrganizationGroup.key is now separate from organizationId, which stays null
for a workspace-keyed row instead of holding a synthetic "workspace:<id>".
- OrganizationGroup.workspaceId comes from the group's first project, so the
workspace an org row enters cannot disagree with the project it lands on.
- WorkspaceGroup drops workspaceName and organizationName. Nothing reads them
since the switcher moved to groupByOrganization, and leaving display fields on
a routing-only type is what invited the first-row bug.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
web/mobile/src/features/context/workspaceGroups.ts (1)
6-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReduce the new multi-line comments.
Keep only short comments for non-obvious constraints. Remove comments that restate the code or product rationale.
web/mobile/src/features/context/workspaceGroups.ts#L6-L9: Reduce this routing explanation to one short constraint comment.web/mobile/src/features/context/workspaceGroups.ts#L52-L59: Reduce this grouping rationale to one short constraint comment.web/mobile/src/features/nav/DrawerProjectSwitcher.tsx#L93-L94: Remove or shorten this implementation-history comment.web/mobile/src/features/nav/DrawerProjectSwitcher.tsx#L108-L109: Remove or shorten this UI-description comment.web/mobile/tests/unit/workspaceGroups.test.ts#L89-L91: Remove or shorten this test-behavior comment.As per coding guidelines, “Keep in-code comments to at most one short line; use longer comments only for genuinely surprising constraints such as bugs, races, or ordering requirements.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 80f3f6be-2c0f-4b98-b5a5-e5f1bbc6cf30
📒 Files selected for processing (4)
web/mobile/src/features/context/workspaceGroups.tsweb/mobile/src/features/nav/DrawerProjectSwitcher.tsxweb/mobile/tests/unit/contextTarget.test.tsweb/mobile/tests/unit/workspaceGroups.test.ts
💤 Files with no reviewable changes (1)
- web/mobile/tests/unit/contextTarget.test.ts
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
web/CLAUDE.md caps in-code comments at one short line. The blocks added in the previous two commits narrated rationale in prose instead. Cut to one line each, keeping only the constraints that are not visible in the code. Leaves the two pre-existing comments in DrawerProjectSwitcher alone. They are untouched by this PR and rewriting them here would be unrelated diff noise.
Context
Signing in from a phone appeared not to work, and the reporter could not switch organization or project once inside
/m. Switching the browser to desktop mode was the workaround.Sign-in itself is fine. I verified sign-up, sign-in, sign-out, re-sign-in and the OIDC callback handback on
/magainst a local EE stack, and they all work. The real problem is that a multi-org account lands in one organization on mobile and has no usable way out, which is what "signing in does not work" felt like. Two separate causes:The switcher listed workspaces, not organizations. Every organization's default workspace is named
Default, soDrawerProjectSwitcherrendered one identicalDefaultrow per org. The trigger already named the organization. Only the list did not, so the rows were indistinguishable and picking one was a coin flip./mnever hid demo projects. The desktop hides them everywhere (projectsAtom) and prefers a non-demo project after login (postLoginRedirect.ts)./mapplied neither, so a demo organization sat in the switcher next to the real ones and could winselectContextTarget's post-sign-in resolution, dropping the user into a project the desktop never offers.Changes
The mobile switcher now groups by organization instead of workspace.
groupByOrganizationinworkspaceGroups.tskeys onorganization_id, labels each row with the organization name, and collects every one of that org's projects across all its workspaces. The panel says "Switch organization" like the desktop rail.The workspace still lives in the URL, so each project row now routes with its own
workspace_idrather than the currently active one. That makes an organization with several workspaces switch correctly too.groupByWorkspacestays untouched, because context resolution is workspace-keyed to match/w/:workspace_id/p/:project_id.Before, in a two-org account:
After:
For the demo projects,
filterOutDemoProjectsmoved out ofoss/src/state/project/selectors/project.tsinto@agenta/entities/project, so both shells share one implementation instead of growing a second copy. It is generic over the row type so/m's zod-inferredMobileProjectkeeps its own shape./mapplies it at the fetch boundary inlib/context.ts, which covers the context resolver, the switcher and post-sign-in landing in one place. OSS keeps a re-export, so nothing there changes behavior.Tests
pnpm --filter @agenta/mobile test: 128 pass, including 4 new cases forgroupByOrganization(org naming, multi-workspace collection, unroutable rows, org-less fallback).tscclean on@agenta/mobileand@agenta/oss; lint clean on every touched file.projectsDemoFilter.test.tsstill passes against the relocated function.sec-ch-ua-mobile: ?1, using a two-org account: sign-up, sign-in, sign-out, re-sign-in, organization switch in both directions, project switch, and reload continuity. The demo path was proven by flippingproject_members.is_demoin Postgres and back.What to QA
Needs an account in two or more organizations. Open the site on a phone, or force the gate with an iPhone user agent plus
sec-ch-ua-mobile: ?1./m. Open the drawer, tap the switcher at the bottom, then "Switch organization". The list shows organization names with distinct avatars, not repeatedDefaultrows.Fixes #6228