-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1164 Ability to add a canvas page to the clipboard to view the nodes on that canvas #627
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 normalizePageTitle from "roamjs-components/queries/normalizePageTitle"; | ||
|
|
||
| const getAllReferencesOnPage = async ( | ||
| pageTitle: string, | ||
| ): Promise<{ uid: string; text: string }[]> => { | ||
| pageTitle = normalizePageTitle(pageTitle); | ||
| let referencedPages: Array<[string, string]> = []; | ||
| if (pageTitle.startsWith("Canvas/")) { | ||
|
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. Canvas page format is defined in settings, so this could change. Let's make sure we grab the up to date format. |
||
| const oldCanvasContent = window.roamAlphaAPI.data.fast.q( | ||
|
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. nit: we should see if we can reuse some code with CanvasReferences |
||
| `[:find ?uid ?title | ||
| :where | ||
| [?c :node/title "${pageTitle}"] | ||
| [?c :block/props ?props] | ||
| [(get ?props :roamjs-query-builder) ?rqb] | ||
| [(get ?rqb :tldraw) [[?k ?v]]] | ||
| [(get ?v :props) ?shape-props] | ||
| [(get ?shape-props :uid) ?uid] | ||
| [?n :block/uid ?uid] | ||
| [?n :node/title ?title] | ||
| ]`, | ||
| ) as Array<[string, string]>; | ||
| const newCanvasContent = window.roamAlphaAPI.data.fast.q( | ||
| `[:find ?uid ?title | ||
| :where | ||
| [?c :node/title "${pageTitle}"] | ||
| [?c :block/props ?props] | ||
| [(get ?props :roamjs-query-builder) ?rqb] | ||
| [(get ?rqb :tldraw) ?tldraw] | ||
| [(get ?tldraw :store) [[?k ?v]]] | ||
| [(get ?v :props) ?shape-props] | ||
| [(get ?shape-props :uid) ?uid] | ||
| [?n :block/uid ?uid] | ||
| [?n :node/title ?title] | ||
| ]`, | ||
| ) as Array<[string, string]>; | ||
| referencedPages = [...oldCanvasContent, ...newCanvasContent]; | ||
| } else { | ||
| referencedPages = (await Promise.resolve( | ||
| window.roamAlphaAPI.data.backend.q( | ||
| `[:find ?uid ?text | ||
| :where | ||
| [?page :node/title "${pageTitle}"] | ||
| [?b :block/page ?page] | ||
| [?b :block/refs ?refPage] | ||
| [?refPage :block/uid ?uid] | ||
| [?refPage :node/title ?text]]`, | ||
| ), | ||
| )) as Array<[string, string]>; | ||
| } | ||
| return referencedPages.map(([uid, text]) => ({ uid, text })); | ||
| }; | ||
|
|
||
| export default getAllReferencesOnPage; | ||
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.
nit: uid;text; is Result[], which is commonly used in the repo