From 470d7eee31bc23c6666ad1372e74527c2672814a Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 30 Oct 2025 18:07:21 +0100 Subject: [PATCH] fix(type-checker): remove as casts hiding type-errors thus bugs. Solve subsequent found bugs --- apps/client/src/components/entrypoints.ts | 2 +- .../src/components/main_tree_executors.ts | 4 +-- .../src/components/root_command_executor.ts | 2 +- apps/client/src/menus/tree_context_menu.ts | 4 +-- apps/client/src/services/note_create.ts | 34 +++++++++++-------- .../src/widgets/collections/board/api.ts | 4 +-- .../widgets/collections/table/context_menu.ts | 14 +++++--- .../widgets/collections/table/row_editing.ts | 15 +++++--- .../mobile_widgets/mobile_detail_menu.tsx | 12 ++++--- apps/client/src/widgets/note_tree.ts | 4 +-- .../ribbon/components/AttributeEditor.tsx | 4 +-- 11 files changed, 60 insertions(+), 39 deletions(-) diff --git a/apps/client/src/components/entrypoints.ts b/apps/client/src/components/entrypoints.ts index ec80a5ecf..7895602b3 100644 --- a/apps/client/src/components/entrypoints.ts +++ b/apps/client/src/components/entrypoints.ts @@ -26,7 +26,7 @@ export default class Entrypoints extends Component { async createNoteIntoInboxCommand() { await noteCreateService.createNote( - { target: "inbox" } as CreateNoteIntoInboxOpts + { target: "inbox" } ); } diff --git a/apps/client/src/components/main_tree_executors.ts b/apps/client/src/components/main_tree_executors.ts index d656437ec..284fd8a1f 100644 --- a/apps/client/src/components/main_tree_executors.ts +++ b/apps/client/src/components/main_tree_executors.ts @@ -55,7 +55,7 @@ export default class MainTreeExecutors extends Component { isProtected: activeNoteContext.note.isProtected, saveSelection: false, promptForType: false, - } as CreateNoteWithUrlOpts + } ); } @@ -84,7 +84,7 @@ export default class MainTreeExecutors extends Component { targetBranchId: node.data.branchId, isProtected: isProtected, saveSelection: false - } as CreateNoteWithUrlOpts + } ); } } diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.ts index 45909738c..eaac60f78 100644 --- a/apps/client/src/components/root_command_executor.ts +++ b/apps/client/src/components/root_command_executor.ts @@ -250,7 +250,7 @@ export default class RootCommandExecutor extends Component { messages: [], title: "New AI Chat" }), - } as CreateNoteWithUrlOpts + } ); if (!result.note) { diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts index 8cb4fcd10..79cf50b51 100644 --- a/apps/client/src/menus/tree_context_menu.ts +++ b/apps/client/src/menus/tree_context_menu.ts @@ -293,7 +293,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener parentComponent?.triggerCommand("addNewRow", { parentNotePath: parentNoteId, customOpts: { + parentNoteUrl: parentNoteId, target: "before", targetBranchId: rowData.branchId, - } as CreateNoteWithUrlOpts + } }) }, { @@ -195,12 +196,16 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro handler: async () => { const branchId = row.getData().branchId; const note = await froca.getBranch(branchId)?.getNote(); + if (!note) { + return; + } parentComponent?.triggerCommand("addNewRow", { - parentNotePath: note?.noteId, + parentNotePath: note.noteId, customOpts: { + parentNoteUrl: note.noteId, target: "after", targetBranchId: branchId, - } as CreateNoteWithUrlOpts + } }); } }, @@ -211,9 +216,10 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro handler: () => parentComponent?.triggerCommand("addNewRow", { parentNotePath: parentNoteId, customOpts: { + parentNoteUrl: parentNoteId, target: "after", targetBranchId: rowData.branchId, - } as CreateNoteWithUrlOpts + } }) }, { kind: "separator" }, diff --git a/apps/client/src/widgets/collections/table/row_editing.ts b/apps/client/src/widgets/collections/table/row_editing.ts index d23e151d8..c948e9e1e 100644 --- a/apps/client/src/widgets/collections/table/row_editing.ts +++ b/apps/client/src/widgets/collections/table/row_editing.ts @@ -19,11 +19,18 @@ export default function useRowTableEditing(api: RefObject, attributeD activate: false, ...customOpts } + + // Normalize "inbox" targets into standard path-based creation. + // When adding a new row, we always have a concrete parent path (`notePath`), + // so even if the originating command requested an "inbox" creation, + // it should instead behave as "into" under the current note. + const normalizedOpts: CreateNoteWithUrlOpts = + opts.target === "inbox" + ? { ...opts, target: "into", parentNoteUrl: notePath } + : { ...opts, parentNoteUrl: notePath }; + note_create.createNote( - { - parentNoteUrl: notePath, - ...opts - } as CreateNoteWithUrlOpts + normalizedOpts ).then(({ branch }) => { if (branch) { setTimeout(() => { diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx index 86bbdc33b..1c74506a9 100644 --- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx +++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx @@ -29,12 +29,14 @@ export default function MobileDetailMenu() { ], selectMenuItemHandler: async ({ command }) => { if (command === "insertChildNote") { - note_create.createNote( - { + const parentNoteUrl = appContext.tabManager.getActiveContextNotePath(); + + if (parentNoteUrl) { + note_create.createNote({ target: "into", - parentNoteUrl: appContext.tabManager.getActiveContextNotePath() ?? undefined - } as CreateNoteWithUrlOpts - ); + parentNoteUrl, + }); + } } else if (command === "delete") { const notePath = appContext.tabManager.getActiveContextNotePath(); if (!notePath) { diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts index c629a5d35..f7e9ccc2c 100644 --- a/apps/client/src/widgets/note_tree.ts +++ b/apps/client/src/widgets/note_tree.ts @@ -229,7 +229,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { target: "into", parentNoteUrl: parentNotePath, isProtected: node.data.isProtected - } as CreateNoteWithUrlOpts, + }, ); } else if (target.classList.contains("enter-workspace-button")) { const node = $.ui.fancytree.getNode(e as unknown as Event); @@ -1847,7 +1847,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { target: "into", parentNoteUrl: notePath, isProtected: node.data.isProtected - } as CreateNoteWithUrlOpts + } ) } }), diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx index e2f61aa45..91780387d 100644 --- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx +++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx @@ -266,7 +266,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI target: "inbox", title, activate: false - } as CreateNoteIntoInboxOpts + } ); return note?.getBestNotePathString() ?? ""; } @@ -280,7 +280,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI title, activate: false, promptForType: true, - } as CreateNoteWithUrlOpts, + }, ) return resp?.note?.getBestNotePathString() ?? ""; }