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
fix(views/board): column duplication after batch rename
Elian Doran9589164008b4
diff --git a/apps/client/src/widgets/view_widgets/board_view/data.ts b/apps/client/src/widgets/view_widgets/board_view/data.tsindex 8281818966..af36587bae 100644--- a/apps/client/src/widgets/view_widgets/board_view/data.ts+++ b/apps/client/src/widgets/view_widgets/board_view/data.ts@@ -10,30 +10,48 @@ export type ColumnMap = Map<string, {export async function getBoardData(parentNote: FNote, groupByColumn: string, persistedData: BoardData) {const byColumn: ColumnMap = new Map();- // Add back existing columns.- for (const column of persistedData.columns || []) {- byColumn.set(column.value, []);- }-+ // First, scan all notes to find what columns actually existawait recursiveGroupBy(parentNote.getChildBranches(), byColumn, groupByColumn);- let newPersistedData: BoardData | undefined;- // Check if we have new columns.- const existingColumns = persistedData.columns?.map(c => c.value) || [];- for (const column of existingColumns) {- if (!byColumn.has(column)) {- byColumn.set(column, []);+ // Get all columns that exist in the notes+ const columnsFromNotes = [...byColumn.keys()];++ // Get existing persisted columns and preserve their order+ const existingPersistedColumns = persistedData.columns || [];+ const existingColumnValues = existingPersistedColumns.map(c => c.value);++ // Find truly new columns (exist in notes but not in persisted data)+ const newColumnValues = columnsFromNotes.filter(col => !existingColumnValues.includes(col));++ // Build the complete correct column list: existing + new+ const allColumns = [+ ...existingPersistedColumns, // Preserve existing order+ ...newColumnValues.map(value => ({ value })) // Add new columns+ ];++ // Remove duplicates (just in case) and ensure we only keep columns that exist in notes or are explicitly preserved+ const deduplicatedColumns = allColumns.filter((column, index) => {+ const firstIndex = allColumns.findIndex(c => c.value === column.value);+ return firstIndex === index; // Keep only the first occurrence+ });++ // Ensure all persisted columns have empty arrays in byColumn (even if no notes use them)+ for (const column of deduplicatedColumns) {+ if (!byColumn.has(column.value)) {+ byColumn.set(column.value, []);}}- const newColumns = [...byColumn.keys()]- .filter(column => !existingColumns.includes(column))- .map(column => ({ value: column }));-- if (newColumns.length > 0) {+ // Return updated persisted data only if there were changes+ let newPersistedData: BoardData | undefined;+ const hasChanges = newColumnValues.length > 0 ||+ existingPersistedColumns.length !== deduplicatedColumns.length ||+ !existingPersistedColumns.every((col, idx) => deduplicatedColumns[idx]?.value === col.value);++ if (hasChanges) {newPersistedData = {...persistedData,- columns: [...(persistedData.columns || []), ...newColumns]+ columns: deduplicatedColumns};}