kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Implement AttendanceEditPage — edit existing attendance session

Open akolson opened this issue 9 months ago • 4 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Implement AttendanceEditPage — allows coaches to update attendance records for a previously saved session. The page loads the existing session, pre-populates the learner toggles, tracks changes against the original state, and prompts for confirmation before saving. Builds on the stub added in #14236 and shares the same learner table pattern as AttendanceNewPage (#14242).

Complexity: Medium Target branch: release-v0.19.x

Context

Once a session is saved, coaches can revisit it from AttendanceHistoryPage to correct mistakes or update records. AttendanceEditPage is structurally similar to AttendanceNewPage — the key differences are that it loads existing data on mount, tracks which records have changed, and requires confirmation before saving to prevent accidental overwrites.

The Change

AttendanceEditPage (kolibri/plugins/coach/frontend/views/attendance/AttendanceEditPage.vue):

  • CoachImmersivePage with H1 showing the session date/time (from session_start_datetime, formatted via formatAttendanceDateTime); shows KCircularLoader while session is loading
  • Learner table — same structure as AttendanceNewPage: searchable, paginated at 50 per page, sorted alphabetically, per-learner KSwitch, "Mark all present" toggle with KModal confirmation
  • Change tracking — compares current attendanceMap against originalAttendanceMap loaded from the session; Save button is disabled when changeCount === 0
  • Save confirmation KModal — shows the number of changes and a present/absent summary before committing
  • BottomAppBar — live present/absent count, Cancel and Save buttons
  • Save — calls updateSession, redirects to ATTENDANCE_HISTORY with a success snackbar; shows error snackbar on failure
  • Unsaved changes guard — beforeRouteLeave prompts with a KModal if the coach navigates away with unsaved changes

Design Spec

Description Screen
Save confirmation modal with present/absent summary Save confirmation modal
Mark all present confirmation modal Mark all modal

Out of Scope

  • Creating a new session (separate issue — AttendanceNewPage)
  • Attendance history list (separate issue — AttendanceHistoryPage)

Acceptance Criteria

General

  • [ ] Session is fetched on mount and learner toggles are pre-populated from existing records
  • [ ] Session date/time is displayed in the page H1; KCircularLoader is shown while loading
  • [ ] Learners are sorted alphabetically and paginated at 50 per page
  • [ ] Learner list is filterable by name via a search box
  • [ ] Each learner row has a KSwitch reflecting the saved state; when true, the row shows a "Present" label and a $themePalette.blue.v_100 background
  • [ ] A "Mark all learners present" KSwitch at the top of the table triggers a KModal confirmation before applying
  • [ ] Save button is disabled when no changes have been made
  • [ ] Saving triggers a confirmation KModal showing the number of changes and a present/absent summary
  • [ ] Confirmed save calls updateSession and redirects to ATTENDANCE_HISTORY with a success snackbar
  • [ ] On error, the user remains on the page and an error snackbar is shown
  • [ ] Navigating away with unsaved changes prompts a KModal confirmation

Styling

  • [ ] Present row background uses $themePalette.blue.v_100, not a hardcoded colour
  • [ ] Absent count in the save confirmation modal uses $themeTokens.error colour

Accessibility and i18n

  • [ ] Table headers are present in the DOM but visually hidden
  • [ ] Each KSwitch has an aria-labelledby referencing a visually hidden label
  • [ ] All user-visible strings are internationalised
  • [ ] Page is keyboard navigable

Testing

  • [ ] Session loads and pre-populates learner toggles correctly
  • [ ] Change count is tracked correctly against the original state
  • [ ] Save button is disabled when changeCount === 0
  • [ ] Save confirmation modal shows correct change count and present/absent summary
  • [ ] Successful save redirects to history with snackbar
  • [ ] Failed save shows error snackbar and stays on page
  • [ ] Unsaved changes guard fires on navigation away

References

  • Issue #14236 — stub page being fleshed out
  • Issue #14242 — AttendanceNewPage, shares the same learner table pattern
  • Issue #14244 — AttendanceHistoryPage, linked from "View Sessions"
  • Issue #14022 — original feature spec with design references

🤖 This issue was written with AI assistance, under supervision, review and final edits by [@akolson] 🤖

akolson avatar Feb 25 '26 12:02 akolson

Implementation Plan for AttendanceEditPage

Overview

Implement AttendanceEditPage — loads an existing attendance session, pre-populates learner toggles, tracks changes against the original state, and prompts for confirmation before saving.

Architecture

The page mirrors AttendanceNewPage structurally (same learner table, pagination/search, mark-all modal, unsaved changes guard). Key differences:

  1. Fetches existing session via fetchSession(attendanceId) on mount, shows KCircularLoader while loading
  2. Tracks changes against an originalAttendanceMap snapshot — Save button disabled when changeCount === 0
  3. Save opens a confirmation KModal showing change count + present/absent summary
  4. Calls updateSession instead of createSession

Files Changed

Action File
Modify packages/kolibri-common/strings/attendanceStrings.js — 4 new i18n strings
Rewrite kolibri/plugins/coach/frontend/views/attendance/AttendanceEditPage.vue — full implementation
Modify kolibri/plugins/coach/frontend/views/attendance/__tests__/AttendancePages.spec.js — full test suite

Phases

  1. Add i18n strings — editPageHeading, saveConfirmationTitle, saveConfirmationDescription, updateSuccessMessage
  2. Write failing tests — 9 test cases covering: session loading, pre-population, change tracking, save button disable, save confirmation modal, success/error save, unsaved changes guard
  3. Implement component — full AttendanceEditPage.vue replacing the stub
  4. Verification — run tests, lint, walk through acceptance criteria

New i18n Strings

  • editPageHeading: "Edit attendance: {date} ({time})"
  • saveConfirmationTitle: "Save {count} change(s)?"
  • saveConfirmationDescription: "{presentCount} present, {absentCount} absent"
  • updateSuccessMessage: "Attendance updated"

Test Coverage

  • Session loads and pre-populates toggles correctly
  • Loader shown while loading
  • Session date/time in heading
  • Change count tracked against original state
  • Save button disabled when changeCount === 0
  • Save confirmation modal shows change count + summary
  • Successful save redirects with snackbar
  • Failed save shows error snackbar
  • Unsaved changes guard on navigation

rtibblesbot avatar Mar 14 '26 04:03 rtibblesbot

Implementation Progress: AttendanceEditPage

All four phases are complete. Branch: issue-14242-a8a461

Changes

File Action
packages/kolibri-common/strings/attendanceStrings.js Added 4 i18n strings: editPageHeading, saveConfirmationTitle, saveConfirmationDescription, updateSuccessMessage
kolibri/plugins/coach/frontend/views/attendance/AttendanceEditPage.vue Full implementation replacing stub
kolibri/plugins/coach/frontend/views/attendance/__tests__/AttendancePages.spec.js 9 new tests for edit page

Test Evidence

PASS kolibri/plugins/coach/frontend/views/attendance/__tests__/AttendancePages.spec.js

Test Suites: 1 passed, 1 total
Tests:       21 passed, 21 total (12 existing + 9 new)

New tests cover:

  • Session fetched on mount, toggles pre-populated from records
  • KCircularLoader shown while loading
  • Session date/time in heading
  • Change count tracked against original state
  • Save button disabled when changeCount === 0
  • Save confirmation modal with change count + present/absent summary
  • Successful save calls updateSession, redirects with snackbar
  • Failed save shows error snackbar, stays on page
  • Unsaved changes guard blocks navigation

Lint

All pre-commit checks pass on all 3 changed files.

Visual Verification

Dev server could not be started due to a Django/silk compatibility issue in the environment (unrelated to these changes). The implementation follows the design spec structurally:

  • Save confirmation modal shows change count in title and present/absent summary in body
  • Absent count uses $themeTokens.error color per spec
  • Mark all present modal matches AttendanceNewPage pattern

Acceptance Criteria Checklist

All criteria verified via tests and code inspection — see phase-4-verification.md for the full mapping.

rtibblesbot avatar Mar 14 '26 04:03 rtibblesbot

Self-review completed for AttendanceEditPage implementation.

All acceptance criteria verified and met. All 21 tests pass.

Findings:

  • suggestion (fixed): Removed unused saveConfirmationDescription i18n string from attendanceStrings.js — the save confirmation modal was composing present/absent counts inline using separate strings instead of this combined one.
  • nitpick: The loader test in AttendancePages.spec.js duplicates setup from the makeEditPageWrapper helper — could be simplified but low priority.
  • praise: Clean change-tracking implementation and consistent patterns with AttendanceNewPage.

rtibblesbot avatar Mar 14 '26 04:03 rtibblesbot

Implemented in #14382

rtibbles avatar Mar 16 '26 01:03 rtibbles