feat(collections/table): support archived notes

This commit is contained in:
Elian Doran 2025-09-12 19:02:10 +03:00
parent 0c0bcb87f9
commit 0a813f9b53
No known key found for this signature in database
3 changed files with 21 additions and 8 deletions

View File

@ -36,6 +36,10 @@
border-right-width: 1px;
}
.tabulator .tabulator-row.archived {
opacity: 0.5;
}
.tabulator .tabulator-footer {
background-color: unset;
padding: 5px 0;

View File

@ -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, saveCon
index="branchId"
movableColumns
movableRows={movableRows}
rowFormatter={rowFormatter}
{...dataTreeProps}
/>
<TableFooter note={note} />
@ -110,6 +115,7 @@ function usePersistence(initialConfig: TableConfig | null | undefined, saveConfi
function 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 | undef
function 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;
}

View File

@ -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: AttributeDef
for (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: AttributeDef
title: 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;