-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-2131 Review and accept imported relation types and triples in Roam #1383
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
sid597
wants to merge
7
commits into
main
Choose a base branch
from
eng-2131-review-and-accept-imported-relation-types-and-triples-in
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d545c52
ENG-2131 Review and accept imported relation types and triples in Roam
sid597 9c05b19
ENG-2131 Address pre-PR review findings
sid597 0b82df3
Fix imported relation matching and refresh the grammar cache
sid597 dfc584f
Read current relation choices when opening the creation dialog
sid597 b58f957
ENG-2131 Align imported relation actions with row content
sid597 1a5f2ce
ENG-2131 Keep delete confirmation within the actions column
sid597 a574c20
ENG-2131 Refresh mounted relation creation after schema changes
sid597 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| import { | ||
| isRelationSchemaDeleted, | ||
| useRelationSchemaRevision, | ||
| } from "~/utils/relationSchemaChanges"; | ||
| import React, { | ||
| useState, | ||
| useRef, | ||
|
|
@@ -120,6 +124,7 @@ import posthog from "posthog-js"; | |
| import { getPersonalSetting } from "~/components/settings/utils/accessors"; | ||
| import { PERSONAL_KEYS } from "~/components/settings/utils/settingKeys"; | ||
| import { json, normalizeProps } from "~/utils/getBlockProps"; | ||
| import { isProvisionalRelationSchema } from "~/utils/relationSchemaAcceptance"; | ||
| import { onPageRefObserverChange } from "~/utils/pageRefObserverHandlers"; | ||
|
|
||
| declare global { | ||
|
|
@@ -133,17 +138,25 @@ export type DiscourseContextType = { | |
| nodes: Record<string, DiscourseNode & { index: number }>; | ||
| // { [Relation.Label] => DiscourseRelation[] } | ||
| relations: Record<string, DiscourseRelation[]>; | ||
| // Imported, not-yet-accepted relation schemas; excluded from relation | ||
| // creation but kept in `relations` so existing shapes still render. | ||
| provisionalRelationIds: Set<string>; | ||
| lastAppEvent: string; | ||
| lastActions: HistoryEntry<TLRecord>[]; | ||
| }; | ||
|
|
||
| export const discourseContext: DiscourseContextType = { | ||
| nodes: {}, | ||
| relations: {}, | ||
| provisionalRelationIds: new Set(), | ||
| lastAppEvent: "", | ||
| lastActions: [], | ||
| }; | ||
|
|
||
| export const isAcceptedRelationSchema = (relation: { id: string }): boolean => | ||
| !discourseContext.provisionalRelationIds.has(relation.id) && | ||
| !isRelationSchemaDeleted(relation.id); | ||
|
|
||
| let activeCanvasPageUid: string | null = null; | ||
| let activeCanvasEditor: Editor | null = null; | ||
|
|
||
|
|
@@ -766,6 +779,7 @@ const TldrawCanvasShared = ({ | |
| }, | ||
| {} as Record<string, DiscourseRelation[]>, | ||
| ); | ||
|
|
||
| return relations; | ||
| }, []); | ||
| const allRelationsById = useMemo(() => { | ||
|
|
@@ -777,9 +791,34 @@ const TldrawCanvasShared = ({ | |
| const allRelationIds = useMemo(() => { | ||
| return Object.keys(allRelationsById); | ||
| }, [allRelationsById]); | ||
| const relationSchemaRevision = useRelationSchemaRevision(); | ||
| const registeredRelationNames = useMemo( | ||
| () => [...new Set(allRelations.map((relation) => relation.label))], | ||
| [allRelations], | ||
| ); | ||
| const allRelationNames = useMemo(() => { | ||
|
Collaborator
Author
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. A label drops out of the canvas toolbar only when every relation carrying it is provisional. A label with one local and one imported relation keeps its tool, and the endpoint-matching step picks from the accepted list only. |
||
| return Object.keys(discourseContext.relations); | ||
| }, []); | ||
| discourseContext.provisionalRelationIds = new Set( | ||
| allRelations | ||
| .filter((r) => isProvisionalRelationSchema(r.id)) | ||
| .map((r) => r.id), | ||
| ); | ||
| return Object.entries(discourseContext.relations) | ||
| .filter(([, relations]) => relations.some(isAcceptedRelationSchema)) | ||
| .map(([name]) => name); | ||
| // Acceptance and deletion invalidate the relation data stored outside React. | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [allRelations, relationSchemaRevision]); | ||
| useEffect(() => { | ||
| const editor = appRef.current; | ||
| if (!editor) return; | ||
| const tool = editor.getCurrentToolId(); | ||
| if ( | ||
| registeredRelationNames.includes(tool) && | ||
| !allRelationNames.includes(tool) | ||
| ) { | ||
| editor.setCurrentTool("select"); | ||
| } | ||
| }, [allRelationNames, registeredRelationNames]); | ||
| const allNodes = useMemo(() => { | ||
| const allNodes = getDiscourseNodes(); | ||
| discourseContext.nodes = Object.fromEntries( | ||
|
|
@@ -1025,7 +1064,9 @@ const TldrawCanvasShared = ({ | |
| static override isLockable = true; | ||
| }; | ||
| const discourseNodeTools = createNodeShapeTools(allNodes); | ||
| const discourseRelationTools = createAllRelationShapeTools(allRelationNames); | ||
| const discourseRelationTools = createAllRelationShapeTools( | ||
| registeredRelationNames, | ||
| ); | ||
| const referencedNodeTools = createAllReferencedNodeTools( | ||
| allAddReferencedNodeByAction, | ||
| ); | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.