Desktop: Make "toggle all folders" button also expand the folder list (#11917)

pull/11929/head
Henry Heino 2025-03-04 03:58:31 -08:00 committed by GitHub
parent b831d8c068
commit 1924dd31d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 0 deletions

View File

@ -1026,6 +1026,7 @@ packages/lib/commands/renderMarkup.test.js
packages/lib/commands/renderMarkup.js
packages/lib/commands/showEditorPlugin.js
packages/lib/commands/synchronize.js
packages/lib/commands/toggleAllFolders.test.js
packages/lib/commands/toggleAllFolders.js
packages/lib/commands/toggleEditorPlugin.js
packages/lib/components/EncryptionConfigScreen/utils.test.js

1
.gitignore vendored
View File

@ -1001,6 +1001,7 @@ packages/lib/commands/renderMarkup.test.js
packages/lib/commands/renderMarkup.js
packages/lib/commands/showEditorPlugin.js
packages/lib/commands/synchronize.js
packages/lib/commands/toggleAllFolders.test.js
packages/lib/commands/toggleAllFolders.js
packages/lib/commands/toggleEditorPlugin.js
packages/lib/components/EncryptionConfigScreen/utils.test.js

View File

@ -0,0 +1,36 @@
import { setupDatabase, switchClient } from '../testing/test-utils';
import { runtime } from './toggleAllFolders';
import Setting from '../models/Setting';
import { CommandContext } from '../services/CommandService';
import { defaultState } from '../reducer';
const command = runtime();
const makeContext = (): CommandContext => {
return {
state: defaultState,
dispatch: ()=>{},
};
};
describe('toggleAllFolders', () => {
beforeEach(async () => {
await setupDatabase(0);
await switchClient(0);
});
test('expanding all should expand the folders header, if previously collapsed', async () => {
Setting.setValue('folderHeaderIsExpanded', false);
// Collapsing all should leave the folder header as-is
const context = makeContext();
await command.execute(context, true);
expect(Setting.value('folderHeaderIsExpanded')).toBe(false);
// Expanding all should also expand the folder header
await command.execute(context, false);
expect(Setting.value('folderHeaderIsExpanded')).toBe(true);
});
});

View File

@ -1,6 +1,7 @@
import { CommandRuntime, CommandDeclaration, CommandContext } from '../services/CommandService';
import { _ } from '../locale';
import getCanBeCollapsedFolderIds from '../models/utils/getCanBeCollapsedFolderIds';
import Setting from '../models/Setting';
export const declaration: CommandDeclaration = {
name: 'toggleAllFolders',
@ -10,6 +11,10 @@ export const declaration: CommandDeclaration = {
export const runtime = (): CommandRuntime => {
return {
execute: async (context: CommandContext, collapseAll: boolean) => {
if (!collapseAll && !Setting.value('folderHeaderIsExpanded')) {
Setting.setValue('folderHeaderIsExpanded', true);
}
context.dispatch({
type: 'FOLDER_SET_COLLAPSED',
ids: collapseAll ? getCanBeCollapsedFolderIds(context.state.folders) : [],