-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1138 Migrate canvas shape node type to discourse-node #894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdroidian
wants to merge
1
commit into
main
Choose a base branch
from
eng-1138-migrate-canvas-shape-node-type-to-discourse-node
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,8 +103,10 @@ import createPage from "roamjs-components/writes/createPage"; | |
| import openBlockInSidebar from "roamjs-components/writes/openBlockInSidebar"; | ||
| import triplesToBlocks from "~/utils/triplesToBlocks"; | ||
| import { | ||
| BaseDiscourseNodeUtil, | ||
| DiscourseNodeUtil, | ||
| DiscourseNodeShape, | ||
| getDiscourseNodeTypeId, | ||
| isDiscourseNodeShape as isDiscourseNodeShapeTypeGuard, | ||
| } from "~/components/canvas/DiscourseNodeUtil"; | ||
| import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid"; | ||
| import { AddReferencedNodeType } from "./DiscourseRelationTool"; | ||
|
|
@@ -146,8 +148,7 @@ export const createAllReferencedNodeUtils = ( | |
| static override type = action; | ||
|
|
||
| isDiscourseNodeShape(shape: TLShape): shape is DiscourseNodeShape { | ||
| const shapeUtil = this.editor.getShapeUtil(shape.type); | ||
| return shapeUtil instanceof BaseDiscourseNodeUtil; | ||
| return isDiscourseNodeShapeTypeGuard(shape); | ||
| } | ||
|
|
||
| handleCreateRelationsInRoam = async ({ | ||
|
|
@@ -177,7 +178,11 @@ export const createAllReferencedNodeUtils = ( | |
| const possibleTargets = allAddReferencedNodeByAction[arrow.type].map( | ||
| (action) => action.destinationType, | ||
| ); | ||
| if (!possibleTargets.includes(target.type)) { | ||
| if ( | ||
| !possibleTargets.includes( | ||
| getDiscourseNodeTypeId({ shape: target }) || "", | ||
| ) | ||
| ) { | ||
| return deleteAndWarn( | ||
| `Target node must be of type ${possibleTargets | ||
| .map((t) => discourseContext.nodes[t].text) | ||
|
|
@@ -587,7 +592,7 @@ const asDiscourseNodeShape = ( | |
| editor: Editor, | ||
| ): DiscourseNodeShape | null => { | ||
| const shapeUtil = editor.getShapeUtil(shape.type); | ||
| return shapeUtil instanceof BaseDiscourseNodeUtil | ||
| return shapeUtil instanceof DiscourseNodeUtil | ||
| ? (shape as DiscourseNodeShape) | ||
| : null; | ||
| }; | ||
|
|
@@ -628,7 +633,11 @@ export const createAllRelationShapeUtils = ( | |
| .filter((r) => r.source === relation.source) | ||
| .map((r) => r.destination); | ||
|
|
||
| if (!possibleTargets.includes(target.type)) { | ||
| if ( | ||
| !possibleTargets.includes( | ||
| getDiscourseNodeTypeId({ shape: target }) || "", | ||
| ) | ||
| ) { | ||
| const uniqueTargets = [...new Set(possibleTargets)]; | ||
| const uniqueTargetTexts = uniqueTargets.map( | ||
| (t) => discourseContext.nodes[t].text, | ||
|
|
@@ -637,8 +646,9 @@ export const createAllRelationShapeUtils = ( | |
| `Target node must be of type ${uniqueTargetTexts.join(", ")}`, | ||
| ); | ||
| } | ||
| if (arrow.type !== target.type) { | ||
| editor.updateShapes([{ id: arrow.id, type: target.type }]); | ||
| const targetNodeTypeId = getDiscourseNodeTypeId({ shape: target }); | ||
| if (targetNodeTypeId && arrow.type !== targetNodeTypeId) { | ||
| editor.updateShapes([{ id: arrow.id, type: targetNodeTypeId }]); | ||
| } | ||
|
Comment on lines
+649
to
652
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not retag relation arrows with a node type ID. At Line 651, 🐛 Proposed fix- const targetNodeTypeId = getDiscourseNodeTypeId({ shape: target });
- if (targetNodeTypeId && arrow.type !== targetNodeTypeId) {
- editor.updateShapes([{ id: arrow.id, type: targetNodeTypeId }]);
- }
+ const targetNodeTypeId = getDiscourseNodeTypeId({ shape: target });
+ if (targetNodeTypeId) {
+ const relationForTarget = discourseContext.relations[relation.label]
+ ?.find(
+ (r) =>
+ r.source === relation.source && r.destination === targetNodeTypeId,
+ );
+ if (relationForTarget && arrow.type !== relationForTarget.id) {
+ editor.updateShapes([{ id: arrow.id, type: relationForTarget.id }]);
+ }
+ }🤖 Prompt for AI Agents |
||
| if (getStoredRelationsEnabled()) { | ||
| const sourceAsDNS = asDiscourseNodeShape(source, editor); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Relation arrow type changed to unregistered node type ID, causing runtime errors
After a relation is successfully drawn between two discourse nodes,
handleCreateRelationsInRoamincreateAllRelationShapeUtilsupdates the arrow shape'stypetotargetNodeTypeId(e.g.,"page-node"). Sincearrow.typeis always a relation ID (a Roam block UID) andtargetNodeTypeIdis always a discourse node type like"page-node", the conditionarrow.type !== targetNodeTypeIdis always true, so this update always executes.In the old system this didn't crash because
createNodeShapeUtilsregistered a ShapeUtil for each node type (e.g.,"page-node"). This PR removes those per-node-type utils in favor of a singleDiscourseNodeUtilwithtype = "discourse-node". Now"page-node"has no registered ShapeUtil, soeditor.updateShapes([{ id: arrow.id, type: "page-node" }])will cause tldraw to fail when it tries to look up the util for the shape. This breaks every relation creation between discourse nodes on the canvas.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.