Migrate `learn` to the new Resource-layer methods
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
Migrate the learn plugin to the new resource-layer methods, following the shared recipe in #15057.
Complexity: High Target branch: develop
Context
learn currently uses the old resource methods. This task applies the migration recipe from #15057 to this plugin only. The new methods already exist (#15056), and the old ones still work, so this change is isolated to learn.
The Change
Apply the #15057 recipe to every resource usage in learn:
- Replace old base-method calls with the new ones (
fetchModel→retrieve,fetchCollection→list,saveModel→create/update,deleteModel→delete,saveCollection→bulkCreate,deleteCollection→bulkDelete, rawget/list/create). - Remove cache-management calls (
clearCache,getModel,getCollection,addModel, …). - Custom methods: rewrite onto
requestif the resource is defined and used only withinlearn; otherwise add/point at a_v2shared method (see #15057). - Use
useRetrieve/useListfor reactive reads, if possible.
Acceptance Criteria
- [ ] No code in
learncalls the old base methods or cache-management helpers. - [ ] Custom methods handled per the recipe (in-place rewrite for target-only resources, or shared
_v2with the original left intact). - [ ] Reactive reads use
useRetrieve/useListwhere possible. - [ ] Tests that call/mock replaced methods are updated;
pnpm test-jestpasses forlearn.
AI usage
I used Claude Code to help draft this issue from the resource-layer refactor plan. I reviewed and edited it and confirmed the scope myself.
Watching for resolution on behalf of learningequality/kolibri#15061.
Hey @rtibblesbot! I have unmarked the coach issue as a blocker, could you start implementing this task now?
Plan: Move every resource call in kolibri/plugins/learn off the legacy Model/Collection methods onto the new Resource methods from #15056, with no change in runtime behaviour.
- [x] Resource definitions
- [x] Learn composables
- [x] Route-handler modules
- [x] Content-browsing views
- [x] Remaining views and cache-management removal
- [x] Acceptance sweep
Implemented in #15155.
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output
Acceptance criteria from #15059, with the evidence for each. Posted here because this account cannot edit an issue body (UpdateIssue is denied), so the boxes there stay unticked.
- [x] No code in
learncalls the old base methods or cache-management helpers.
$ grep -rnE '\.(fetchModel|fetchCollection|saveModel|deleteModel|saveCollection|deleteCollection|fetchDetailModel|fetchDetailCollection|fetchListCollection|getListEndpoint|postListEndpoint|postDetailEndpoint|accessListEndpoint|accessDetailEndpoint|clearCache|getModel|getCollection|addModel|findModel|removeModel|removeCollection|unCacheModel|unCacheCollection)\b' kolibri/plugins/learn
$ echo $?
1
Anchored on \b rather than ( so .fetchTree.mockResolvedValue in specs is caught too, and so is the stale JSDoc example in apiResources.js, which was updated for that reason.
- [x] Custom methods handled per the recipe. Six
_v2methods added to sharedkolibri-commonresources, each a pure addition with the original left intact for the plugins not yet migrated:ContentNodeResource.fetchTree_v2,fetchBookmarks_v2,fetchRecommendationsFor_v2,fetchRandomCollection_v2,ContentNodeProgressResource.fetchTree_v2,ChannelResource.fetchFilterOptions_v2,RemoteChannelResource.getKolibriStudioStatus_v2.learn's ownLearnerCourseResource.getResumeDatatook the in-place branch — it is defined and used only withinlearn— with an unchanged signature and return.
No learn call site still names an original:
$ grep -rnE '\.(fetchTree|fetchBookmarks|fetchRecommendationsFor|fetchRandomCollection|fetchFilterOptions|getKolibriStudioStatus)\b' kolibri/plugins/learn
$ echo $?
1
-
[x] Reactive reads use
useRetrieve/useListwhere possible — which, inlearn, is nowhere. Scoped to reactive reads, per #15057 step 4 ("if it will become a large refactor, then omit it"). Four groups of call site, none convertible:learn's only threeuseFetchsites are all inCourseUnitView/index.vue: one composes two independent requests into a single object, the other two wrap thefetchTree_v2andgetResumeDatacustom endpoints.Resource.useList'sfetchMethodis() => this.list(toValue(params))— it can only drive the default list endpoint.usePinnedDevices.fetchPinsForUser,useBookmarks.fetchBookmarksanduseContentNodeProgress.*each reshape the response into a module-level shared map that is the composable's public surface.useList'sonSuccessis a side-effect hook, not a mapper, so itsdataref would hold the unshaped response and the map would still need maintaining alongside it.LibraryPage/index.vue's_showChannelsis the closest call — it does write torootNodes/rootNodesLoadingrefs. It still does not convert: it is invoked per(channels, baseurl)pair rather than from reactive params, it re-orders the response against itschannelsargument, and it drops the result behind asamePageCheckGenerator()guarduseListhas no hook for.- Everything else is a one-shot imperative call — Options-API methods and
.then()chains, route handlers, andDeviceConnectionStatus.vue's 5suseTimeoutPoll.
-
[x] Tests that call/mock replaced methods are updated;
pnpm test-jestpasses forlearn. Eight specs updated. Most use bare automocks, so only the names change;CourseUnitView.spec.jsandLearnIndex.spec.jsusejest.mockfactories, where a missing key isundefinedrather than an auto-stub, so their keys were renamed explicitly.
$ pnpm test-jest -- --testPathPatterns 'plugins/learn|apiResources'
Test Suites: 36 passed, 36 total
Tests: 933 passed, 933 total
New spec packages/kolibri-common/apiResources/__tests__/ContentNodeResource.spec.js covers the two overrides that carry real behaviour — the read-through cache, the defensive copy on a cache hit, and list populating the cache. The six _v2 methods are one-line request wrappers and get none.
Two things found on the way, both left alone:
ContentNodeResource.fetchResume,fetchPopular,fetchNextStepsandfetchLessonResourcesare unmigrated. They targetkolibri:core:usercontentnode_list, a different resource name thanthis.requestcan resolve, and they already bypass theModel/Collectionlayer.CustomContentRenderer.vue'ssendRandomCollectionreads.resultsoff what therandomendpoint returns as a bare array, so the sandbox custom-channel API has always receivedundefinedthere. Pre-existing; worth its own issue.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.