Skip to content

Commit

Permalink
Allow Query editor clickable when no conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
dvargas92495 committed Mar 22, 2022
1 parent cac0506 commit 9b8397d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ const QueryEditor = ({
style={{ maxHeight: 32 }}
intent={"primary"}
disabled={
!conditions.length ||
!conditions.every((c) => !!c.relation && !!c.target) ||
!returnNode ||
selections.some((s) => !s.text)
Expand Down
16 changes: 13 additions & 3 deletions src/utils/fireQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { DAILY_NOTE_PAGE_TITLE_REGEX } from "roamjs-components/date/constants";

type PredefinedSelection = {
test: RegExp;
pull: (a: { returnNode: string; match: RegExpExecArray }) => string;
pull: (a: {
returnNode: string;
match: RegExpExecArray;
where: string;
}) => string;
mapper: (
r: PullBlock,
key: string
Expand Down Expand Up @@ -43,8 +47,12 @@ const predefinedSelections: PredefinedSelection[] = [
},
{
test: /^node:(\s*.*\s*)$/i,
pull: ({ match, returnNode }) =>
`(pull ?${(match[1] || returnNode)?.trim()} [:node/title :block/uid])`,
pull: ({ match, returnNode, where }) => {
const node = (match[1] || returnNode)?.trim();
return where.includes(`?${node}`)
? `(pull ?${node} [:node/title :block/uid])`
: "";
},
mapper: (r) => {
return {
"": r?.[":node/title"] || "",
Expand Down Expand Up @@ -132,12 +140,14 @@ const fireQuery = ({
.map((p) => ({
mapper: p.defined.mapper,
pull: p.defined.pull({
where,
returnNode,
match: p.defined.test.exec(p.s.text),
}),
label: p.s.label || p.s.text,
key: p.s.text,
}))
.filter((p) => !!p.pull)
);
const find = definedSelections.map((p) => p.pull).join("\n");
const query = `[:find\n${find}\n:in $ ?date-regex\n:where\n${where}\n]`;
Expand Down

0 comments on commit 9b8397d

Please sign in to comment.