-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-1867 Import cross-app relations into Roam as tentative relations #1302
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
maparent
wants to merge
7
commits into
main
from
eng-1867-Import-cross-app–relations-in-roam-as-tentative
The head ref may contain hidden characters: "eng-1867-Import-cross-app\u2013relations-in-roam-as-tentative"
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
204d0e1
ENG-1867 function to import relations and schemas after discover
maparent 1d5da16
actually import the relations
maparent b09d310
tentative flag
maparent 477adf2
Correction to getDiscourseRelations: allow triple-less relations
maparent 6413bc1
allow rel to local target
maparent 7b1fa33
add new relation to global settings
maparent d0dcb0f
Repair tests
maparent 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
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import discourseConfigRef from "~/utils/discourseConfigRef"; | ||
| import createBlock from "roamjs-components/writes/createBlock"; | ||
| import { setGlobalSetting } from "~/components/settings/utils/accessors"; | ||
| import { GLOBAL_KEYS } from "~/components/settings/utils/settingKeys"; | ||
|
|
||
| export const createRelationSchema = async ({ | ||
| label, | ||
| complement, | ||
| source, | ||
| destination, | ||
| }: { | ||
| label: string; | ||
| complement: string; | ||
| source: string; | ||
| destination: string; | ||
| }) => { | ||
| const grammarNode = discourseConfigRef.tree.find( | ||
| (node) => node.text === "grammar", | ||
| ); | ||
| const relationsNode = grammarNode?.children.find( | ||
| (node) => node.text === "relations", | ||
| ); | ||
| if (!relationsNode) throw new Error("Cannot find the relation grammar"); | ||
| const blockUid = await createBlock({ | ||
| parentUid: relationsNode.uid, | ||
|
maparent marked this conversation as resolved.
|
||
| order: "last", | ||
| node: { | ||
| text: label, | ||
| children: [ | ||
| { | ||
| text: "source", | ||
| children: [{ text: source }], | ||
| }, | ||
| { | ||
| text: "destination", | ||
| children: [{ text: destination }], | ||
| }, | ||
| { | ||
| text: "complement", | ||
| children: [{ text: complement }], | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| setGlobalSetting([GLOBAL_KEYS.relations, blockUid], { | ||
| label, | ||
| source, | ||
| destination, | ||
| complement, | ||
| ifConditions: [], | ||
| }); | ||
| return blockUid; | ||
| }; | ||
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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { | |
| type SettingsSnapshot, | ||
| } from "~/components/settings/utils/accessors"; | ||
| import discourseConfigRef from "./discourseConfigRef"; | ||
| import { getStoredRelationsEnabled } from "~/utils/storedRelations"; | ||
|
|
||
| export type Triple = readonly [string, string, string]; | ||
| export type DiscourseRelation = { | ||
|
|
@@ -47,6 +48,7 @@ const getDiscourseRelations = (snapshot?: SettingsSnapshot) => { | |
| const grammarNode = getGrammarNode(); | ||
| const relationsNode = getRelationsNode(grammarNode); | ||
| const relationNodes = relationsNode?.children || DEFAULT_RELATION_VALUES; | ||
| const storedRelationsEnabled = getStoredRelationsEnabled(); | ||
| const discourseRelations = relationNodes.flatMap( | ||
| (r: InputTextNode, i: number) => { | ||
| const tree = (r?.children || []) as TextNode[]; | ||
|
|
@@ -58,6 +60,9 @@ const getDiscourseRelations = (snapshot?: SettingsSnapshot) => { | |
| complement: getSettingValueFromTree({ tree, key: "Complement" }), | ||
| }; | ||
| const ifNode = tree.find(matchNodeText("if"))?.children || []; | ||
| if (ifNode.length === 0 && storedRelationsEnabled) { | ||
|
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. No triples on a new-style relation created from scratch |
||
| return [{ ...data, triples: [] }]; | ||
| } | ||
| return ifNode.map((node) => ({ | ||
| ...data, | ||
| triples: node.children | ||
|
|
||
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.
adding the tentative flag