Skip to content

Commit d7620ff

Browse files
authored
add input support for created by (#170)
1 parent 4083632 commit d7620ff

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

src/utils/conditionToDatalog.ts

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -396,32 +396,55 @@ const translator: Record<string, Translator> = {
396396
placeholder: "Enter any text",
397397
},
398398
"created by": {
399-
callback: ({ source, target }) => [
400-
{
401-
type: "data-pattern",
402-
arguments: [
403-
{ type: "variable", value: source },
404-
{ type: "constant", value: ":create/user" },
405-
{ type: "variable", value: `${source}-User` },
406-
],
407-
},
408-
{
409-
type: "data-pattern",
410-
arguments: [
411-
{ type: "variable", value: `${source}-User` },
412-
{ type: "constant", value: ":user/display-page" },
413-
{ type: "variable", value: `${source}-User-Display` },
414-
],
415-
},
416-
{
417-
type: "data-pattern",
418-
arguments: [
419-
{ type: "variable", value: `${source}-User-Display` },
420-
{ type: "constant", value: ":node/title" },
421-
{ type: "constant", value: `"${normalizePageTitle(target)}"` },
422-
],
423-
},
424-
],
399+
callback: ({ source, target }) => {
400+
const initialDatalog: DatalogClause[] = [
401+
{
402+
type: "data-pattern",
403+
arguments: [
404+
{ type: "variable", value: source },
405+
{ type: "constant", value: ":create/user" },
406+
{ type: "variable", value: `${source}-User` },
407+
],
408+
},
409+
{
410+
type: "data-pattern",
411+
arguments: [
412+
{ type: "variable", value: `${source}-User` },
413+
{ type: "constant", value: ":user/display-page" },
414+
{ type: "variable", value: `${source}-User-Display` },
415+
],
416+
},
417+
];
418+
return INPUT_REGEX.test(target)
419+
? [
420+
...initialDatalog,
421+
{
422+
type: "data-pattern",
423+
arguments: [
424+
{ type: "variable", value: `${source}-User-Display` },
425+
{ type: "constant", value: ":node/title" },
426+
{
427+
type: "variable",
428+
value: target.replace(INPUT_REGEX, ""),
429+
},
430+
],
431+
},
432+
]
433+
: [
434+
...initialDatalog,
435+
{
436+
type: "data-pattern",
437+
arguments: [
438+
{ type: "variable", value: `${source}-User-Display` },
439+
{ type: "constant", value: ":node/title" },
440+
{
441+
type: "constant",
442+
value: `"${normalizePageTitle(target)}"`,
443+
},
444+
],
445+
},
446+
];
447+
},
425448
targetOptions: () =>
426449
(
427450
window.roamAlphaAPI.data.fast.q(
@@ -756,7 +779,7 @@ const translator: Record<string, Translator> = {
756779
{ type: "variable", value: `${target}-TLDraw-Value` },
757780
],
758781
},
759-
},
782+
},
760783
{
761784
type: "fn-expr",
762785
fn: "get",

src/utils/fireQuery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ const fireQuery: FireQuery = async (_args) => {
325325
try {
326326
if (getNodeEnv() === "development") {
327327
console.log("Query to Roam:");
328-
console.log(query, ...inputs);
328+
console.log(query);
329+
if (inputs) console.log("Inputs:", ...inputs);
329330
}
330331
return Promise.all(
331332
window.roamAlphaAPI.data.fast.q(query, ...inputs).map(formatResult)

0 commit comments

Comments
 (0)