Skip to content

Build your personal knowledge base with Trilium Notes

feat(collections/table): disable "Insert row above/below" if sorting

Elian Doran68beb0d41904
diff --git a/apps/client/src/widgets/collections/table/context_menu.ts b/apps/client/src/widgets/collections/table/context_menu.ts
index 37caf16635..16cbd39ff5 100644
--- a/apps/client/src/widgets/collections/table/context_menu.ts
+++ b/apps/client/src/widgets/collections/table/context_menu.ts
@@ -160,6 +160,7 @@ function showHeaderContextMenu(parentComponent: Component, e: MouseEvent, tabula
export function showRowContextMenu(parentComponent: Component, e: MouseEvent, row: RowComponent, parentNote: FNote, tabulator: Tabulator) {
const rowData = row.getData() as TableData;
+ const sorters = tabulator.getSorters();
let parentNoteId: string = parentNote.noteId;
@@ -177,6 +178,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
{
title: t("table_view.row-insert-above"),
uiIcon: "bx bx-horizontal-left bx-rotate-90",
+ enabled: !sorters.length,
handler: () => parentComponent?.triggerCommand("addNewRow", {
parentNotePath: parentNoteId,
customOpts: {
@@ -203,6 +205,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
{
title: t("table_view.row-insert-below"),
uiIcon: "bx bx-horizontal-left bx-rotate-270",
+ enabled: !sorters.length,
handler: () => parentComponent?.triggerCommand("addNewRow", {
parentNotePath: parentNoteId,
customOpts: {
diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsx
index 0c4e3e8f88..40f5310c6e 100644
--- a/apps/client/src/widgets/collections/table/index.tsx
+++ b/apps/client/src/widgets/collections/table/index.tsx
@@ -2,7 +2,7 @@ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "p
import { ViewModeProps } from "../interface";
import { buildColumnDefinitions } from "./columns";
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
-import { useLegacyWidget, useNoteLabel, useNoteLabelBoolean, useNoteLabelInt, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";
+import { useLegacyWidget, useNoteLabelBoolean, useNoteLabelInt, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";
import Tabulator from "./tabulator";
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options, RowComponent} from 'tabulator-tables';
import { useContextMenu } from "./context_menu";