Add AttendanceBlock to coach class home page
Overview
Add AttendanceBlock to the coach class home page. The block is the entry point into the attendance feature — it surfaces a "Mark attendance" button, displays up to 5 recent sessions as stacked present/absent bar charts with counts, and links to the full session history. Uses fetchRecentSessions from the useAttendance composable added in #14231.
Complexity: Low
Target branch: release-v0.19.x
Context
The coach class home page (HomePage) is composed of several Block components (e.g. lessons, quizzes, groups). AttendanceBlock follows the same pattern — it slots into the existing Block component with a title, a primary action, and a summary of recent activity.
The Change
AttendanceBlock (kolibri/plugins/coach/frontend/views/home/HomePage/AttendanceBlock.vue):
- Uses the existing
Blockcomponent withattendanceLabelas the title and a "View history" link - "Mark attendance" button — links to
ATTENDANCE_NEWroute - Recent sessions list — fetches up to 5 sessions via
fetchRecentSessionson mount; each session shows:- Formatted date/time via
formatAttendanceDateTime - Stacked green/red bar chart showing present/absent proportion (using
$themePalettetokens) - Present and absent counts with colour-coded dots
- Formatted date/time via
- Loading state — a
KCircularLoaderis shown whilefetchRecentSessionsis in flight - Error handling — errors from
fetchRecentSessionsare dispatched tohandleApiError - Empty state — "No attendance sessions yet" message when no sessions exist
- Uses Composition API (
setup()) - The block is positioned first on the top-left on desktop, and first in the stacked grid on medium and small breakpoints
Bar chart visual spec — the stacked present/absent bar is a custom implementation (no KDS component fits this use case):
- Two segments rendered left-to-right: green (present) and red (absent)
- Segment widths are proportional to present/absent counts out of the total
- Bar height: 8px with rounded corners (
border-radius: 4px) - Segment colours:
$themePalette.green.v_500(present) and$themePalette.red.v_500(absent) - Present and absent counts displayed below the bar as text, each preceded by a colour-coded dot matching the segment colour
Bar chart a11y:
- Container has a visually hidden string describing the distribution (e.g., "16 present, 8 absent")
- Visible counts with colour-coded dots are
aria-hiddento defer to the visually hidden string - 3:1 minimum contrast ratio between adjacent segments (WCAG 1.4.11)
- 4.5:1 minimum contrast ratio between text and segment background (WCAG 1.4.3)
- Information not conveyed by colour alone — counts are always visible (WCAG 1.4.1)
Design Spec
| Description | Screen |
|---|---|
| Attendance block on class home page |
Out of Scope
- Navigation from "Mark attendance" and "View history" links — routes are wired in a separate issue
- Full session history page (separate issue)
- Attendance-taking and edit pages (separate issues)
Acceptance Criteria
General
- [ ]
AttendanceBlockappears on the class home page, positioned first on the top-left on desktop and first in the stacked grid on medium and small breakpoints - [ ] A prominent "Mark attendance" button is displayed
- [ ] Up to 5 recent sessions are fetched on mount via
fetchRecentSessionsand displayed as stacked present/absent bar charts with counts - [ ] Each session shows a formatted date/time, a green/red proportional bar, and present/absent counts with colour-coded dots
- [ ] A
KCircularLoaderis shown whilefetchRecentSessionsis in flight - [ ] Errors from
fetchRecentSessionsare dispatched tohandleApiError - [ ] "No attendance sessions yet" message is shown when no sessions exist
- [ ] "View history" link is shown only when sessions exist
Styling
- [ ] Bar chart colours use
$themePalettetokens, not hardcoded values - [ ] Bar is 8px tall with rounded corners
- [ ] Segment widths are proportional to present/absent counts
Accessibility and i18n
- [ ] All user-visible strings are internationalised
- [ ] "Mark attendance" button and "View history" link are keyboard navigable
- [ ] Bar chart container has a visually hidden string describing the present/absent distribution
- [ ] Visible counts with colour-coded dots are
aria-hidden - [ ] 3:1 contrast ratio between adjacent bar segments (WCAG 1.4.11)
- [ ] 4.5:1 contrast ratio between segment text and its background (WCAG 1.4.3)
- [ ] Present/absent counts satisfy WCAG 1.4.1 — information not conveyed by colour alone
Testing
- [ ] Block renders correctly with sessions and in the empty state
- [ ]
KCircularLoaderis shown during fetch and hidden after - [ ]
fetchRecentSessionsis called on mount with the correct class ID
References
- Issue #14231 —
useAttendancecomposable - Issue #14022 — original feature spec with design references
Blockcomponent — existing home page block pattern thatAttendanceBlockfollows
🤖 This issue was written with AI assistance, under supervision, review and final edits by [@akolson] 🤖
Overall this is looking very solid, just a few additional details that may help:
- What should be shown while
fetchRecentSessionsis in flight? No loading state (e.g.KCircularLoader) is specified. - What happens if
fetchRecentSessionsfails? I don't know that we have good error handling for the other parts here, so it may just be a matter of specifying we let it be handled by handleApiError? - The "stacked green/red bar chart" is a custom implementation (not a KDS component). The issue mentions
$themePalettetokens for colors (good), but should specify some more details, especially for a11y support. Can duplicate considerations and solutions from this issue: https://github.com/learningequality/kolibri/issues/14166
I don't know that we have good error handling for the other parts here, so it may just be a matter of specifying we let it be handled by handleApiError?
Yes, specifying the handleApiError makes sense in this case
Implementation Plan Summary
I've analyzed the issue, all referenced files, and the stakeholder feedback. Here's the plan for AttendanceBlock:
Stakeholder Feedback Incorporated
Per @rtibbles and @akolson:
- Loading state —
KCircularLoadershown whilefetchRecentSessionsis in flight (added to acceptance criteria) - Error handling — errors dispatched to
handleApiError(confirmed approach) - Bar chart a11y — aligned with #14166: visually hidden description string,
aria-hiddenon visible counts, WCAG contrast ratios (1.4.1, 1.4.3, 1.4.11), information not conveyed by colour alone
Phases
| Phase | Description |
|---|---|
| 1 | Add ATTENDANCE_NEW/ATTENDANCE_HISTORY route constants + i18n strings to attendanceStrings.js |
| 2 | Create AttendanceBlock.vue — Composition API, useAttendance composable, Block/BlockItem pattern, stacked bar chart with $themePalette tokens, loading/empty/error states, a11y |
| 3 | Integrate into HomePage/index.vue — first in left column on desktop, first in stacked grid on smaller breakpoints |
| 4 | Jest tests — loading state, sessions rendering, empty state, fetchRecentSessions called on mount |
| 5 | Lint and final verification against acceptance criteria |
Key Design Decisions
- Local loading ref instead of
attendanceLoadingfrom composable —fetchRecentSessionsdoesn't toggleattendanceLoading(onlyfetchSessionsdoes), so we manage loading state locally in the component - API data shape from
recentendpoint:{ present_count, total_count }— absent count computed astotal_count - present_count - Bar chart is a simple flex container with two divs, widths proportional to counts, 8px height, 4px border-radius
- a11y:
role="img"+aria-labelon bar container with "{present} present, {absent} absent"; visible counts arearia-hidden="true"
Target branch: release-v0.19.x
Implementation Progress: AttendanceBlock Component
Stakeholder Feedback Addressed
Per @rtibbles and @akolson:
- Loading state:
KCircularLoadershown whilefetchRecentSessionsis in flight (localref(true)→.finally(() => loading.value = false)) - Error handling: Errors dispatched to
handleApiErrorviastore.dispatch('handleApiError', { error })in.catch() - Bar chart a11y (aligned with #14166):
role="img"+aria-labelon bar containers with "{present} present, {absent} absent" text description; visible counts arearia-hidden="true"; colors use$themePalettetokens; information not conveyed by color alone (numeric counts always visible)
What Was Implemented
AttendanceBlock.vue— Composition API component usingBlock/BlockItempattern,useAttendancecomposable,$themePalettetokens for bar colors, i18n viaattendanceStrings- Route constants —
ATTENDANCE_NEWandATTENDANCE_HISTORYadded toPageNames - i18n strings — 7 strings added to
attendanceStrings.js - HomePage integration —
AttendanceBlockpositioned first in the left column on desktop - Tests — 7 passing Jest tests covering: fetch on mount, loading state, empty state, session rendering, a11y attributes, error handling
Test Summary
PASS AttendanceBlock.spec.js
✓ calls fetchRecentSessions on mount with the class ID
✓ shows loading state while fetchRecentSessions is in flight
✓ renders empty state when no sessions exist
✓ renders sessions with present and absent counts
✓ renders bar chart with role="img" and aria-label for a11y
✓ marks visible counts as aria-hidden
✓ dispatches handleApiError when fetchRecentSessions fails
7 passed, 0 failed
All pre-commit lint checks pass.
Self-Review Progress Update
Stakeholder Feedback Addressed
- @rtibbles — All three points incorporated:
- Loading state:
KCircularLoadershown whilefetchRecentSessionsis in flight - Error handling: Errors dispatched to
handleApiError(confirmed by @akolson) - Bar chart a11y: Duplicated considerations from #14166 — visually hidden description (
role="img"+aria-label),aria-hiddenon visible counts, WCAG contrast via$themePalettetokens, information not conveyed by colour alone (text counts always visible)
- Loading state:
Self-Review Findings
- No blocking issues found
- No suggestion-level issues requiring action
- 2 nitpicks: Removed an unused CSS class (
session-item); noted test uses@vue/test-utilsfollowing existing coach plugin convention (all 9 existing coach test files use it) - 4 praise items: Strong a11y implementation, clean error handling, well-structured test mocks, proper i18n
Acceptance Criteria
All acceptance criteria verified and met — general (8/8), styling (3/3), a11y/i18n (7/7), testing (3/3 + error handling test).
Verification
- Tests: 7/7 passing
- Lint: clean
- All external calls in tests properly mocked (useAttendance composable, kolibri/router, Vuex store)
@rtibblesbot
Please note that Bar chart a11y must be implemented according to these indications:
-
CORRECT approach is described in https://github.com/learningequality/kolibri/issues/14166#issue-3935275603:
- Container has no role with a visually hidden string describing the distribution in text (e.g., "2 present, 3 absent")
- Visible numbers inside all segments satisfy WCAG 1.4.1 (information not conveyed by color alone)
- Visible numbers are
aria-hiddento defer to the visually hidden string text - 3:1 contrast between adjacent segments (WCAG 1.4.11)
- 4.5:1 contrast between text and its segment background (WCAG 1.4.3)
-
INCORRECT approach is
role="img"+aria-label, mentioned in your comments above.
Fixed in #14355