Skip to content

Build your personal knowledge base with Trilium Notes

fix(table): does not respect protected note of parent

Elian Dorana6a1594265f6
diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsx
index 87745b3e2d..b4c49faf70 100644
--- a/apps/client/src/widgets/collections/table/index.tsx
+++ b/apps/client/src/widgets/collections/table/index.tsx
@@ -18,14 +18,14 @@ import useRowTableEditing from "./row_editing";
import { TableData } from "./rows";
import Tabulator from "./tabulator";
-export default function TableView({ note, noteIds, notePath, viewConfig, saveConfig }: ViewModeProps<TableConfig>) {
+export default function TableView({ note, noteIds, viewConfig, saveConfig }: ViewModeProps<TableConfig>) {
const tabulatorRef = useRef<VanillaTabulator>(null);
const parentComponent = useContext(ParentComponent);
const [ attributeDetailWidgetEl, attributeDetailWidget ] = useLegacyWidget(() => new AttributeDetailWidget().contentSized());
const contextMenuEvents = useContextMenu(note, parentComponent, tabulatorRef);
const persistenceProps = usePersistence(viewConfig, saveConfig);
- const rowEditingEvents = useRowTableEditing(tabulatorRef, attributeDetailWidget, notePath);
+ const rowEditingEvents = useRowTableEditing(tabulatorRef, attributeDetailWidget, note);
const { newAttributePosition, resetNewAttributePosition } = useColTableEditing(tabulatorRef, attributeDetailWidget, note);
const { columnDefs, rowData, movableRows, hasChildren } = useData(note, noteIds, viewConfig, newAttributePosition, resetNewAttributePosition);
const dataTreeProps = useMemo<Options>(() => {
diff --git a/apps/client/src/widgets/collections/table/row_editing.ts b/apps/client/src/widgets/collections/table/row_editing.ts
index 22ef0e7e48..c4df69e7ae 100644
--- a/apps/client/src/widgets/collections/table/row_editing.ts
+++ b/apps/client/src/widgets/collections/table/row_editing.ts
@@ -1,24 +1,27 @@
+import { RefObject } from "preact";
import { EventCallBackMethods, RowComponent, Tabulator } from "tabulator-tables";
+
import { CommandListenerData } from "../../../components/app_context";
-import note_create, { CreateNoteOpts } from "../../../services/note_create";
-import { useLegacyImperativeHandlers } from "../../react/hooks";
-import { RefObject } from "preact";
+import FNote from "../../../entities/fnote";
import { setAttribute, setLabel } from "../../../services/attributes";
+import branches from "../../../services/branches";
import froca from "../../../services/froca";
+import note_create, { CreateNoteOpts } from "../../../services/note_create";
import server from "../../../services/server";
-import branches from "../../../services/branches";
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
+import { useLegacyImperativeHandlers } from "../../react/hooks";
-export default function useRowTableEditing(api: RefObject<Tabulator>, attributeDetailWidget: AttributeDetailWidget, parentNotePath: string): Partial<EventCallBackMethods> {
+export default function useRowTableEditing(api: RefObject<Tabulator>, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote): Partial<EventCallBackMethods> {
// Adding new rows
useLegacyImperativeHandlers({
addNewRowCommand({ customOpts, parentNotePath: customNotePath }: CommandListenerData<"addNewRow">) {
- const notePath = customNotePath ?? parentNotePath;
+ const notePath = customNotePath ?? parentNote.noteId;
if (notePath) {
const opts: CreateNoteOpts = {
activate: false,
+ isProtected: parentNote.isProtected,
...customOpts
- }
+ };
note_create.createNote(notePath, opts).then(({ branch }) => {
if (branch) {
setTimeout(() => {
@@ -26,7 +29,7 @@ export default function useRowTableEditing(api: RefObject<Tabulator>, attributeD
focusOnBranch(api.current, branch?.branchId);
}, 100);
}
- })
+ });
}
}
});
@@ -91,14 +94,14 @@ function focusOnBranch(api: Tabulator, branchId: string) {
}
function findRowDataById(rows: RowComponent[], branchId: string): RowComponent | null {
- for (let row of rows) {
+ for (const row of rows) {
const item = row.getIndex() as string;
if (item === branchId) {
return row;
}
- let found = findRowDataById(row.getTreeChildren(), branchId);
+ const found = findRowDataById(row.getTreeChildren(), branchId);
if (found) return found;
}
return null;