Skip to content

Commit

Permalink
feat: added item customization callback to folder accordion hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zovomat committed May 11, 2022
1 parent dff2ee0 commit 94c0e03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/store/folder/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,32 @@ export const useFoldersByView = (view: FolderView): Array<Folder> => {

export const useFoldersAccordionByView = (
view: FolderView,
CustomComponent: ComponentType<{ folder: Folder }>
CustomComponent: ComponentType<{ folder: Folder }>,
itemProps?: (item: AccordionFolder) => Record<string, any>
): Array<AccordionFolder> => {
const roots = useRoots();
return useMemo(
() =>
roots
? mapNodes<Folder, AccordionFolder>(Object.values(roots), {
mapFunction: (f) => ({
id: f.id,
label: f.name,
CustomComponent,
items: [],
folder: f,
disableHover: isRoot(f)
}),
mapFunction: (f) => {
const item = {
id: f.id,
label: f.name,
CustomComponent,
items: [],
folder: f,
disableHover: isRoot(f)
};
const props = itemProps?.(item) ?? {};
return { ...item, ...props };
},
filterFunction: folderViewFilter(view),
recursionKey: 'items',
sortFunction: sortFolders,
deep: false
})
: [],
[CustomComponent, roots, view]
[CustomComponent, itemProps, roots, view]
);
};
5 changes: 3 additions & 2 deletions types/exports/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
SoapFetch
} from '../account';
import { Mods, TagActionResponse, CreateTagResponse, SoapNotify, SoapRefresh } from '../network';
import { HistoryParams, ShellModes } from '../misc';
import { HistoryParams, ShellModes, AccordionFolder } from '../misc';
import { Tag, Tags } from '../tags';
import { Folder, Folders } from '../folder';
import { QueryChip } from '../search';
Expand Down Expand Up @@ -219,7 +219,8 @@ export const useFoldersByView: (view: string) => Array<Folder>;

export const useFoldersAccordionByView: (
view: string,
CustomComponent: ComponentType<{ folder: Folder }>
CustomComponent: ComponentType<{ folder: Folder }>,
itemProps?: (item: AccordionFolder) => Record<string, any>
) => Array<AccordionFolder>;

// Run Search
Expand Down
1 change: 1 addition & 0 deletions types/misc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { i18n } from 'i18next';
import { ComponentType } from 'react';
import { CarbonioModule, PanelMode } from '../apps';

// eslint-disable-next-line no-shadow
export enum JSNS {
ACCOUNT = 'urn:zimbraAccount',
ADMIN = 'urn:zimbraAdmin',
Expand Down

0 comments on commit 94c0e03

Please sign in to comment.