-
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
The head ref may contain hidden characters: "eng-1867-Import-cross-app\u2013relations-in-roam-as-tentative"
Changes from all commits
204d0e1
1d5da16
b09d310
477adf2
6413bc1
7b1fa33
d0dcb0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: [], | ||
|
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.
When Useful? React with 👍 / 👎. |
||
| }); | ||
| return blockUid; | ||
| }; | ||
| 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 | ||
|
|
||
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