-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix tree state preservation for table view #7056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix tree state preservation for table view #7056
Conversation
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
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]); |
There was a problem hiding this comment.
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.
persistenceMode: "local", | ||
persistence: { | ||
tree: true | ||
} |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
Fixes:
Features added:
Implementation details: