kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Add AttendanceBlock to coach class home page

Open akolson opened this issue 9 months ago • 7 comments

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 Block component with attendanceLabel as the title and a "View history" link
  • "Mark attendance" button — links to ATTENDANCE_NEW route
  • Recent sessions list — fetches up to 5 sessions via fetchRecentSessions on mount; each session shows:
    • Formatted date/time via formatAttendanceDateTime
    • Stacked green/red bar chart showing present/absent proportion (using $themePalette tokens)
    • Present and absent counts with colour-coded dots
  • Loading state — a KCircularLoader is shown while fetchRecentSessions is in flight
  • Error handling — errors from fetchRecentSessions are dispatched to handleApiError
  • 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-hidden to 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 AttendanceBlock

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

  • [ ] AttendanceBlock appears 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 fetchRecentSessions and 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 KCircularLoader is shown while fetchRecentSessions is in flight
  • [ ] Errors from fetchRecentSessions are dispatched to handleApiError
  • [ ] "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 $themePalette tokens, 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
  • [ ] KCircularLoader is shown during fetch and hidden after
  • [ ] fetchRecentSessions is called on mount with the correct class ID

References

  • Issue #14231 — useAttendance composable
  • Issue #14022 — original feature spec with design references
  • Block component — existing home page block pattern that AttendanceBlock follows

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

akolson avatar Feb 24 '26 16:02 akolson

Overall this is looking very solid, just a few additional details that may help:

  1. What should be shown while fetchRecentSessions is in flight? No loading state (e.g. KCircularLoader) is specified.
  2. What happens if fetchRecentSessions fails? 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?
  3. The "stacked green/red bar chart" is a custom implementation (not a KDS component). The issue mentions $themePalette tokens 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

rtibbles avatar Mar 06 '26 22:03 rtibbles

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

akolson avatar Mar 09 '26 13:03 akolson

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:

  1. Loading state — KCircularLoader shown while fetchRecentSessions is in flight (added to acceptance criteria)
  2. Error handling — errors dispatched to handleApiError (confirmed approach)
  3. Bar chart a11y — aligned with #14166: visually hidden description string, aria-hidden on 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 attendanceLoading from composable — fetchRecentSessions doesn't toggle attendanceLoading (only fetchSessions does), so we manage loading state locally in the component
  • API data shape from recent endpoint: { present_count, total_count } — absent count computed as total_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-label on bar container with "{present} present, {absent} absent"; visible counts are aria-hidden="true"

Target branch: release-v0.19.x

rtibblesbot avatar Mar 09 '26 20:03 rtibblesbot

Implementation Progress: AttendanceBlock Component

Stakeholder Feedback Addressed

Per @rtibbles and @akolson:

  1. Loading state: KCircularLoader shown while fetchRecentSessions is in flight (local ref(true) → .finally(() => loading.value = false))
  2. Error handling: Errors dispatched to handleApiError via store.dispatch('handleApiError', { error }) in .catch()
  3. Bar chart a11y (aligned with #14166): role="img" + aria-label on bar containers with "{present} present, {absent} absent" text description; visible counts are aria-hidden="true"; colors use $themePalette tokens; information not conveyed by color alone (numeric counts always visible)

What Was Implemented

  • AttendanceBlock.vue — Composition API component using Block/BlockItem pattern, useAttendance composable, $themePalette tokens for bar colors, i18n via attendanceStrings
  • Route constants — ATTENDANCE_NEW and ATTENDANCE_HISTORY added to PageNames
  • i18n strings — 7 strings added to attendanceStrings.js
  • HomePage integration — AttendanceBlock positioned 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.

rtibblesbot avatar Mar 09 '26 20:03 rtibblesbot

Self-Review Progress Update

Stakeholder Feedback Addressed

  • @rtibbles — All three points incorporated:
    1. Loading state: KCircularLoader shown while fetchRecentSessions is in flight
    2. Error handling: Errors dispatched to handleApiError (confirmed by @akolson)
    3. Bar chart a11y: Duplicated considerations from #14166 — visually hidden description (role="img" + aria-label), aria-hidden on visible counts, WCAG contrast via $themePalette tokens, information not conveyed by colour alone (text counts always visible)

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-utils following 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 avatar Mar 09 '26 20:03 rtibblesbot

@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-hidden to 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.

radinamatic avatar Mar 09 '26 21:03 radinamatic

Fixed in #14355

rtibbles avatar Mar 11 '26 16:03 rtibbles