ENG-1549: Add convert existing page to discourse node command#987
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
Address review comments on PR #987: - DRY the SmartBlocks template-handling logic by extracting insertTemplateBlocks into createDiscourseNode.ts and reusing it from convertPageToNodeFromCommand. - Tighten createOverride return type from Promise<string | void> to Promise<string> so the dialog can collapse the override fallback into a single const.
Image insertion belongs with template insertion (matches the original pre-refactor coupling). Extract handleImageCreation to a module-level insertCanvasKeyImage and call it from the helper after template work. createDiscourseNode no longer needs a separate image step; convert flow's image branch is a no-op via undefined imageUrl.
Pure extraction — the function body is identical to the original closure. The signature now takes pageUid, discourseNodes, configPageUid, imageUrl, extensionAPI, and text as params instead of picking them up via closure. createDiscourseNode passes its already-computed discourseNodes through (no duplicate fetch).
| return false; | ||
| }; | ||
|
|
||
| const handleImageCreation = async ({ |
There was a problem hiding this comment.
Pulled out function from line 53, nothing changed in the implementation of this.
Step back from the insertTemplateBlocks orchestrator. The PR is just two function extractions: - hasSmartBlockSyntax and createBlocksFromTemplate are exported from createDiscourseNode.ts at module scope. - handleImageCreation stays at module scope (used only by createDiscourseNode). createDiscourseNode keeps its original if/else SmartBlocks orchestration; convertPageToNodeFromCommand keeps its inline orchestration too. Both sites now call the shared helpers.
| const results = await runQuery({ | ||
| extensionAPI, | ||
| parentUid, | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention |
There was a problem hiding this comment.
extra line to fix lint
| }) => { | ||
| const createBlocksFromTemplate = async () => { | ||
| await Promise.all( | ||
| stripUid(templateNode.children).map((node, templateOrder) => |
There was a problem hiding this comment.
- Removed the
uidfrom the place we pulled this from (line153).
Because: stripUid(...) already removes uid, so the destructuring was redundant and caused an unused uid lint warning
- Updated from
ordertotemplateOrder, defaults to 0. We need to add template to last block if we convert a page using the command palette command
| }); | ||
| await createBlocksFromTemplate(); | ||
| } else if (useSmartBlocks && window.roamjs?.extension?.smartblocks) { | ||
| void window.roamjs.extension.smartblocks?.triggerSmartblock({ |
There was a problem hiding this comment.
void That is only to mark the promise as intentionally not awaited. Runtime intent is the same
…ting-page-to-node-roam # Conflicts: # apps/roam/src/utils/createDiscourseNode.ts
…ting-page-to-node-roam # Conflicts: # apps/roam/src/utils/createDiscourseNode.ts
https://www.loom.com/share/ace42b9d8d66415b9143d4d4a164cfc1