From 94e3582bb83a154fc5bc42d35866abab43ad5978 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Mon, 8 Jan 2024 03:58:11 -0800 Subject: [PATCH] Chore: Fixes #9678: Fix API and mobile startup regressions caused by folder refactor (#9679) --- packages/app-mobile/root.tsx | 2 -- packages/lib/services/rest/Api.test.ts | 16 ++++++++++++++++ packages/lib/services/rest/routes/folders.ts | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/app-mobile/root.tsx b/packages/app-mobile/root.tsx index 5af588d36..53511be49 100644 --- a/packages/app-mobile/root.tsx +++ b/packages/app-mobile/root.tsx @@ -46,7 +46,6 @@ const { AppNav } = require('./components/app-nav.js'); import Note from '@joplin/lib/models/Note'; import Folder from '@joplin/lib/models/Folder'; import BaseSyncTarget from '@joplin/lib/BaseSyncTarget'; -const { FoldersScreenUtils } = require('@joplin/lib/folders-screen-utils.js'); import Resource from '@joplin/lib/models/Resource'; import Tag from '@joplin/lib/models/Tag'; import NoteTag from '@joplin/lib/models/NoteTag'; @@ -516,7 +515,6 @@ async function initialize(dispatch: Function) { // reg.dispatch = dispatch; BaseModel.dispatch = dispatch; - FoldersScreenUtils.dispatch = dispatch; BaseSyncTarget.dispatch = dispatch; NavService.dispatch = dispatch; BaseModel.setDb(db); diff --git a/packages/lib/services/rest/Api.test.ts b/packages/lib/services/rest/Api.test.ts index 5cfabbd65..c78d84334 100644 --- a/packages/lib/services/rest/Api.test.ts +++ b/packages/lib/services/rest/Api.test.ts @@ -109,6 +109,22 @@ describe('services_rest_Api', () => { expect(response.items.length).toBe(2); })); + it('should return folders as a tree', async () => { + const folder1 = await Folder.save({ title: 'Folder 1' }); + await Folder.save({ title: 'Folder 2', parent_id: folder1.id }); + await Folder.save({ title: 'Folder 3', parent_id: folder1.id }); + + const response = await api.route(RequestMethod.GET, 'folders', { as_tree: 1 }); + expect(response).toMatchObject([{ + title: 'Folder 1', + id: folder1.id, + children: [ + { title: 'Folder 2' }, + { title: 'Folder 3' }, + ], + }]); + }); + it('should fail on invalid paths', (async () => { const hasThrown = await checkThrowAsync(async () => await api.route(RequestMethod.GET, 'schtroumpf')); expect(hasThrown).toBe(true); diff --git a/packages/lib/services/rest/routes/folders.ts b/packages/lib/services/rest/routes/folders.ts index 889e1f4f5..b6efa3ce6 100644 --- a/packages/lib/services/rest/routes/folders.ts +++ b/packages/lib/services/rest/routes/folders.ts @@ -5,13 +5,13 @@ import paginatedResults from '../utils/paginatedResults'; import BaseModel from '../../../BaseModel'; import requestFields from '../utils/requestFields'; import Folder from '../../../models/Folder'; -const { FoldersScreenUtils } = require('../../../folders-screen-utils.js'); +import { allForDisplay } from '../../../folders-screen-utils'; const { ErrorNotFound } = require('../utils/errors'); export default async function(request: Request, id: string = null, link: string = null) { if (request.method === 'GET' && !id) { if (request.query.as_tree) { - const folders = await FoldersScreenUtils.allForDisplay({ fields: requestFields(request, BaseModel.TYPE_FOLDER) }); + const folders = await allForDisplay({ fields: requestFields(request, BaseModel.TYPE_FOLDER) }); const output = await Folder.allAsTree(folders); return output; } else {