kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Migrate `learn` to the new Resource-layer methods

Open AlexVelezLl opened this issue 4 months ago • 8 comments

❌ 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, raw get/list/create).
  • Remove cache-management calls (clearCache, getModel, getCollection, addModel, …).
  • Custom methods: rewrite onto request if the resource is defined and used only within learn; otherwise add/point at a _v2 shared method (see #15057).
  • Use useRetrieve / useList for reactive reads, if possible.

Acceptance Criteria

  • [ ] No code in learn calls the old base methods or cache-management helpers.
  • [ ] Custom methods handled per the recipe (in-place rewrite for target-only resources, or shared _v2 with the original left intact).
  • [ ] Reactive reads use useRetrieve / useList where possible.
  • [ ] Tests that call/mock replaced methods are updated; pnpm test-jest passes for learn.

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.

AlexVelezLl avatar Jul 23 '26 14:07 AlexVelezLl

Watching for resolution on behalf of learningequality/kolibri#15061.

rtibblesbot avatar Aug 04 '26 14:08 rtibblesbot

Hey @rtibblesbot! I have unmarked the coach issue as a blocker, could you start implementing this task now?

AlexVelezLl avatar Aug 05 '26 19:08 AlexVelezLl

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

rtibblesbot avatar Aug 05 '26 20:08 rtibblesbot

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 learn calls 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 _v2 methods added to shared kolibri-common resources, 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 own LearnerCourseResource.getResumeData took the in-place branch — it is defined and used only within learn — 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/useList where possible — which, in learn, 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 three useFetch sites are all in CourseUnitView/index.vue: one composes two independent requests into a single object, the other two wrap the fetchTree_v2 and getResumeData custom endpoints. Resource.useList's fetchMethod is () => this.list(toValue(params)) — it can only drive the default list endpoint.
    • usePinnedDevices.fetchPinsForUser, useBookmarks.fetchBookmarks and useContentNodeProgress.* each reshape the response into a module-level shared map that is the composable's public surface. useList's onSuccess is a side-effect hook, not a mapper, so its data ref would hold the unshaped response and the map would still need maintaining alongside it.
    • LibraryPage/index.vue's _showChannels is the closest call — it does write to rootNodes/rootNodesLoading refs. It still does not convert: it is invoked per (channels, baseurl) pair rather than from reactive params, it re-orders the response against its channels argument, and it drops the result behind a samePageCheckGenerator() guard useList has no hook for.
    • Everything else is a one-shot imperative call — Options-API methods and .then() chains, route handlers, and DeviceConnectionStatus.vue's 5s useTimeoutPoll.
  • [x] Tests that call/mock replaced methods are updated; pnpm test-jest passes for learn. Eight specs updated. Most use bare automocks, so only the names change; CourseUnitView.spec.js and LearnIndex.spec.js use jest.mock factories, where a missing key is undefined rather 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, fetchNextSteps and fetchLessonResources are unmigrated. They target kolibri:core:usercontentnode_list, a different resource name than this.request can resolve, and they already bypass the Model/Collection layer.
  • CustomContentRenderer.vue's sendRandomCollection reads .results off what the random endpoint returns as a bare array, so the sandbox custom-channel API has always received undefined there. Pre-existing; worth its own issue.

rtibblesbot avatar Aug 06 '26 22:08 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Aug 07 '26 03:08 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Aug 08 '26 01:08 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Aug 08 '26 04:08 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Aug 10 '26 18:08 rtibblesbot