chore: move db only property util fns to their own ns

by doing this found a couple places where we accidentally called db fns
in file graph contexts
This commit is contained in:
Gabriel Horner
2023-11-17 16:36:09 -05:00
parent 6f9143df4f
commit e95531869a
16 changed files with 103 additions and 81 deletions

View File

@@ -1,13 +1,11 @@
(ns frontend.handler.property.util
"Utility fns for properties. Most of these are used in file or db graphs.
"Utility fns for properties that are for both file and db graphs.
Some fns like lookup and get-property were written to easily be backwards
compatible with file graphs"
(:require [frontend.config :as config]
[frontend.state :as state]
[logseq.db.frontend.property :as db-property]
[logseq.graph-parser.util :as gp-util]
[frontend.db :as db]
[clojure.set :as set]
[frontend.util :as util]))
(defn lookup
@@ -27,26 +25,13 @@
(when-let [properties (:block/properties block)]
(lookup properties key))))
(defn get-property-name
"Get a property's name given its uuid"
[uuid]
(:block/original-name (db/entity [:block/uuid uuid])))
(defn get-built-in-property-uuid
"Get a built-in property's uuid given its name"
([property-name] (get-built-in-property-uuid (state/get-current-repo) property-name))
([repo property-name]
(:block/uuid (db/entity repo [:block/name (name property-name)]))))
(defn get-user-property-uuid
(defn get-page-uuid
"Get a user property's uuid given its unsanitized name"
([property-name] (get-user-property-uuid (state/get-current-repo) property-name))
;; Get a page's uuid given its unsanitized name
([property-name] (get-page-uuid (state/get-current-repo) property-name))
([repo property-name]
(:block/uuid (db/entity repo [:block/name (gp-util/page-name-sanity-lc (name property-name))]))))
;; Get a page's uuid given its unsanitized name
(def get-page-uuid get-user-property-uuid)
(defn get-pid
"Get a property's id (name or uuid) given its name. For file and db graphs"
[property-name]
@@ -62,34 +47,4 @@
(get-property block :logseq.tldraw.page))
(defn shape-block? [block]
(= :whiteboard-shape (get-property block :ls-type)))
(defonce *hidden-built-in-properties (atom #{}))
(defn all-hidden-built-in-properties?
"Checks if the given properties are all hidden built-in properties"
[properties]
(let [repo (state/get-current-repo)]
(when (empty? @*hidden-built-in-properties)
(let [built-in-properties (set (map #(get-built-in-property-uuid repo (name %))
db-property/hidden-built-in-properties))]
(reset! *hidden-built-in-properties built-in-properties)))
(set/subset? (set properties) @*hidden-built-in-properties)))
(defn readable-properties
"Given a DB graph's properties, returns a readable properties map with keys as
property names and property values dereferenced where possible. A property's
value will only be a uuid if it's a page or a block"
[properties]
(->> properties
(map (fn [[k v]]
(let [prop-ent (db/entity [:block/uuid k])]
[(-> prop-ent
:block/name
keyword)
(if (seq (get-in prop-ent [:block/schema :values])) ; closed values
(when-let [block (db/entity [:block/uuid v])]
(or (:block/original-name block)
(get-in block [:block/schema :value])))
v)])))
(into {})))
(= :whiteboard-shape (get-property block :ls-type)))