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/table): support archived notes
Elian Doran0a813f9b5361
diff --git a/apps/client/src/widgets/collections/table/index.css b/apps/client/src/widgets/collections/table/index.cssindex cc1eb13298..48249b0c90 100644--- a/apps/client/src/widgets/collections/table/index.css+++ b/apps/client/src/widgets/collections/table/index.css@@ -36,6 +36,10 @@border-right-width: 1px;}+.tabulator .tabulator-row.archived {+ opacity: 0.5;+}+.tabulator .tabulator-footer {background-color: unset;padding: 5px 0;diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsxindex fc2e71a7bd..0c4e3e8f88 100644--- a/apps/client/src/widgets/collections/table/index.tsx+++ b/apps/client/src/widgets/collections/table/index.tsx@@ -4,7 +4,7 @@ import { buildColumnDefinitions } from "./columns";import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";import { useLegacyWidget, useNoteLabel, useNoteLabelBoolean, useNoteLabelInt, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";import Tabulator from "./tabulator";-import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables';+import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options, RowComponent} from 'tabulator-tables';import { useContextMenu } from "./context_menu";import { ParentComponent } from "../../react/react_utils";import FNote from "../../../entities/fnote";@@ -46,6 +46,11 @@ export default function TableView({ note, noteIds, notePath, viewConfig, saveCon}}, [ hasChildren ]);+ const rowFormatter = useCallback((row: RowComponent) => {+ const data = row.getData() as TableData;+ row.getElement().classList.toggle("archived", !!data.isArchived);+ }, []);+return (<div className="table-view">{columnDefs && (@@ -66,7 +71,7 @@ export default function TableView({ note, noteIds, notePath, viewConfig, saveConindex="branchId"movableColumnsmovableRows={movableRows}-+ rowFormatter={rowFormatter}{...dataTreeProps}/><TableFooter note={note} />@@ -110,6 +115,7 @@ function usePersistence(initialConfig: TableConfig | null | undefined, saveConfifunction useData(note: FNote, noteIds: string[], viewConfig: TableConfig | undefined, newAttributePosition: RefObject<number | undefined>, resetNewAttributePosition: () => void) {const [ maxDepth ] = useNoteLabelInt(note, "maxNestingDepth") ?? -1;+ const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");const [ columnDefs, setColumnDefs ] = useState<ColumnDefinition[]>();const [ rowData, setRowData ] = useState<TableData[]>();@@ -119,7 +125,7 @@ function useData(note: FNote, noteIds: string[], viewConfig: TableConfig | undeffunction refresh() {const info = getAttributeDefinitionInformation(note);- buildRowDefinitions(note, info, maxDepth).then(({ definitions: rowData, hasSubtree: hasChildren, rowNumber }) => {+ buildRowDefinitions(note, info, includeArchived, maxDepth).then(({ definitions: rowData, hasSubtree: hasChildren, rowNumber }) => {const columnDefs = buildColumnDefinitions({info,movableRows,@@ -149,7 +155,8 @@ function useData(note: FNote, noteIds: string[], viewConfig: TableConfig | undef// React to external row updates.if (loadResults.getBranchRows().some(branch => branch.parentNoteId === note.noteId || noteIds.includes(branch.parentNoteId ?? ""))|| loadResults.getNoteIds().some(noteId => noteIds.includes(noteId))- || loadResults.getAttributeRows().some(attr => noteIds.includes(attr.noteId!))) {+ || loadResults.getAttributeRows().some(attr => noteIds.includes(attr.noteId!))+ || loadResults.getAttributeRows().some(attr => attr.name === "archived" && attr.noteId && noteIds.includes(attr.noteId))) {refresh();return;}diff --git a/apps/client/src/widgets/collections/table/rows.ts b/apps/client/src/widgets/collections/table/rows.tsindex 460f169acb..84b4c5882d 100644--- a/apps/client/src/widgets/collections/table/rows.ts+++ b/apps/client/src/widgets/collections/table/rows.ts@@ -10,10 +10,11 @@ export type TableData = {relations: Record<string, boolean | string | null>;branchId: string;colorClass: string | undefined;+ isArchived: boolean;_children?: TableData[];};-export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDefinitionInformation[], maxDepth = -1, currentDepth = 0) {+export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDefinitionInformation[], includeArchived: boolean, maxDepth = -1, currentDepth = 0) {const definitions: TableData[] = [];const childBranches = parentNote.getChildBranches();let hasSubtree = false;@@ -21,8 +22,8 @@ export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDeffor (const branch of childBranches) {const note = await branch.getNote();- if (!note) {- continue; // Skip if the note is not found+ if (!note || (!includeArchived && note.isArchived)) {+ continue;}const labels: typeof definitions[0]["labels"] = {};@@ -41,12 +42,13 @@ export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDeftitle: note.title,labels,relations,+ isArchived: note.isArchived,branchId: branch.branchId,colorClass: note.getColorClass()}if (note.hasChildren() && (maxDepth < 0 || currentDepth < maxDepth)) {- const { definitions, rowNumber: subRowNumber } = (await buildRowDefinitions(note, infos, maxDepth, currentDepth + 1));+ const { definitions, rowNumber: subRowNumber } = (await buildRowDefinitions(note, infos, includeArchived, maxDepth, currentDepth + 1));def._children = definitions;hasSubtree = true;rowNumber += subRowNumber;