Skip to content

Conversation

bangbangbanggit
Copy link

@bangbangbanggit bangbangbanggit commented Sep 22, 2025

Fixes:

  • Table view tree no longer expands during add row/delete row/edit row operations
  • Expansion/collapse state persists across app restarts and navigation
  • Context menu 'insert row above/below' options remain available
  • No interference with existing table functionality

Features added:

  • Preserve tree expansion state during data refreshes using dataTreeStartExpanded
  • Add localStorage persistence for expansion state across app sessions
  • Track expand/collapse events externally to avoid Tabulator setData() limitations
  • Each note maintains independent expansion state keyed by noteId
  • Prevent visual collapse/re-expand flicker during table operations

Implementation details:

  • Use Tabulator's native dataTreeStartExpanded instead of post-hoc restoration
  • External state tracking with React refs for session persistence
  • localStorage integration for cross-session state preservation
  • Proper event chaining to maintain existing context menu functionality
  • Debounced refresh handling to prevent overlapping state updates

Features added:
- Preserve tree expansion state during data refreshes using dataTreeStartExpanded
- Add localStorage persistence for expansion state across app sessions
- Track expand/collapse events externally to avoid Tabulator setData() limitations
- Each note maintains independent expansion state keyed by noteId
- Prevent visual collapse/re-expand flicker during table operations

Implementation details:
- Use Tabulator's native dataTreeStartExpanded instead of post-hoc restoration
- External state tracking with React refs for session persistence
- localStorage integration for cross-session state preservation
- Proper event chaining to maintain existing context menu functionality
- Debounced refresh handling to prevent overlapping state updates

Fixes:
- Tree nodes no longer collapse during add/delete/edit operations
- Expansion state persists across app restarts and navigation
- Context menu 'insert row above/below' options restored
- No interference with existing table functionality
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 22, 2025
@bangbangbanggit bangbangbanggit changed the title Add tree state preservation for table view Fix tree state preservation for table view Sep 23, 2025
Comment on lines +33 to +45
useEffect(() => {
const storageKey = `trilium-tree-expanded-${note.noteId}`;
try {
const stored = localStorage.getItem(storageKey);
if (stored) {
const expandedIds = JSON.parse(stored);
expandedRowsRef.current = new Set(expandedIds);
console.log('Loaded expansion state from storage:', expandedIds);
}
} catch (e) {
console.warn('Failed to load tree expansion state:', e);
}
}, [note.noteId]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is good but Trilium does not use the local storage feature at all. All data in Trilium is managed within the SQL database. For storing tree expansion state, ideally you should use the already provided view storage see ViewModeProps<TableConfig>.

Since the user can be expanding/collapsing a lot of times, it's best to delay the saving in a spaced update.

Comment on lines +74 to +77
persistenceMode: "local",
persistence: {
tree: true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned previously, we don't store data in local storage, we store it in an attachment inside the note. We must not break this functionality.

...rowEditingEvents
...rowEditingEvents,
tableBuilt: () => {
console.log('Table built - setting up tree event tracking');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many debug logs inside the PR, please get rid of them.

@eliandoran eliandoran marked this pull request as draft September 23, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants