Skip to content

Breaking: Use content tree API for editor data loading (fixes #458)#459

Merged
taylortom merged 8 commits into
masterfrom
feature/tree-api-integration
May 8, 2026
Merged

Breaking: Use content tree API for editor data loading (fixes #458)#459
taylortom merged 8 commits into
masterfrom
feature/tree-api-integration

Conversation

@taylortom
Copy link
Copy Markdown
Contributor

@taylortom taylortom commented Mar 11, 2026

Fixes #458

Breaking

  • Editor data loading now uses GET /api/content/tree/:courseId instead of the full-content POST /api/content/query — payload reduced from ~300-500KB to ~10-20KB
  • Staleness check now uses If-Modified-Since conditional requests, returning 304 when content hasn't changed (zero body transfer vs previous POST query)
  • Full documents fetched on demand only when editing individual items (article, block, component, contentObject, config, course, themeEditor)
  • editorDataLoader internal API changed: loadTree() replaces ContentCollection fetch; isOutdated() uses conditional GET
  • Editor index files now await model.fetch() before scaffold form building
  • peerDependencies updated to declare runtime requirements explicitly:
    • adapt-authoring-content: ^3.0.0 — for the new tree endpoint
    • adapt-authoring-authored: ^1.4.0 — for course timestamp on update

Update

  • editorDataLoader.js$.ajax used throughout instead of native fetch for consistency with the rest of the codebase; semicolons and spacing restored to match surrounding editor module style
  • menuSettings/index.js — no full fetch needed since _menu, _theme, _enabledPlugins are now in tree projection

Dependencies

Testing

  1. Open the editor for an existing course — verify menu/page tree renders correctly
  2. Navigate to edit an article/block/component — verify the edit form loads with all fields
  3. Edit config, course settings, theme editor — verify full data is available
  4. Make an edit and return to menu — verify staleness check triggers a refresh
  5. Check browser network tab — initial load should use /api/content/tree/:id instead of /api/content/query

taylortom and others added 2 commits March 11, 2026 01:29
Replace full content fetch with lightweight tree endpoint. Editor now
loads projected fields via GET /api/content/tree/:courseId and fetches
full documents on demand when editing individual items. Staleness check
uses If-Modified-Since conditional requests for zero-cost polling.
Origin.editor.data.content is a plain Backbone.Collection with no url
property (created via native fetch in loadTree), so calling .fetch()
on it throws, causing an errorfetchingdata popup on every menu delete
despite the DELETE request succeeding.

Instead of re-fetching, remove the deleted item and its descendants
from the local collection directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the editor’s data-loading strategy to use a lightweight content tree endpoint for initial load and conditional requests for staleness checks, while lazily fetching full documents only when a user opens an item for editing.

Changes:

  • Replace the initial full content fetch with GET /api/content/tree/:courseId and store projected items in Origin.editor.data.content.
  • Update staleness detection to use If-Modified-Since conditional requests (304 when unchanged).
  • Ensure full models are fetched on-demand (await model.fetch()) before building scaffold forms in individual editor routes.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
app/modules/editor/global/editorDataLoader.js Implements tree loading + conditional staleness check; replaces previous full collection fetch logic.
app/modules/editor/article/index.js Fetch full article document before building the edit form.
app/modules/editor/block/index.js Fetch full block document before building the edit form.
app/modules/editor/component/index.js Fetch full component document before building the edit form (existing items only).
app/modules/editor/contentObject/index.js Fetch full page/menu document before building the edit form.
app/modules/editor/config/index.js Fetch full config document before building the edit form.
app/modules/editor/course/index.js Fetch full course document before building the settings form.
app/modules/editor/themeEditor/index.js Fetch full course + config before opening the theme editor UI.
app/modules/editor/contentObject/views/editorMenuView.js Updates client-side deletion handling to remove items from the in-memory tree/collections.
app/modules/editor/menuSettings/index.js Minor whitespace-only change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/modules/editor/global/editorDataLoader.js Outdated
Comment thread app/modules/editor/global/editorDataLoader.js Outdated
Comment thread app/modules/editor/global/editorDataLoader.js Outdated
Comment thread app/modules/editor/global/editorDataLoader.js Outdated
Comment thread app/modules/editor/global/editorDataLoader.js Outdated
…ader

isOutdated() now returns the fetched tree data on 200 so loadTree() can
reuse it instead of hitting the same endpoint a second time. The await
on isOutdated() is moved inside the existing try/catch so network errors
are handled gracefully. Also removes redundant Backbone method
reassignments in favour of the idiomatic model collection option.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@taylortom
Copy link
Copy Markdown
Contributor Author

@copilot Thanks for the review — addressed the following in 0f08de3:

Double request on stale content (comment #2): isOutdated() now returns the parsed response body ({ items, lastModified }) when the tree endpoint returns 200, so loadTree() reuses it instead of making a second request to the same endpoint.

Unhandled rejection (comment #1): Moved the await isOutdated() call inside the existing try/catch block in load(), so network errors and non-ok responses are caught and routed through handleError(). Also added an explicit check for non-ok responses in isOutdated().

Redundant method assignments (comment #4): Removed the manual findWhere/where reassignments and passed model: ContentModel in the collection options instead.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

@copilot Thanks for the review — addressed the following in 0f08de3:

Double request on stale content (comment #2): isOutdated() now returns the parsed response body ({ items, lastModified }...

Addressed the two remaining reviewer comments in e277615:

  • fetch → $.ajax (comment Fix references to EditorData plugins #3): Converted both HTTP calls to use $.ajaxloadTree uses success/error callbacks to capture Last-Modified from the response header, and isOutdated uses complete to correctly handle both 304 and 200 status codes.
  • Semicolons (comment Fix API filter params #5): Restored semicolons and define(function(require) spacing to match the original file style and surrounding editor modules.

The canImport check used `=== undefined` which returned false even
when the array was empty, blocking every import once the importer
started initialising the array up-front.
@taylortom taylortom changed the title New: Use content tree API for editor data loading Breaking: Use content tree API for editor data loading May 8, 2026
…estamp

Editor data loading now requires:
- adapt-authoring-content with the GET /api/content/tree/:courseId endpoint (^3.0.0)
- adapt-authoring-authored with course timestamp on update (^1.4.0)
@taylortom taylortom changed the title Breaking: Use content tree API for editor data loading Breaking: Use content tree API for editor data loading (fixes #458) May 8, 2026
@taylortom taylortom merged commit 8f3b7a7 into master May 8, 2026
2 checks passed
@taylortom taylortom deleted the feature/tree-api-integration branch May 8, 2026 21:18
github-actions Bot pushed a commit that referenced this pull request May 8, 2026
# [3.0.0](v2.0.7...v3.0.0) (2026-05-08)

### Breaking

* Use content tree API for editor data loading (fixes #458) (#459) ([8f3b7a7](8f3b7a7)), closes [#458](#458) [#459](#459)

### Chore

* Add packages:write permission to release workflow ([9c39a25](9c39a25))
* Use shared semantic-release config ([7bb4ff4](7bb4ff4))
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for content tree

3 participants