kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Implement AttendanceHistoryPage — attendance session history

Open akolson opened this issue 9 months ago • 5 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 AttendanceHistoryPage — a paginated, sortable overview of all attendance sessions for a classroom. Coaches can filter by date range, navigate to any session to edit it, or start a new session from this page. Builds on the stub added in #14236.

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

Context

AttendanceHistoryPage is the hub coaches land on after submitting a new session, and the page they return to after editing. It gives a full picture of attendance over time for a class and acts as the navigation hub between AttendanceNewPage and AttendanceEditPage.

The Change

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

  • CoachAppBarPage with a back link to the class home page and a "Mark attendance" button linking to ATTENDANCE_NEW
  • KTable — sortable table with columns: Date (link to edit session), Present count, Absent count; default sort by date descending
  • Date range filter (KSelect) — options: Past 7 days, Past 30 days (default), Past 365 days, All time, Custom
    • Selecting Custom opens a KDateRange picker; on apply, a formatted MM-DD-YYYY – MM-DD-YYYY option is added to the dropdown
  • Pagination — 10 sessions per page with prev/next controls
  • Empty state — "No attendance sessions found" message when no sessions match the filter
  • Sessions fetched via fetchSessions with start_date and end_date params on mount and on filter change

Design Spec

Description Screen
Attendance history table AttendanceHistoryPage
Date range filter options Date range filter

Out of Scope

  • Taking a new attendance session (separate issue — AttendanceNewPage)
  • Editing an existing session (separate issue — AttendanceEditPage)

Acceptance Criteria

General

  • [ ] Sessions are fetched on mount and re-fetched when the date range filter changes
  • [ ] KTable displays sessions with Date, Present, and Absent columns, sorted by date descending by default
  • [ ] Date column entries are links that navigate to ATTENDANCE_EDIT for that session
  • [ ] "Mark attendance" button links to ATTENDANCE_NEW
  • [ ] "Back to class" link navigates to the class home page
  • [ ] Date range filter defaults to "Past 30 days" and includes: Past 7 days, Past 30 days, Past 365 days, All time, Custom
  • [ ] Selecting Custom opens a KDateRange picker; applying adds a formatted start – end option to the dropdown
  • [ ] Sessions are paginated at 10 per page with prev/next controls
  • [ ] "No attendance sessions found" empty state is shown when no sessions match the filter

Accessibility and i18n

  • [ ] All user-visible strings are internationalised
  • [ ] Date range filter and pagination controls are keyboard navigable
  • [ ] KDateRange validation errors are displayed for invalid, future, or out-of-range dates

Testing

  • [ ] Sessions load and render correctly in the table
  • [ ] Date range filter fetches sessions with correct start_date and end_date params
  • [ ] Custom date range applies correctly and updates the dropdown
  • [ ] Pagination renders correct subset of sessions
  • [ ] Empty state renders when no sessions are returned

References

  • Issue #14236 — stub page being fleshed out
  • Issue #14242 — AttendanceNewPage, linked from "Mark attendance" button
  • 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

Watching for resolution on behalf of learningequality/kolibri#14243.

rtibblesbot avatar Mar 11 '26 22:03 rtibblesbot

Implementation Plan — AttendanceHistoryPage

Architecture

The page uses the existing useAttendance composable (extended with server-side pagination support) to fetch sessions from the AttendanceSessionViewSet API. Sessions are displayed in a KTable with Date, Present, and Absent columns. A KSelect dropdown provides preset date range filters plus a Custom option that opens KDateRange. Server-side pagination via OptionalPageNumberPagination with 10 items per page.

Phases

Phase 1: Extend useAttendance composable

  • Add fetchPaginatedSessions(classId, params) that uses getCollection to access pagination metadata (page, count, total_pages) stored by the Kolibri Collection class
  • Add paginationState ref
  • Update composable mock + tests

Phase 2: Build AttendanceHistoryPage + backend annotations

  • Replace stub with full implementation:
    • CoachAppBarPage wrapper with "Back to class" link + "Mark attendance" button
    • KTable with sortable Date (links to ATTENDANCE_EDIT), Present, Absent columns
    • KSelect date range filter: Past 7 days, Past 30 days (default), Past 365 days, All time, Custom
    • KDateRange picker for custom date range — adds formatted option to dropdown
    • Prev/next pagination controls (10 per page)
    • Empty state: "No attendance sessions found"
    • All strings internationalized via createTranslator + shared attendanceStrings
  • Add annotate_queryset to AttendanceSessionViewSet for present_count/total_count on the main list endpoint (currently only on /recent/ action)

Phase 3: Frontend tests

  • Component tests covering: page structure, session table rendering, data loading with date params, empty state, pagination controls

Files Changed

File Change
composables/useAttendance.js Add fetchPaginatedSessions, paginationState
composables/__mocks__/useAttendance.js Add mock
composables/__tests__/useAttendance.spec.js Pagination tests
attendanceStrings.js Add shared strings
AttendanceHistoryPage.vue Full implementation
attendance/api.py Add annotate_queryset
attendance/test/test_api.py Test count annotations
__tests__/AttendanceHistoryPage.spec.js New component tests

rtibblesbot avatar Mar 13 '26 06:03 rtibblesbot

Implementation Complete — AttendanceHistoryPage

All three phases are implemented with passing tests.

Summary of changes

Phase 1: Composable extension

  • Added fetchPaginatedSessions and paginationState to useAttendance composable
  • Uses getCollection + .metadata for pagination info (page, count, total_pages)
  • Updated mock for downstream tests

Phase 2: Page component + backend

  • Replaced stub AttendanceHistoryPage.vue with full implementation:
    • CoachAppBarPage wrapper with "Back to class" link + "Mark attendance" button
    • KTable with Date (links to edit), Present, Absent columns
    • KSelect date range filter (7d, 30d default, 365d, All time, Custom)
    • KDateRange picker for custom date range
    • Server-side pagination with prev/next controls
    • Empty state: "No attendance sessions found"
    • All strings internationalized via createTranslator + shared attendanceStrings
  • Added shared i18n strings (noSessionsFoundMessage, dateLabel) to attendanceStrings.js
  • Added annotate_queryset to AttendanceSessionViewSet for present_count/total_count on list endpoint

Phase 3: Tests

  • 11 component tests covering page structure, data loading, table rendering, empty state, pagination
  • Updated AttendancePages.spec.js to remove stub test (replaced by dedicated spec)

Test evidence

Frontend: 37/37 passed, 4/4 suites
Backend:  17/17 passed (5 deselected: pre-existing Python 3.14 compat issues)
Lint:     7 files, 0 errors

Files changed

File Change
composables/useAttendance.js Added fetchPaginatedSessions, paginationState
composables/__mocks__/useAttendance.js Added mock entries
composables/__tests__/useAttendance.spec.js 3 new pagination tests
strings/attendanceStrings.js Added noSessionsFoundMessage, dateLabel
AttendanceHistoryPage.vue Full page implementation
attendance/api.py Added annotate_queryset for counts
attendance/test/test_api.py 1 new annotation test
__tests__/AttendanceHistoryPage.spec.js 11 new component tests
__tests__/AttendancePages.spec.js Removed stub test

rtibblesbot avatar Mar 13 '26 06:03 rtibblesbot

Self-Review Findings & Fixes

Reviewed git diff release-v0.19.x...HEAD against issue requirements.

Findings fixed:

  • Removed non-functional sortable/disableBuiltinSorting from KTable — sort headers appeared clickable but had no handler. Removed to avoid misleading UI (server already returns date-descending order).
  • DRYed up recent action in api.py — now calls self.annotate_queryset() instead of duplicating the present_count/total_count annotations inline.
  • Replaced formatDisplayDate with locale-aware $formatDate — the hardcoded MM-DD-YYYY format was US-centric; now uses the i18n date formatter for proper localization.
  • Fixed null flash on selectedDateRange — was initialized as ref(null) and set in onMounted, causing a brief null state before mount. Now initialized directly with the "Past 30 days" default.
  • Added missing custom date range test — acceptance criterion "Custom date range applies correctly and updates the dropdown" was untested.

Remaining (nitpick-level, not fixed):

  • Test uses @vue/test-utils instead of Vue Testing Library (consistent with 10+ other coach plugin tests)
  • formatDisplayDate i18n concern resolved by $formatDate replacement

Test evidence:

  • 30/30 tests passing across 3 suites (useAttendance, AttendanceHistoryPage, AttendancePages)
  • Lint: 2 files, 0 errors

rtibblesbot avatar Mar 13 '26 06:03 rtibblesbot

Mostly fixed in #14379

rtibbles avatar Mar 14 '26 04:03 rtibbles