Skip to content

Commit 67c327f

Browse files
authored
add {current user} to "with text" condition (#476)
1 parent 9ab8b30 commit 67c327f

1 file changed

Lines changed: 57 additions & 21 deletions

File tree

apps/roam/src/utils/conditionToDatalog.ts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
12
import { DAILY_NOTE_PAGE_TITLE_REGEX } from "roamjs-components/date/constants";
23
import parseNlpDate from "roamjs-components/date/parseNlpDate";
34
import getAllPageNames from "roamjs-components/queries/getAllPageNames";
@@ -441,8 +442,8 @@ const translator: Record<string, Translator> = {
441442
},
442443
"with text": {
443444
callback: ({ source, target }) => {
444-
if (isRegex(target)) {
445-
const rePattern = regexRePatternValue(target);
445+
const currentUserMatch = /^\s*{current user}\s*$/i.test(target);
446+
if (currentUserMatch) {
446447
return [
447448
{
448449
type: "or-clause",
@@ -465,30 +466,19 @@ const translator: Record<string, Translator> = {
465466
},
466467
],
467468
},
468-
{
469-
type: "fn-expr",
470-
fn: "re-pattern",
471-
arguments: [
472-
{
473-
type: "constant",
474-
value: rePattern,
475-
},
476-
],
477-
binding: {
478-
type: "bind-scalar",
479-
variable: { type: "variable", value: `${target}-regex` },
480-
},
481-
},
482469
{
483470
type: "pred-expr",
484-
pred: "re-find",
471+
pred: "clojure.string/includes?",
485472
arguments: [
486-
{ type: "variable", value: `${target}-regex` },
487473
{ type: "variable", value: `${source}-String` },
474+
{ type: "constant", value: `"${getCurrentUserDisplayName()}"` },
488475
],
489476
},
490477
];
491-
} else {
478+
}
479+
480+
if (isRegex(target)) {
481+
const rePattern = regexRePatternValue(target);
492482
return [
493483
{
494484
type: "or-clause",
@@ -511,16 +501,62 @@ const translator: Record<string, Translator> = {
511501
},
512502
],
513503
},
504+
{
505+
type: "fn-expr",
506+
fn: "re-pattern",
507+
arguments: [
508+
{
509+
type: "constant",
510+
value: rePattern,
511+
},
512+
],
513+
binding: {
514+
type: "bind-scalar",
515+
variable: { type: "variable", value: `${target}-regex` },
516+
},
517+
},
514518
{
515519
type: "pred-expr",
516-
pred: "clojure.string/includes?",
520+
pred: "re-find",
517521
arguments: [
522+
{ type: "variable", value: `${target}-regex` },
518523
{ type: "variable", value: `${source}-String` },
519-
{ type: "constant", value: `"${normalizePageTitle(target)}"` },
520524
],
521525
},
522526
];
523527
}
528+
529+
return [
530+
{
531+
type: "or-clause",
532+
clauses: [
533+
{
534+
type: "data-pattern",
535+
arguments: [
536+
{ type: "variable", value: source },
537+
{ type: "constant", value: ":block/string" },
538+
{ type: "variable", value: `${source}-String` },
539+
],
540+
},
541+
{
542+
type: "data-pattern",
543+
arguments: [
544+
{ type: "variable", value: source },
545+
{ type: "constant", value: ":node/title" },
546+
{ type: "variable", value: `${source}-String` },
547+
],
548+
},
549+
],
550+
},
551+
{
552+
type: "pred-expr",
553+
pred: "clojure.string/includes?",
554+
arguments: [
555+
{ type: "variable", value: `${source}-String` },
556+
{ type: "constant", value: `"${normalizePageTitle(target)}"` },
557+
],
558+
},
559+
];
524560
},
525561
placeholder: "Enter any text",
526562
},

0 commit comments

Comments
 (0)