Skip to content

fix: fetching classes and class users separately, then aggregating students client-side#4737

Merged
vinaypanduga merged 1 commit into
mainfrom
main-ng-9
Jul 16, 2026
Merged

fix: fetching classes and class users separately, then aggregating students client-side#4737
vinaypanduga merged 1 commit into
mainfrom
main-ng-9

Conversation

@narayanangourav-sutara

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist gemini-code-assist 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.

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.

Comment on lines 129 to 134
roles.includes(role),
);
setCanModify(
schoolMatches &&
(normalizedRole === RoleType.PRINCIPAL || hasSubjectModificationRole),
hasSubjectModificationRole ||
(schoolMatches && normalizedRole === RoleType.PRINCIPAL),
);

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.

high

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.

Suggested change
roles.includes(role),
);
setCanModify(
schoolMatches &&
(normalizedRole === RoleType.PRINCIPAL || hasSubjectModificationRole),
hasSubjectModificationRole ||
(schoolMatches && normalizedRole === RoleType.PRINCIPAL),
);
roles?.includes(role),
);
setCanModify(
hasSubjectModificationRole ||
(schoolMatches && normalizedRole === RoleType.PRINCIPAL),
);

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@vinaypanduga
vinaypanduga merged commit 9b13c45 into main Jul 16, 2026
1 check passed
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