diff --git a/apps/roam/src/utils/conditionToDatalog.ts b/apps/roam/src/utils/conditionToDatalog.ts index 0382ff685..3567f8c00 100644 --- a/apps/roam/src/utils/conditionToDatalog.ts +++ b/apps/roam/src/utils/conditionToDatalog.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import { DAILY_NOTE_PAGE_TITLE_REGEX } from "roamjs-components/date/constants"; import parseNlpDate from "roamjs-components/date/parseNlpDate"; import getAllPageNames from "roamjs-components/queries/getAllPageNames"; @@ -441,8 +442,8 @@ const translator: Record = { }, "with text": { callback: ({ source, target }) => { - if (isRegex(target)) { - const rePattern = regexRePatternValue(target); + const currentUserMatch = /^\s*{current user}\s*$/i.test(target); + if (currentUserMatch) { return [ { type: "or-clause", @@ -465,30 +466,19 @@ const translator: Record = { }, ], }, - { - type: "fn-expr", - fn: "re-pattern", - arguments: [ - { - type: "constant", - value: rePattern, - }, - ], - binding: { - type: "bind-scalar", - variable: { type: "variable", value: `${target}-regex` }, - }, - }, { type: "pred-expr", - pred: "re-find", + pred: "clojure.string/includes?", arguments: [ - { type: "variable", value: `${target}-regex` }, { type: "variable", value: `${source}-String` }, + { type: "constant", value: `"${getCurrentUserDisplayName()}"` }, ], }, ]; - } else { + } + + if (isRegex(target)) { + const rePattern = regexRePatternValue(target); return [ { type: "or-clause", @@ -511,16 +501,62 @@ const translator: Record = { }, ], }, + { + type: "fn-expr", + fn: "re-pattern", + arguments: [ + { + type: "constant", + value: rePattern, + }, + ], + binding: { + type: "bind-scalar", + variable: { type: "variable", value: `${target}-regex` }, + }, + }, { type: "pred-expr", - pred: "clojure.string/includes?", + pred: "re-find", arguments: [ + { type: "variable", value: `${target}-regex` }, { type: "variable", value: `${source}-String` }, - { type: "constant", value: `"${normalizePageTitle(target)}"` }, ], }, ]; } + + return [ + { + type: "or-clause", + clauses: [ + { + type: "data-pattern", + arguments: [ + { type: "variable", value: source }, + { type: "constant", value: ":block/string" }, + { type: "variable", value: `${source}-String` }, + ], + }, + { + type: "data-pattern", + arguments: [ + { type: "variable", value: source }, + { type: "constant", value: ":node/title" }, + { type: "variable", value: `${source}-String` }, + ], + }, + ], + }, + { + type: "pred-expr", + pred: "clojure.string/includes?", + arguments: [ + { type: "variable", value: `${source}-String` }, + { type: "constant", value: `"${normalizePageTitle(target)}"` }, + ], + }, + ]; }, placeholder: "Enter any text", },