fix: fetching classes and class users separately, then aggregating students client-side#4737
Conversation
…udents client-side
There was a problem hiding this comment.
Code Review
This pull request refactors the campaign audience summary retrieval by replacing complex client-side query and processing logic with a Supabase RPC call get_campaign_audience_summary, simplifying the SupabaseApi implementation and updating the database types accordingly. Additionally, it adjusts the permission logic in SubjectSelection.tsx. A review comment suggests using optional chaining when checking roles to prevent potential runtime errors when the roles array is undefined.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| roles.includes(role), | ||
| ); | ||
| setCanModify( | ||
| schoolMatches && | ||
| (normalizedRole === RoleType.PRINCIPAL || hasSubjectModificationRole), | ||
| hasSubjectModificationRole || | ||
| (schoolMatches && normalizedRole === RoleType.PRINCIPAL), | ||
| ); |
There was a problem hiding this comment.
The roles array destructured from the auth state can potentially be undefined or null (as indicated by the fallback const userRoles = roles || []; on line 99). Accessing roles.includes(role) directly inside the useEffect hook without a safety guard can lead to a runtime TypeError if roles is not yet loaded.
Using optional chaining roles?.includes(role) ensures the application does not crash during initialization or when the auth state is loading.
| roles.includes(role), | |
| ); | |
| setCanModify( | |
| schoolMatches && | |
| (normalizedRole === RoleType.PRINCIPAL || hasSubjectModificationRole), | |
| hasSubjectModificationRole || | |
| (schoolMatches && normalizedRole === RoleType.PRINCIPAL), | |
| ); | |
| roles?.includes(role), | |
| ); | |
| setCanModify( | |
| hasSubjectModificationRole || | |
| (schoolMatches && normalizedRole === RoleType.PRINCIPAL), | |
| ); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b99efc033c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .in('grade_id', gradeIds) | ||
| .eq('is_deleted', false); | ||
| const { data, error } = await this.supabase.rpc( | ||
| 'get_campaign_audience_summary', |
There was a problem hiding this comment.
Add the missing campaign audience summary RPC
This new code makes every campaign audience summary depend on the get_campaign_audience_summary RPC, but this commit only adds the TypeScript declaration; a repo-wide rg "get_campaign_audience_summary" finds no SQL/migration/function definition outside this call and the type entry. In any environment that has not had this function created manually, Supabase will return an RPC-not-found error, this method falls back to { totalStudents: 0, grades: [] }, and the campaign setup UI treats the selected audience as having 0 students and blocks progression. Please include the DB function/migration or keep the client-side path until the RPC is deployed.
Useful? React with 👍 / 👎.
No description provided.