mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
This commit is contained in:
parent
7d068cfb87
commit
32141d4e23
@ -21,7 +21,7 @@ import { FolderEntity } from '@joplin/lib/services/database/types';
|
||||
import { State } from '@joplin/lib/reducer';
|
||||
import CustomButton from './CustomButton';
|
||||
import FolderPicker from './FolderPicker';
|
||||
import { getTrashFolderId, itemIsInTrash } from '@joplin/lib/services/trash';
|
||||
import { itemIsInTrash } from '@joplin/lib/services/trash';
|
||||
import restoreItems from '@joplin/lib/services/trash/restoreItems';
|
||||
import { ModelType } from '@joplin/lib/BaseModel';
|
||||
|
||||
@ -588,7 +588,7 @@ class ScreenHeaderComponent extends PureComponent<ScreenHeaderProps, ScreenHeade
|
||||
}
|
||||
}}
|
||||
mustSelect={!!folderPickerOptions.mustSelect}
|
||||
folders={this.props.folders.filter(f => f.id !== getTrashFolderId())}
|
||||
folders={Folder.getRealFolders(this.props.folders)}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
|
@ -10,7 +10,6 @@ const { dialogs } = require('../../utils/dialogs.js');
|
||||
const { _ } = require('@joplin/lib/locale');
|
||||
const { default: FolderPicker } = require('../FolderPicker');
|
||||
const TextInput = require('../TextInput').default;
|
||||
const { getTrashFolderId } = require('@joplin/lib/services/trash');
|
||||
|
||||
class FolderScreenComponent extends BaseScreenComponent {
|
||||
static navigationOptions() {
|
||||
@ -108,7 +107,7 @@ class FolderScreenComponent extends BaseScreenComponent {
|
||||
<FolderPicker
|
||||
themeId={this.props.themeId}
|
||||
placeholder={_('Select parent notebook')}
|
||||
folders={this.props.folders.filter(f => f.id !== getTrashFolderId())}
|
||||
folders={Folder.getRealFolders(this.props.folders)}
|
||||
selectedFolderId={this.state.folder.parent_id}
|
||||
onValueChange={newValue => this.parent_changeValue(newValue)}
|
||||
mustSelect
|
||||
|
@ -353,6 +353,27 @@ describe('models/Folder', () => {
|
||||
await expectThrow(async () => Folder.delete(folder2.id, { toTrash: true, toTrashParentId: folder2.id }));
|
||||
});
|
||||
|
||||
it('should filter out the trash folder and the deleted folders', async () => {
|
||||
let folders: FolderEntity[] = [];
|
||||
|
||||
expect(Folder.getRealFolders(folders).length).toBe(0);
|
||||
|
||||
const folder1 = await Folder.save({});
|
||||
const folder2 = await Folder.save({ parent_id: folder1.id });
|
||||
const folder3 = await Folder.save({ parent_id: folder2.id });
|
||||
|
||||
folders = await Folder.all();
|
||||
expect(Folder.getRealFolders(folders).sort((a, b) => a.created_time - b.created_time)).toEqual([folder1, folder2, folder3]);
|
||||
|
||||
await Folder.delete(folder2.id, { toTrash: true });
|
||||
folders = await Folder.all();
|
||||
expect(Folder.getRealFolders(folders)).toEqual([folder1]);
|
||||
|
||||
await Folder.delete(folder1.id, { toTrash: true });
|
||||
folders = await Folder.all();
|
||||
expect(Folder.getRealFolders(folders).length).toBe(0);
|
||||
});
|
||||
|
||||
it('should tell if at least one folder other than trash and deleted exists', async () => {
|
||||
let folders: FolderEntity[] = [];
|
||||
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(false);
|
||||
|
@ -936,10 +936,15 @@ export default class Folder extends BaseItem {
|
||||
return !!folders.find(f => !!f.icon);
|
||||
}
|
||||
|
||||
public static getRealFolders(folders: FolderEntity[]) {
|
||||
// returns all folders other than trash folder and deleted folders
|
||||
const trashFolderId = getTrashFolderId();
|
||||
return folders.filter((folder) => folder.id !== trashFolderId && folder.deleted_time === 0);
|
||||
}
|
||||
|
||||
public static atLeastOneRealFolderExists(folders: FolderEntity[]) {
|
||||
// returns true if at least one folder exists other than trash folder and deleted folders
|
||||
const trashFolderId = getTrashFolderId();
|
||||
return folders.filter((folder) => folder.id !== trashFolderId && folder.deleted_time === 0).length > 0;
|
||||
return this.getRealFolders(folders).length > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user