Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(collections/list): checkboxes for expand depth
Elian Doran45d2e1f5e22a
diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsxindex 7a5f9b6b18..80627151f1 100644--- a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx+++ b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx@@ -116,20 +116,13 @@ function SplitButtonPropertyView({ note, property }: { note: FNote, property: SptriggerCommand: parentComponent.triggerCommand.bind(parentComponent)};+ const ItemsComponent = property.items;return <SplitButtontext={property.label}icon={property.icon}onClick={() => clickContext && property.onClick(clickContext)}>- {clickContext && property.items.map(subproperty => {- if ("type" in subproperty && subproperty) {- return <FormDropdownDivider />- }-- return (- <FormListItem onClick={() => clickContext && subproperty.onClick(clickContext)}>{subproperty.label}</FormListItem>- );- })}+ {parentComponent && <ItemsComponent note={note} parentComponent={parentComponent} />}</SplitButton>}diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.ts b/apps/client/src/widgets/ribbon/collection-properties-config.tsxsimilarity index 80%rename from apps/client/src/widgets/ribbon/collection-properties-config.tsrename to apps/client/src/widgets/ribbon/collection-properties-config.tsxindex 5161e14962..c0827d8b2a 100644--- a/apps/client/src/widgets/ribbon/collection-properties-config.ts+++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx@@ -6,6 +6,10 @@ import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS, type MapLayer } from "../collectionimport { ViewTypeOptions } from "../collections/interface";import { FilterLabelsByType } from "@triliumnext/commons";import { DEFAULT_THEME, getPresentationThemes } from "../collections/presentation/themes";+import { VNode } from "preact";+import { useNoteLabel } from "../react/hooks";+import { FormDropdownDivider, FormListItem } from "../react/FormList";+import Component from "../../components/component";interface BookConfig {properties: BookProperty[];@@ -27,12 +31,7 @@ export interface ButtonProperty {export interface SplitButtonProperty extends Omit<ButtonProperty, "type"> {type: "split-button";- items: ({- label: string;- onClick(context: BookContext): void;- } | {- type: "separator"- })[];+ items({ note, parentComponent }: { note: FNote, parentComponent: Component }): VNode;}export interface NumberProperty {@@ -100,34 +99,7 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {type: "split-button",icon: "bx bx-move-vertical",onClick: buildExpandListHandler(1),- items: [- {- label: "Expand 1 level",- onClick: buildExpandListHandler(1)- },- { type: "separator" },- {- label: "Expand 2 levels",- onClick: buildExpandListHandler(2),- },- {- label: "Expand 3 levels",- onClick: buildExpandListHandler(3),- },- {- label: "Expand 4 levels",- onClick: buildExpandListHandler(4),- },- {- label: "Expand 5 levels",- onClick: buildExpandListHandler(5),- },- { type: "separator" },- {- label: "Expand all children",- onClick: buildExpandListHandler("all"),- }- ]+ items: ListExpandDepth}]},@@ -217,6 +189,33 @@ function buildMapLayer([ id, layer ]: [ string, MapLayer ]): ComboBoxItem {};}+function ListExpandDepth(context: { note: FNote, parentComponent: Component }) {+ const [ currentDepth ] = useNoteLabel(context.note, "expanded");++ return (+ <>+ <ListExpandDepthButton label="Expand 1 level" depth={1} {...context} checked={currentDepth === ""} />+ <FormDropdownDivider />+ {Array.from({ length: 4 }, (_, i) => i + 2).map(depth => [+ <ListExpandDepthButton label={`Expand ${depth} levels`} depth={depth} {...context} checked={!!currentDepth && parseInt(currentDepth, 10) === depth} />+ ])}+ <FormDropdownDivider />+ <ListExpandDepthButton label="Expand all levels" depth="all" checked={currentDepth === "all"} {...context} />+ </>+ )+}++function ListExpandDepthButton({ label, depth, note, parentComponent, checked }: { label: string, depth: number | "all", note: FNote, parentComponent: Component, checked?: boolean }) {+ const handler = buildExpandListHandler(depth);++ return (+ <FormListItem+ onClick={() => handler({ note, triggerCommand: parentComponent.triggerCommand.bind(parentComponent) })}+ checked={checked}+ >{label}</FormListItem>+ );+}+function buildExpandListHandler(depth: number | "all") {return async ({ note, triggerCommand }: BookContext) => {const { noteId } = note;