Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 57 additions & 21 deletions apps/roam/src/utils/conditionToDatalog.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -441,8 +442,8 @@ const translator: Record<string, Translator> = {
},
"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",
Expand All @@ -465,30 +466,19 @@ const translator: Record<string, Translator> = {
},
],
},
{
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",
Expand All @@ -511,16 +501,62 @@ const translator: Record<string, Translator> = {
},
],
},
{
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",
},
Expand Down