From 188bc84294c1c36d36acef202436712cbc5a6058 Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Wed, 19 Feb 2025 12:53:27 -0600 Subject: [PATCH 1/3] add {this page} --- src/utils/conditionToDatalog.ts | 40 ++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/utils/conditionToDatalog.ts b/src/utils/conditionToDatalog.ts index 28156288..5dd05413 100644 --- a/src/utils/conditionToDatalog.ts +++ b/src/utils/conditionToDatalog.ts @@ -17,6 +17,7 @@ import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageU import getPageTitlesStartingWithPrefix from "roamjs-components/queries/getPageTitlesStartingWithPrefix"; import extractRef from "roamjs-components/util/extractRef"; import getCurrentUserDisplayName from "roamjs-components/queries/getCurrentUserDisplayName"; +import getPageTitleByBlockUid from "roamjs-components/queries/getPageTitleByBlockUid"; type ConditionToDatalog = (condition: Condition) => DatalogClause[]; @@ -32,9 +33,11 @@ const regexRePatternValue = (str: string) => { const getTitleDatalog = ({ source, target, + uid, }: { source: string; target: string; + uid?: string; }): DatalogClause[] => { const dateMatch = /^\s*{date(?::([^}]+))?}\s*$/i.exec(target); if (dateMatch) { @@ -93,7 +96,7 @@ const getTitleDatalog = ({ if (currentMatch) { // Can't use this, since it's async // window.roamAlphaAPI.ui.mainWindow.getOpenPageOrBlockUid(); - const uid = getCurrentPageUid(); + const mainWindowUid = getCurrentPageUid(); return [ { type: "data-pattern", @@ -102,7 +105,24 @@ const getTitleDatalog = ({ { type: "constant", value: ":node/title" }, { type: "constant", - value: `"${getPageTitleByPageUid(uid)}"`, + value: `"${getPageTitleByPageUid(mainWindowUid)}"`, + }, + ], + }, + ]; + } + const thisPageMatch = /^\s*{this page}\s*$/i.test(target); + if (thisPageMatch && uid) { + console.log(uid); + return [ + { + type: "data-pattern", + arguments: [ + { type: "variable", value: source }, + { type: "constant", value: ":node/title" }, + { + type: "constant", + value: `"${getPageTitleByBlockUid(uid)}"`, }, ], }, @@ -233,7 +253,7 @@ const translator: Record = { isVariable: true, }, "is referenced by block in page with title": { - callback: ({ source, target }) => [ + callback: ({ source, target, uid }) => [ { type: "data-pattern", arguments: [ @@ -250,7 +270,7 @@ const translator: Record = { { type: "variable", value: target }, ], }, - ...getTitleDatalog({ source: target, target }), + ...getTitleDatalog({ source: target, target, uid }), ], placeholder: "Enter any placeholder for the node", targetOptions: () => @@ -259,6 +279,7 @@ const translator: Record = { "{date:today}", "{current}", "{current user}", + "{this page}", ]), }, "is in page": { @@ -283,6 +304,7 @@ const translator: Record = { "{date:today}", "{current}", "{current user}", + "{this page}", ]), placeholder: "Enter a page name or {date} for any DNP", }, @@ -585,7 +607,7 @@ const translator: Record = { placeholder: "Enter the display name of any user with access to this graph", }, "references title": { - callback: ({ source, target }) => [ + callback: ({ source, target, uid }) => [ { type: "data-pattern", arguments: [ @@ -594,7 +616,7 @@ const translator: Record = { { type: "variable", value: `${target}-Ref` }, ], }, - ...getTitleDatalog({ source: `${target}-Ref`, target }), + ...getTitleDatalog({ source: `${target}-Ref`, target, uid }), ], targetOptions: () => getAllPageNames().concat([ @@ -602,6 +624,7 @@ const translator: Record = { "{date:today}", "{current}", "{current user}", + "{this page}", ]), placeholder: "Enter a page name or {date} for any DNP", }, @@ -620,7 +643,7 @@ const translator: Record = { placeholder: "Enter a heading value (0, 1, 2, 3)", }, "is in page with title": { - callback: ({ source, target }) => [ + callback: ({ source, target, uid }) => [ { type: "data-pattern", arguments: [ @@ -629,7 +652,7 @@ const translator: Record = { { type: "variable", value: target }, ], }, - ...getTitleDatalog({ source: target, target }), + ...getTitleDatalog({ source: target, target, uid }), ], targetOptions: () => getAllPageNames().concat([ @@ -637,6 +660,7 @@ const translator: Record = { "{date:today}", "{current}", "{current user}", + "{this page}", ]), placeholder: "Enter a page name or {date} for any DNP", }, From d3a30c643d076a08f48d0f78a1704da144d948be Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Wed, 19 Feb 2025 12:53:32 -0600 Subject: [PATCH 2/3] add docs --- docs/query-builder.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/query-builder.md b/docs/query-builder.md index a017b618..50275699 100644 --- a/docs/query-builder.md +++ b/docs/query-builder.md @@ -79,6 +79,16 @@ You can use a combination of multiple **conditions** to select the data you want | `with text` | The `source` block or page has the exact text `target` somewhere in its block text or page title. | [Link](examples.md#with-text) | | `with text in title` | The `source` page has the exact text `target` somewhere in its page title. | [Link](examples.md#with-title-in-text) | +### Target Options + +Some relationships have a `target` field that supports the following options: + +- `{date}` - matches any Daily Note Page +- `{date:today}` - matches the current date +- `{current}` - matches the page currently open in the main window +- `{this page}` - matches the page in which the query is run +- `{current user}` - matches the current user + ## Selections **Selections** specify what data from the blocks that match your conditions get returned. They determine the **columns** of the table. By default, the block text or page title is always returned and hyperlinked. Every selection is made up of two parts: the `label` and the `data`: From a70ec02e48b069248fca4accdc671ab25b257c88 Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Wed, 19 Feb 2025 12:56:07 -0600 Subject: [PATCH 3/3] . --- src/utils/conditionToDatalog.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/conditionToDatalog.ts b/src/utils/conditionToDatalog.ts index 5dd05413..f76bdfdf 100644 --- a/src/utils/conditionToDatalog.ts +++ b/src/utils/conditionToDatalog.ts @@ -113,7 +113,6 @@ const getTitleDatalog = ({ } const thisPageMatch = /^\s*{this page}\s*$/i.test(target); if (thisPageMatch && uid) { - console.log(uid); return [ { type: "data-pattern",