Преглед изворни кода

enhance: properties, tags and other core tags can be queried

from simple queries and used as property value selection criteria
Gabriel Horner пре 10 месеци
родитељ
комит
cafa70f409

+ 1 - 1
src/main/frontend/components/property/config.cljs

@@ -96,7 +96,7 @@
                (let [toggle-fn #(do
                                   (when (fn? on-hide) (on-hide))
                                   (shui/popup-hide! id))
-                     classes (model/get-all-classes (state/get-current-repo) {:except-root-class? true})
+                     classes (model/get-all-readable-classes (state/get-current-repo) {:except-root-class? true})
                      options (map (fn [class]
                                     {:label (:block/title class)
                                      :value (:block/uuid class)})

+ 4 - 1
src/main/frontend/components/property/value.cljs

@@ -553,7 +553,10 @@
                                               "Choose nodes"
                                               :else
                                               "Choose node")
-                 :show-new-when-not-exact-match? (if (and parent-property? (contains? (set children-pages) (:db/id block)))
+                 :show-new-when-not-exact-match? (if (or (and parent-property? (contains? (set children-pages) (:db/id block)))
+                                                         ;; Don't allow creating private tags
+                                                         (seq (set/intersection (set (map :db/ident classes))
+                                                                                ldb/private-tags)))
                                                    false
                                                    true)
                  :extract-chosen-fn :value

+ 1 - 1
src/main/frontend/components/query/builder.cljs

@@ -227,7 +227,7 @@
         db-based? (config/db-based-graph? repo)]
     (rum/use-effect!
      (fn []
-       (let [result (db-model/get-all-classes repo {:except-root-class? true})]
+       (let [result (db-model/get-all-readable-classes repo {:except-root-class? true})]
          (set-values! result)))
      [])
     (let [items (->> values

+ 12 - 3
src/main/frontend/db/model.cljs

@@ -798,18 +798,27 @@ independent of format as format specific heading characters are stripped"
                     :nonce (:nonce shape)}))))))
 
 (defn get-all-classes
-  [repo & {:keys [except-root-class?]
-           :or {except-root-class? false}}]
+  [repo & {:keys [except-root-class? except-private-tags?]
+           :or {except-root-class? false
+                except-private-tags? true}}]
   (let [db (conn/get-db repo)
         classes (->> (d/datoms db :avet :block/tags :logseq.class/Tag)
                      (map (fn [d]
                             (db-utils/entity db (:e d))))
                      (remove (fn [d]
-                               (contains? ldb/private-tags (:db/ident d)))))]
+                               (and except-private-tags?
+                                    (contains? ldb/private-tags (:db/ident d))))))]
     (if except-root-class?
       (keep (fn [e] (when-not (= :logseq.class/Root (:db/ident e)) e)) classes)
       classes)))
 
+(defn get-all-readable-classes
+  "Gets all classes that are used in a read only context e.g. querying or used
+  for property value selection. This should _not_ be used in a write context e.g.
+  adding a tag to a node or creating a new node with a tag"
+  [repo opts]
+  (get-all-classes repo (merge opts {:except-private-tags? false})))
+
 (defn get-structured-children
   [repo eid]
   (->>