Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/collections/table): bring back dragging rows

Elian Doran6eea921820a2
diff --git a/apps/client/src/widgets/collections/table/editing.ts b/apps/client/src/widgets/collections/table/editing.ts
index e71aa7bb4d..b8d66ea7f7 100644
--- a/apps/client/src/widgets/collections/table/editing.ts
+++ b/apps/client/src/widgets/collections/table/editing.ts
@@ -6,6 +6,8 @@ import { RefObject } from "preact";
import { setAttribute, setLabel } from "../../../services/attributes";
import froca from "../../../services/froca";
import server from "../../../services/server";
+import FNote from "../../../entities/fnote";
+import branches from "../../../services/branches";
export default function useTableEditing(api: RefObject<Tabulator>, parentNotePath: string): Partial<EventCallBackMethods> {
// Adding new rows
@@ -55,6 +57,20 @@ export default function useTableEditing(api: RefObject<Tabulator>, parentNotePat
}
}
}
+ },
+ rowMoved(row) {
+ const branchIdsToMove = [ row.getData().branchId ];
+
+ const prevRow = row.getPrevRow();
+ if (prevRow) {
+ branches.moveAfterBranch(branchIdsToMove, prevRow.getData().branchId);
+ return;
+ }
+
+ const nextRow = row.getNextRow();
+ if (nextRow) {
+ branches.moveBeforeBranch(branchIdsToMove, nextRow.getData().branchId);
+ }
}
};
}
@@ -87,3 +103,8 @@ function findRowDataById(rows: RowComponent[], branchId: string): RowComponent |
}
return null;
}
+
+export function canReorderRows(parentNote: FNote) {
+ return !parentNote.hasLabel("sorted")
+ && parentNote.type !== "search";
+}
diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsx
index f880d4873f..5326229829 100644
--- a/apps/client/src/widgets/collections/table/index.tsx
+++ b/apps/client/src/widgets/collections/table/index.tsx
@@ -3,7 +3,6 @@ import { ViewModeProps } from "../interface";
import { buildColumnDefinitions } from "./columns";
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
import { useNoteLabelInt, useSpacedUpdate } from "../../react/hooks";
-import { canReorderRows } from "../../view_widgets/table_view/dragging";
import Tabulator from "./tabulator";
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables';
import { useContextMenu } from "./context_menu";
@@ -12,7 +11,7 @@ import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import Button from "../../react/Button";
import "./index.css";
-import useTableEditing from "./editing";
+import useTableEditing, { canReorderRows } from "./editing";
interface TableConfig {
tableData?: {
diff --git a/apps/client/src/widgets/view_widgets/table_view/dragging.ts b/apps/client/src/widgets/view_widgets/table_view/dragging.ts
deleted file mode 100644
index 39d5a0178f..0000000000
--- a/apps/client/src/widgets/view_widgets/table_view/dragging.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import type { Tabulator } from "tabulator-tables";
-import type FNote from "../../../entities/fnote.js";
-import branches from "../../../services/branches.js";
-
-export function canReorderRows(parentNote: FNote) {
- return !parentNote.hasLabel("sorted")
- && parentNote.type !== "search";
-}
-
-export function configureReorderingRows(tabulator: Tabulator) {
- tabulator.on("rowMoved", (row) => {
- const branchIdsToMove = [ row.getData().branchId ];
-
- const prevRow = row.getPrevRow();
- if (prevRow) {
- branches.moveAfterBranch(branchIdsToMove, prevRow.getData().branchId);
- return;
- }
-
- const nextRow = row.getNextRow();
- if (nextRow) {
- branches.moveBeforeBranch(branchIdsToMove, nextRow.getData().branchId);
- }
- });
-}