Skip to content

Section manager: make "Set Selected Bios" honour the selection and show every error - #179

Merged
siekmang merged 2 commits into
release/3.3.0from
claude-review/publish-bios-selection
Nov 18, 2026
Merged

siekmang merged 2 commits into
release/3.3.0from
claude-review/publish-bios-selection

Conversation

@mvirgin

@mvirgin mvirgin commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Release target: this is meant for the release after 3.3.0 (#169 merges release/3.2.5 into main as 3.3.0). It is opened against release/3.2.5 only because the next release branch does not exist yet. Please retarget it to that branch once it is created, and don't merge it into release/3.2.5 before #169 lands.

Summary

In the blueprint section manager ("Manage Sections"), "Set Selected Bios" ignored the checkboxes. It was wired to the same handler as "Set Bios", which loops over every associated section. If an LXD unchecked sections whose instructors had customised their bios and clicked "Set Selected Bios", every section's profile page was still rewritten.

This PR builds on #160 (target-page profile names and the write warning) and leaves its behaviour unchanged. It fixes four problems in PublishInterface.tsx:

  1. Selection ignored. applySectionProfiles now takes the list of sections to update. "Set Bios" passes every section, and "Set Selected Bios" passes only the checked ones. "Publish all" and "Publish selected" use the same two lists.
  2. Only the last error was shown. sectionError copied errorsByCourseId from the render it was created in, so each call in the loop started from the same stale snapshot. When five sections failed, only one row showed an error. It now uses a functional state update, so every failing row shows its error. This also makes the setErrorsByCourseId({}) reset at the start of a run take effect, and stops the old code mutating the previous run's error arrays in place.
  3. course.isBlueprint was never called. Course.isBlueprint is a method, so !course?.isBlueprint on the four action buttons was always false. setIsBlueprint(course.isBlueprint) worked only because React treats a function argument as a state updater and calls it. Both now call course.isBlueprint().
  4. undefined ids sent to Canvas. Unchecking a section stores undefined under its id in sectionsToPublish. "Publish selected" passed those entries straight to Course.publishAll, which sent course_ids[]=undefined and counted them in "Published N sections". Unchecked entries are now dropped. Any section whose id is not a number is skipped and named in the status message (for example "Skipped 1 section(s) with no course id: …"), and is never passed to getProfilePage or publishAll. Sections were stored under section.id, so every id-less section shared one NaN entry and only one of them was listed or reported. They now get separate entries, so each one is listed and named.

Publishing also no longer gets stuck. Before, if the publish request failed, or the section-list refresh 500 ms later failed, loading was never cleared, so the modal couldn't be closed. The refresh failure was also an unhandled rejection. Both failures now show a message and end the loading state.

User impact: "Set Selected Bios" and "Publish selected" now act only on checked sections. When several sections fail, each failing row shows its own error. A failed publish or refresh shows an error instead of hanging. "Set Bios" and "Publish all" behave as before.

Changes

  • src/publish/publishInterface/PublishInterface.tsx
    • applySectionProfiles(targetSections) and publishCourses(event, targetSections) take a Course[]. The buttons pass either all sections or the selected ones.
    • New exported helpers: selectedOnly(record) drops unchecked (undefined) entries, and splitByValidId(courses) separates sections with a numeric id from those without. A private skippedMessage adds the skipped section names to the status line.
    • sectionError uses setErrorsByCourseId(prev => …).
    • The "profile page not found / ambiguous" path marks only the target sections, not every section.
    • course.isBlueprint() is called in the effect and on the buttons.
    • Course.publishAll is wrapped in a try/catch. A failed request now shows "Publishing failed: …" and clears loading, so the modal can be closed.
    • The delayed post-publish refresh (course.getAssociatedCourses()) runs in a try/catch/finally. If it fails, the message reads "Published N sections, but the section list could not be refreshed: …". loading is always cleared.
    • sections and sectionsToPublish are keyed by sectionKey(section) in the load path, the post-publish refresh and the checkbox toggle.
    • Removed the unused _currentProfiles copy.
  • src/publish/publishInterface/sectionKey.ts (new): sectionKey(section) returns the Canvas id, or no-id:<name>:<course code> when the id isn't a finite number.
  • src/publish/publishInterface/SectionRows.tsx: uses sectionKey to read a row's checkbox state and as the React key, so rows for id-less sections show their real selection state.
  • src/publish/publishInterface/__tests__/PublishInterface.sections.test.tsx (new). It covers:
    • "Set Selected Bios" fetches and writes only the checked sections, while "Set Bios" still writes all of them.
    • Three sections failing for three different reasons (no profile, multiple matches, render not verified) all show their errors.
    • An ambiguous profile page marks only the selected sections, and no section page is fetched.
    • "Publish selected" sends only the checked ids. The test checks the course_ids entries in the actual PUT /api/v1/accounts/:id/courses form body, and none is "undefined".
    • A section with no id is skipped, named in the status message, and never passed to getProfilePage or publishAll.
    • Two id-less sections are both listed and both named as skipped.
    • A failed publish request shows "Publishing failed: …" and re-enables the buttons.
    • A failed post-publish refresh shows its error and re-enables the buttons.
    • Blueprint check: isBlueprint() is called and the tools are enabled for a blueprint, and a non-blueprint, non-DEV course gets the disabled "Not BP or DEV" button and no section tools.
    • Unit tests for selectedOnly and splitByValidId.
  • CHANGELOG.md: see the note below.

Known, not changed

After a publish, the refresh replaces sections with new Course objects. RenderBpInterface decides whether to show "Set Selected Bios" and "Publish selected" with isEqual(sections, sectionsToPublish). Each Course carries its own arrow-function properties (isBlueprint, getAssociatedCourses), so isEqual sees the new objects as different even when every section is still selected. As a result, the two "selected" buttons can appear after a publish when nothing has been unchecked. This happened before this PR too and is left for a separate change.

CHANGELOG placement

The current [Unreleased] section on release/3.2.5 holds the 3.3.0 notes. #169 copies that section as its description. Adding these entries there would list them under 3.3.0. This PR therefore does the release-cut step already used for 3.2.5 (d34d552): it renames that section to ## 3.3.0 and opens a new empty [Unreleased] above it, with these entries in it. When this PR is retargeted onto the next release branch, that branch will already have the same ## 3.3.0 heading, so the rename either merges cleanly or leaves a trivial conflict around the new entries. In both cases the entries cannot slip into the 3.3.0 notes unnoticed.

Testing

Run locally after a clean npm ci:

  • npm test (rebased onto the current release/3.2.5): 65 suites passed and 1 skipped. 463 tests passed and 11 skipped, out of 474. The skipped suite and tests are already skipped on release/3.2.5.
  • The new suite has 13 tests. To check that it catches the bugs, it was also run against the unchanged PublishInterface.tsx, with only the two new helpers added so it compiles. 6 of the first 10 tests failed: selected-only bios, every error shown, the ambiguous-page selection, publish ids, missing id, and the isBlueprint() call. The other 4 cover behaviour that was already correct: "Set Bios writes every section", the non-blueprint check and the two helper unit tests. The three later tests were checked against the version before the keying and refresh fixes. "Two id-less sections" and "refresh failure" failed there. "Publish request failure" passed, because that catch was already in place.
  • npm run lint: clean.
  • npm run typecheck: clean.
  • npm run build (production): compiled with webpack's 3 usual asset-size warnings and no errors.

Not verified

There is no Canvas test instance available, so nothing here was run against real Canvas. All results come from Jest with Canvas mocked. In particular:

  • That Canvas really leaves unchecked sections' profile pages untouched after "Set Selected Bios" (the tests only show that the extension does not request them).
  • The real PUT /api/v1/accounts/:id/courses request with a partial course_ids[] list. Canvas runs that batch as an asynchronous Progress job. The existing fixed 500 ms wait before refreshing the section list is unchanged, so the list can still show sections as unpublished for a moment after "Published N sections". Polling the Progress job is left for a separate change.
  • How a section without a numeric id could arise in practice. No real path to one was found. The guard is defensive. Two id-less sections with the same name and course code would still share one entry.
  • The look of the new warning-coloured status line (alert-warning) in Canvas's styles.

Out of scope, left unchanged: src/ui/module/index.ts has the same if (course?.isBlueprint) method-reference check. It means the "Lock All" and "Unlock Profile & Home" buttons on the Modules page are also added to non-blueprint courses. That is a separate UI surface and is not changed here.

🤖 Generated with Claude Code

"Set Selected Bios" was wired to the same handler as "Set Bios", which
loops over every associated section, so it rewrote the profile page on
sections the user had unchecked. applySectionProfiles and publishCourses
now take the list of sections to act on; the "selected" buttons pass
only the checked sections.

Also in the section manager:
- sectionError uses a functional state update, so every failing section
  keeps its error instead of only the last one in a pass.
- Call course.isBlueprint() instead of testing the method reference,
  which was always truthy.
- Drop unchecked (undefined) entries before publishing, and skip and
  report sections without a numeric id rather than sending "undefined"
  to Canvas.
- Key sections by sectionKey(), which falls back to name and course
  code when a section has no usable id, so several id-less sections are
  each listed and reported instead of collapsing onto one entry.
- Catch a failed publish request and a failed post-publish refresh, so
  the modal shows the error and always leaves the loading state.

The CHANGELOG entries go in a new [Unreleased] section above 3.3.0,
since this is intended for the release after 3.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

✅ Build artifact available: Download here

@siekmang
siekmang changed the base branch from release/3.2.5 to release/3.3.0 November 18, 2026 14:31
@siekmang

Copy link
Copy Markdown
Contributor

I tested in my test course, and the behavior matches. Didn't run with actual bios, but it did throw the error message only on the courses I selected.

@siekmang
siekmang marked this pull request as ready for review November 18, 2026 17:31
@siekmang
siekmang merged commit ada7ab1 into release/3.3.0 Nov 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants