Skip to content

refactor(groups): split useUserGroups' {all} boolean into two queries - #515

Merged
chiptus merged 3 commits into
mainfrom
refactor/UPL-16/split-user-groups-query
Oct 1, 2026
Merged

chiptus merged 3 commits into
mainfrom
refactor/UPL-16/split-user-groups-query

Conversation

@chiptus

@chiptus chiptus commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Splits useUserGroups' { all } boolean (which flipped both the admin-gating and is_member semantics behind one flag) into useMyGroupsQuery (always member-scoped, is_member always true) and useAllGroupsQuery (admin view, falling back to the exact member-only result for non-admins). All call sites moved to the member-only hook except the Groups page's admin toggle, which now renders one of two sibling components instead of threading the boolean into a shared hook.

UPL-16

Verification

  • Sign in as a regular user and open /groups — your groups list renders the same as before.
  • As an admin, toggle "My Groups" / "All Groups" on /groups — behaves identically to before the split, including membership badges on the all-groups view.
  • As a non-admin hitting the all-groups view (e.g. via the toggle if visible), you still only ever see your own groups — never an error or a leaked full group list.
  • pnpm run typecheck, pnpm run lint, and pnpm test all pass.
  • New useMyGroups.integration.test.ts / useAllGroups.integration.test.ts cover both paths (run via pnpm run test:integration against a local Supabase instance).

🤖 Generated with Claude Code

https://claude.ai/code/session_015AWdzYUiNjQwtASYbWTnaX


Generated by Claude Code

…odules

fetchUserGroups(userId, { all }) flipped both the auth model (admin-gated)
and the is_member semantics behind one flag. Splits it into
useMyGroupsQuery (always member-scoped, is_member always true) and
useAllGroupsQuery (admin view, falling back to the member-only result for
non-admins). The Groups page's My/All toggle now renders one of two
sibling components instead of threading the boolean into a shared hook.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015AWdzYUiNjQwtASYbWTnaX
Copilot AI balanced review requested due to automatic review settings September 30, 2026 05:21
@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
upline Ready Ready Preview Oct 1, 2026 3:01pm UTC

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Regular admins are shown the all-groups view but are treated as non-admins by the new query.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Splits group fetching into member-scoped and administrative queries, updating consumers, cache invalidation, and integration coverage.

Changes:

  • Adds useMyGroupsQuery and useAllGroupsQuery.
  • Migrates group consumers and query keys.
  • Adds Supabase integration fixtures and tests.
File Description
src/​test/​integration/​fixtures/​groups.ts Adds group fixtures.
src/​test/​integration/​fixtures/​adminRoles.ts Supports configurable admin roles.
src/​routes/​groups/​index.tsx Selects the appropriate group query.
src/​routes/​__root.tsx Prefetches member groups.
src/​pages/​Settings/​SettingsPage.tsx Uses the member query.
src/​pages/​SetDetails/​SetGroupVoting.tsx Uses the member query.
src/​pages/​EditionView/​tabs/​VoteTab/​AuthedFilteredSetsPanel.tsx Uses the member query.
src/​contexts/​ActiveScopeContext.tsx Reads member groups.
src/​components/​layout/​AppHeader/​GroupsIndicator.tsx Reads member groups.
src/​api/​groups/​useUserGroups.ts Removes the combined query.
src/​api/​groups/​useMyGroups.ts Implements member-scoped fetching.
src/​api/​groups/​useMyGroups.integration.test.ts Tests member-group behavior.
src/​api/​groups/​useLeaveGroup.ts Invalidates both new query keys.
src/​api/​groups/​useJoinGroup.ts Invalidates both new query keys.
src/​api/​groups/​useDeleteGroup.ts Invalidates all group queries.
src/​api/​groups/​useCreateGroup.ts Invalidates all group queries.
src/​api/​groups/​useAllGroups.ts Implements privileged group fetching.
src/​api/​groups/​useAllGroups.integration.test.ts Tests fallback and super-admin behavior.
src/​api/​groups/​types.ts Defines separate query keys.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/api/groups/useAllGroups.ts Outdated
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Playwright test results

passed  68 passed

Details

stats  68 tests across 22 suites
duration  1 minute, 32 seconds
commit  e4a62ab

Comment thread src/api/groups/useAllGroups.ts Outdated
Comment thread src/api/groups/useMyGroups.ts Outdated
Comment thread src/api/groups/useMyGroups.ts Outdated

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The split preserves access semantics, updates all callers and invalidations, and includes focused integration coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

}

// If not found as a member, check if user is the creator
// Not a member: let `groups` RLS decide (creator, or super admin who can read every group)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

remove comment

@chiptus
chiptus merged commit 12bf952 into main Oct 1, 2026
10 checks passed
@chiptus
chiptus deleted the refactor/UPL-16/split-user-groups-query branch October 1, 2026 15:08

This branch was successfully deployed

1 active deployment
Preview — e4a62abc Deployed Oct 1, 2026 by vercel[bot]
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.

3 participants