Skip to content

fix: take attendance/ edit attendance#1172

Open
corypride wants to merge 1 commit into
mainfrom
cpride/dynamic_attendance_label
Open

fix: take attendance/ edit attendance#1172
corypride wants to merge 1 commit into
mainfrom
cpride/dynamic_attendance_label

Conversation

@corypride

Copy link
Copy Markdown
Contributor

Pre-Submission PR Checklist

  • No debug/console/fmt.Println statements
  • Unnecessary development comments removed
  • All acceptance criteria verified
  • Functions according to ticket specifications
  • Tested manually where applicable
  • Branch rebased with latest main
  • No business logic exists within the database layer

Description of the change

After taking attendance for a class session on the Facility Dashboard, the "Take Attendance" button gave no visual indication that action had already been taken. This change makes the button dynamically reflect the real attendance state for each session in Today's Schedule.

  • Sessions with no attendance recorded show a green "Take Attendance" button (existing style, unchanged)
  • Sessions where attendance has already been taken show a gray outline "Edit Attendance" button, matching the style used in the Sessions Tab within Class Detail

Implementation: GetTodaysSchedule() now calls the existing GetAttendanceCountsForEvents() DB function (already used by the missing-attendance flow) after building the schedule item list, and sets a new has_attendance field on each item. The frontend button renders conditionally based on that field. No new DB queries, no migration needed.

  • Related issues: Link to related Asana ticket that this closes.
    Asana Task

Screenshot(s)

image

@corypride corypride requested a review from a team as a code owner June 12, 2026 18:03
@corypride corypride requested review from carddev81 and removed request for a team June 12, 2026 18:03
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Attendance buttons in the schedule now dynamically reflect status, showing "Edit Attendance" when attendance is already recorded or "Take Attendance" when no attendance exists
    • Button styling updates to visually indicate the current attendance state for each class

Walkthrough

This PR adds a has_attendance boolean field to schedule items that tracks whether an attendance record exists. The backend model and frontend type are updated, the service layer enriches items by querying attendance counts, and the Dashboard button conditionally renders "Edit Attendance" or "Take Attendance" based on the field value.

Changes

Attendance Status in Schedule Items

Layer / File(s) Summary
Data model contracts
backend/src/models/program_classes.go, frontend/src/types/program.ts
TodaysScheduleItem struct and interface both add a has_attendance boolean field for API serialization and frontend type safety.
Backend attendance enrichment
backend/src/services/classes.go
GetTodaysSchedule queries attendance counts for schedule items' event and date pairs, builds a lookup map, and populates the HasAttendance field on each item; query errors are ignored without propagating.
Frontend attendance button rendering
frontend/src/pages/Dashboard.tsx
The attendance button text and styling change based on item.has_attendance: "Edit Attendance" with outline variant when true, otherwise "Take Attendance" with default variant.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding dynamic button text that displays 'Take Attendance' or 'Edit Attendance' based on whether attendance has been recorded.
Description check ✅ Passed The description provides clear context about the problem, the solution, and implementation details that directly relate to the changeset across backend and frontend files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/services/classes.go`:
- Around line 346-355: The current code silently ignores errors from
svc.db.GetAttendanceCountsForEvents which can lead to incorrect HasAttendance
values; change the handler to propagate the error instead of swallowing it:
check the returned err from svc.db.GetAttendanceCountsForEvents (called as
attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(...)) and if err !=
nil return that error (or wrap it with context) so the caller can handle it;
only run the map population and set items[i].HasAttendance when err == nil and
attendanceCounts is valid. Ensure you reference
svc.db.GetAttendanceCountsForEvents, attendanceCounts, items and HasAttendance
when updating the implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5df29b79-ce0d-494a-8c2d-279cd2f2735e

📥 Commits

Reviewing files that changed from the base of the PR and between 1f0c08e and 70e4267.

📒 Files selected for processing (4)
  • backend/src/models/program_classes.go
  • backend/src/services/classes.go
  • frontend/src/pages/Dashboard.tsx
  • frontend/src/types/program.ts

Comment on lines +346 to +355
attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates)
if err == nil {
taken := make(map[string]bool)
for _, ac := range attendanceCounts {
taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true
}
for i, item := range items {
items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)]
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t silently ignore attendance enrichment DB failures.

Line 347 currently drops the error path, which can return incorrect has_attendance state and mislabel buttons in the dashboard. Handle the failure explicitly (prefer returning an error here).

Proposed fix
 		attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates)
-		if err == nil {
-			taken := make(map[string]bool)
-			for _, ac := range attendanceCounts {
-				taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true
-			}
-			for i, item := range items {
-				items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)]
-			}
-		}
+		if err != nil {
+			return nil, fmt.Errorf("get attendance counts for today's schedule: %w", err)
+		}
+		taken := make(map[string]bool, len(attendanceCounts))
+		for _, ac := range attendanceCounts {
+			taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true
+		}
+		for i, item := range items {
+			items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)]
+		}
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates)
if err == nil {
taken := make(map[string]bool)
for _, ac := range attendanceCounts {
taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true
}
for i, item := range items {
items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)]
}
}
attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates)
if err != nil {
return nil, fmt.Errorf("get attendance counts for today's schedule: %w", err)
}
taken := make(map[string]bool, len(attendanceCounts))
for _, ac := range attendanceCounts {
taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true
}
for i, item := range items {
items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)]
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/services/classes.go` around lines 346 - 355, The current code
silently ignores errors from svc.db.GetAttendanceCountsForEvents which can lead
to incorrect HasAttendance values; change the handler to propagate the error
instead of swallowing it: check the returned err from
svc.db.GetAttendanceCountsForEvents (called as attendanceCounts, err :=
svc.db.GetAttendanceCountsForEvents(...)) and if err != nil return that error
(or wrap it with context) so the caller can handle it; only run the map
population and set items[i].HasAttendance when err == nil and attendanceCounts
is valid. Ensure you reference svc.db.GetAttendanceCountsForEvents,
attendanceCounts, items and HasAttendance when updating the implementation.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant