Skip to content

Commit

Permalink
fix: broken simple queries
Browse files Browse the repository at this point in the history
close #8900
  • Loading branch information
tiensonqin committed Mar 27, 2023
1 parent 0ae6fd4 commit 3b959f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
26 changes: 19 additions & 7 deletions src/main/frontend/components/query/builder.cljs
Expand Up @@ -270,8 +270,12 @@
(page-ref/->page-ref (second clause))

(= (keyword f) :page-tags)
(if (string? (second clause))
(cond
(string? (second clause))
(str "#" (second clause))
(symbol? (second clause))
(str "#" (str (second clause)))
:else
(str "#" (second (second clause))))

(contains? #{:property :page-property} (keyword f))
Expand All @@ -287,7 +291,15 @@
(last clause)))

(= (keyword f) :between)
(str "between: " (second (second clause)) " - " (second (last clause)))
(let [start (if (or (keyword? (second clause))
(symbol? (second clause)))
(name (second clause))
(second (second clause)))
end (if (or (keyword? (last clause))
(symbol? (last clause)))
(name (last clause))
(second (last clause)))]
(str "between: " start " ~ " end))

(contains? #{:task :priority} (keyword f))
(str (name f) ": "
Expand All @@ -312,7 +324,7 @@
[:a.flex.text-sm.query-clause {:on-click toggle-fn}
clause]

[:div.flex.flex-row.items-center.gap-2.p-1.rounded.border
[:div.flex.flex-row.items-center.gap-2.p-1.rounded.border.query-clause-btn
[:a.flex.query-clause {:on-click toggle-fn}
(dsl-human-output clause)]]))
(fn [{:keys [toggle-fn]}]
Expand Down Expand Up @@ -368,17 +380,17 @@
(let [kind (keyword (first clause))]
(if (query-builder/operators-set kind)
[:div.operator-clause.flex.flex-row.items-center {:data-level (count loc)}
[:div.text-4xl.mr-1.font-thin "("]
[:div.clause-bracket "("]
(clauses-group *tree *find (conj loc 0) kind (rest clause))
[:div.text-4xl.ml-1.font-thin ")"]]
[:div.clause-bracket ")"]]
(clause-inner *tree loc clause)))]))

(rum/defc clauses-group
[*tree *find loc kind clauses]
(let [parens? (and (= loc [0])
(> (count clauses) 1))]
[:div.clauses-group
(when parens? [:div.text-4xl.mr-1.font-thin "("])
(when parens? [:div.clause-bracket "("])
(when-not (and (= loc [0])
(= kind :and)
(<= (count clauses) 1))
Expand All @@ -390,7 +402,7 @@
(clause *tree *find (update loc (dec (count loc)) #(+ % i 1)) item))
clauses)

(when parens? [:div.text-4xl.ml-1.font-thin ")"])
(when parens? [:div.clause-bracket ")"])

(when (not= loc [0])
(add-filter *find *tree loc []))]))
Expand Down
11 changes: 10 additions & 1 deletion src/main/frontend/components/query/builder.css
Expand Up @@ -29,7 +29,7 @@
}

.clauses-group {
@apply flex flex-row gap-1 flex-wrap items-center text-sm;
@apply flex flex-row gap-2 flex-wrap items-center text-sm;
}

a.query-clause, a.add-filter {
Expand All @@ -43,4 +43,13 @@
.filter-item select {
border: none;
}

.clause-bracket {
@apply text-4xl ml-1 font-thin opacity-30;
font-family: "Inter";
}

.query-clause-btn {
border-color: var(--ls-border-color);
}
}
13 changes: 11 additions & 2 deletions src/main/frontend/template.cljs
Expand Up @@ -3,6 +3,8 @@
(:require [clojure.string :as string]
[frontend.date :as date]
[frontend.state :as state]
[frontend.db.utils :as db-utils]
[frontend.util :as util]
[logseq.graph-parser.util.page-ref :as page-ref]))

(defn- variable-rules
Expand All @@ -11,8 +13,15 @@
"yesterday" (page-ref/->page-ref (date/yesterday))
"tomorrow" (page-ref/->page-ref (date/tomorrow))
"time" (date/get-current-time)
"current page" (page-ref/->page-ref (or (state/get-current-page)
(date/today)))})
"current page" (when-let [current-page (or
(state/get-current-page)
(date/today))]
(let [block-uuid (parse-uuid current-page)
page (if block-uuid
(:block/page (db-utils/entity [:block/uuid block-uuid]))
(db-utils/entity [:block/name (util/page-name-sanity-lc current-page)]))
current-page' (:block/original-name page)]
(page-ref/->page-ref current-page')))})

;; TODO: programmable
;; context information, date, current page
Expand Down

0 comments on commit 3b959f3

Please sign in to comment.