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
refactor(collections/board): use API to reorder column
Elian Doranf300b6c8a2b9
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.tsindex 7188ef699f..c4cca678ae 100644--- a/apps/client/src/widgets/collections/board/api.ts+++ b/apps/client/src/widgets/collections/board/api.ts@@ -99,6 +99,23 @@ export default class BoardApi {this.saveConfig(this.viewConfig);}+ reorderColumn(fromIndex: number, toIndex: number) {+ if (!this.columns || fromIndex === toIndex) return;++ const newColumns = [...this.columns];+ const [movedColumn] = newColumns.splice(fromIndex, 1);+ newColumns.splice(toIndex, 0, movedColumn);++ // Update view config with new column order+ const newViewConfig = {+ ...this.viewConfig,+ columns: newColumns.map(col => ({ value: col }))+ };++ this.saveConfig(newViewConfig);+ return newColumns;+ }+async insertRowAtPosition(column: string,relativeToBranchId: string,diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 4837035529..2dc71b6473 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -91,23 +91,11 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveCuseEffect(refresh, [ parentNote, noteIds, viewConfig ]);const handleColumnDrop = useCallback((fromIndex: number, toIndex: number) => {- if (!columns || fromIndex === toIndex) return;-- const newColumns = [...columns];- const [movedColumn] = newColumns.splice(fromIndex, 1);- newColumns.splice(toIndex, 0, movedColumn);-- // Update view config with new column order- const newViewConfig = {- ...viewConfig,- columns: newColumns.map(col => ({ value: col }))- };-- saveConfig(newViewConfig);+ const newColumns = api.reorderColumn(fromIndex, toIndex);setColumns(newColumns);setDraggedColumn(null);setColumnDropPosition(null);- }, [columns, viewConfig, saveConfig]);+ }, [api]);useTriliumEvent("entitiesReloaded", ({ loadResults }) => {// Check if any changes affect our boarddiff --git a/apps/client/src/widgets/view_widgets/board_view/api.ts b/apps/client/src/widgets/view_widgets/board_view/api.tsdeleted file mode 100644index 42eda932ea..0000000000--- a/apps/client/src/widgets/view_widgets/board_view/api.ts+++ /dev/null@@ -1,84 +0,0 @@-import appContext from "../../../components/app_context";-import FNote from "../../../entities/fnote";-import attributes from "../../../services/attributes";-import { executeBulkActions } from "../../../services/bulk_action";-import note_create from "../../../services/note_create";-import ViewModeStorage from "../view_mode_storage";-import { BoardData } from "./config";-import { ColumnMap, getBoardData } from "./data";--export default class BoardApi {-- private constructor(- private _columns: string[],- private _parentNoteId: string,- private viewStorage: ViewModeStorage<BoardData>,- private byColumn: ColumnMap,- private persistedData: BoardData,- private _statusAttribute: string) {}-- get columns() {- return this._columns;- }-- get statusAttribute() {- return this._statusAttribute;- }-- getColumn(column: string) {- return this.byColumn.get(column);- }-- async reorderColumns(newColumnOrder: string[]) {- // Update the co lumn order in persisted data- if (!this.persistedData.columns) {- this.persistedData.columns = [];- }-- // Create a map of existing column data- const columnDataMap = new Map();- this.persistedData.columns.forEach(col => {- columnDataMap.set(col.value, col);- });-- // Reorder columns based on new order- this.persistedData.columns = newColumnOrder.map(columnValue => {- return columnDataMap.get(columnValue) || { value: columnValue };- });-- // Update internal columns array- this._columns = newColumnOrder;-- await this.viewStorage.store(this.persistedData);- }-- async refresh(parentNote: FNote) {- // Refresh the API data by re-fetching from the parent note-- // Use the current in-memory persisted data instead of restoring from storage- // This ensures we don't lose recent updates like column renames-- // Update internal state- this.byColumn = byColumn;-- if (newPersistedData) {- this.persistedData = newPersistedData;- this.viewStorage.store(this.persistedData);- }-- // Use the order from persistedData.columns, then add any new columns found- const orderedColumns = this.persistedData.columns?.map(col => col.value) || [];- const allColumns = Array.from(byColumn.keys());- const newColumns = allColumns.filter(col => !orderedColumns.includes(col));- this._columns = [...orderedColumns, ...newColumns];- }-- static async build(parentNote: FNote, viewStorage: ViewModeStorage<BoardData>) {- const statusAttribute = parentNote.getLabelValue("board:groupBy") ?? "status";-- let persistedData = await viewStorage.restore() ?? {};-- return new BoardApi(columns, parentNote.noteId, viewStorage, byColumn, persistedData, statusAttribute);- }--}