Skip to content

feat(fe): teams pickers send the active organizationId (DEV-2566 step 1) - #2458

Open
vecchp wants to merge 1 commit into
mainfrom
feat/fe-teams-payload-org
Open

vecchp wants to merge 1 commit into
mainfrom
feat/fe-teams-payload-org

Conversation

@vecchp

@vecchp vecchp commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Mobile-first split of #2450 (feat/perm/teams-header-strip) — see the rollout audit on #2457. Jira: DEV-2566.

Why this lands first

The backend half of #2450 retires the X-Organization-ID header — any released app build that still reads as header-only would get You do not have access to this organization. on the teams query the moment that deploys (and teams power the TaskForm picker). The app can't be redeployed instantly, so the client change ships first:

What changes

useOrgTeams reads the active-org store reactively (useSyncExternalStore over getActiveOrgId / subscribeActiveOrgId — the same store the header interceptor read) and sends it as TeamFilter.organizationId. The query is skipped while no org is active (none remembered, or the user has none) instead of issuing a request the backend would deny.

Why it's safe against today's backend

Rollout

  1. This PR → publish via EAS Update targeting the current runtimeVersion (or the next store build if the runtime moved).
  2. Once the build is live and adopted: land feat(perm): retire the X-Organization-ID header — mobile teams cutover (DEV-2566) #2450's backend retirement (header + middleware deleted) and then chore(fe): stop sending the retired X-Organization-ID header #2452 (interceptor removal). Neither should deploy before step 1 is in users' hands.

Notes

Summary by Sourcery

Scope team picker queries to the active organization and avoid unauthorized requests when no organization is selected.

New Features:

  • Send the active organization ID in team query filters so teams are scoped to the organization shown in the UI.
  • Keep team queries idle when no organization is active.

Enhancements:

  • Reactively synchronize team queries with the active-organization store, including remembered organizations before the organization list loads.

Tests:

  • Update team hook coverage to verify organization IDs in request variables, remembered-organization behavior, and no-request behavior without an active organization.

Splits the mobile half of #2450 out to ship first: useOrgTeams reads the
active-org store reactively and sends TeamFilter.organizationId, and stays
idle while no org is known.  Safe against today's backend — the teams read
prefers the filter and falls back to the still-live X-Organization-ID
header — so old and new binaries both work until the header retirement
lands, once this build is deployed.

The header interceptor keeps sending the header (removal is #2452); the
backend retirement follows in #2450 after adoption.  #2450 drops its FE
hunks when rebasing onto this.

Verified: tsc (lib + spec), eslint, prettier; vitest runs in CI.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @vecchp, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The PR moves teams organization scoping from implicit header reliance to the active organization ID in GraphQL filter variables, using a reactive store subscription and skipping unscoped requests. Tests validate remembered/current organization selection, request-time consistency, early loading behavior, and the no-active-organization case.

Sequence diagram for organization-scoped teams queries

sequenceDiagram
    participant Store as ActiveOrgStore
    participant Hook as useOrgTeams
    participant Apollo as ApolloClient
    participant Backend as TeamsAPI

    Store->>Hook: subscribeActiveOrgId()
    Store-->>Hook: getActiveOrgId()
    Hook->>Apollo: useQuery(TeamsDocument, variables.filters.organizationId)
    Apollo->>Backend: Teams request with organizationId
    Backend-->>Apollo: Teams result
    Apollo-->>Hook: teams, loading, error

    alt no active organization
        Hook->>Apollo: skip query
    end
Loading

Flow diagram for active-organization teams query gating

flowchart TD
    A[Active organization store changes] --> B[useSyncExternalStore reads activeOrgId]
    B --> C{activeOrgId exists?}
    C -->|Yes| D[useQuery with filters.organizationId]
    D --> E[Teams API returns scoped teams]
    C -->|No| F[Query skipped; remain idle]
Loading

File-Level Changes

Change Details Files
Scopes teams queries with the reactively tracked active organization ID and avoids querying without one.
  • Subscribes to active-organization store updates via useSyncExternalStore.
  • Adds filters.organizationId to generated query variables.
  • Skips the query when no active organization is available while preserving pagination and activity filters.
libs/expo/betterangels/src/lib/hooks/useOrgTeams/useOrgTeams.ts
Updates hook coverage to verify organization IDs are attached to requests and idle behavior is enforced.
  • Records operation variables and store state at the Apollo link.
  • Verifies active and remembered organizations, including before organization-list loading completes.
  • Adds coverage confirming no request is issued when no organization is active.
libs/expo/betterangels/src/lib/hooks/useOrgTeams/useOrgTeams.test.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

🚀 Expo continuous deployment is ready for betterangels!

  • Project → betterangels
  • Environment → Preview
  • Platforms → android, ios
  • Scheme → betterangels
  🤖 Android 🍎 iOS
Runtime Version 4d84f3f87051ebb9c1713e7e2d4522e4b23135d9 4d84f3f87051ebb9c1713e7e2d4522e4b23135d9
Build Details Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview
Runtime version: 4d84f3f87051ebb9c1713e7e2d4522e4b23135d9
App version: 1.2.11
Git commit: a1900145e6c2315da5a85930acd4fcf2f8619aa2
Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview
Runtime version: 4d84f3f87051ebb9c1713e7e2d4522e4b23135d9
App version: 1.2.11
Git commit: a1900145e6c2315da5a85930acd4fcf2f8619aa2
Update Details Update Permalink
DetailsBranch: feat-fe-teams-payload-org
Runtime version: 4d84f3f87051ebb9c1713e7e2d4522e4b23135d9
Git commit: c3a00bf6964f58e8bb4b382556ef01e589e4a6ea
Update Permalink
DetailsBranch: feat-fe-teams-payload-org
Runtime version: 4d84f3f87051ebb9c1713e7e2d4522e4b23135d9
Git commit: c3a00bf6964f58e8bb4b382556ef01e589e4a6ea
Update QR

iOS Simulator Build: Simulator Build Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants