1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Chore: Fixes #9678: Fix API and mobile startup regressions caused by folder refactor (#9679)

This commit is contained in:
Henry Heino 2024-01-08 03:58:11 -08:00 committed by GitHub
parent b9b2d37fdd
commit 94e3582bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View File

@ -46,7 +46,6 @@ const { AppNav } = require('./components/app-nav.js');
import Note from '@joplin/lib/models/Note'; import Note from '@joplin/lib/models/Note';
import Folder from '@joplin/lib/models/Folder'; import Folder from '@joplin/lib/models/Folder';
import BaseSyncTarget from '@joplin/lib/BaseSyncTarget'; import BaseSyncTarget from '@joplin/lib/BaseSyncTarget';
const { FoldersScreenUtils } = require('@joplin/lib/folders-screen-utils.js');
import Resource from '@joplin/lib/models/Resource'; import Resource from '@joplin/lib/models/Resource';
import Tag from '@joplin/lib/models/Tag'; import Tag from '@joplin/lib/models/Tag';
import NoteTag from '@joplin/lib/models/NoteTag'; import NoteTag from '@joplin/lib/models/NoteTag';
@ -516,7 +515,6 @@ async function initialize(dispatch: Function) {
// reg.dispatch = dispatch; // reg.dispatch = dispatch;
BaseModel.dispatch = dispatch; BaseModel.dispatch = dispatch;
FoldersScreenUtils.dispatch = dispatch;
BaseSyncTarget.dispatch = dispatch; BaseSyncTarget.dispatch = dispatch;
NavService.dispatch = dispatch; NavService.dispatch = dispatch;
BaseModel.setDb(db); BaseModel.setDb(db);

View File

@ -109,6 +109,22 @@ describe('services_rest_Api', () => {
expect(response.items.length).toBe(2); 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 () => { it('should fail on invalid paths', (async () => {
const hasThrown = await checkThrowAsync(async () => await api.route(RequestMethod.GET, 'schtroumpf')); const hasThrown = await checkThrowAsync(async () => await api.route(RequestMethod.GET, 'schtroumpf'));
expect(hasThrown).toBe(true); expect(hasThrown).toBe(true);

View File

@ -5,13 +5,13 @@ import paginatedResults from '../utils/paginatedResults';
import BaseModel from '../../../BaseModel'; import BaseModel from '../../../BaseModel';
import requestFields from '../utils/requestFields'; import requestFields from '../utils/requestFields';
import Folder from '../../../models/Folder'; import Folder from '../../../models/Folder';
const { FoldersScreenUtils } = require('../../../folders-screen-utils.js'); import { allForDisplay } from '../../../folders-screen-utils';
const { ErrorNotFound } = require('../utils/errors'); const { ErrorNotFound } = require('../utils/errors');
export default async function(request: Request, id: string = null, link: string = null) { export default async function(request: Request, id: string = null, link: string = null) {
if (request.method === 'GET' && !id) { if (request.method === 'GET' && !id) {
if (request.query.as_tree) { 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); const output = await Folder.allAsTree(folders);
return output; return output;
} else { } else {