chore: keep using class instead of tag for internal usage

pull/11458/head
Tienson Qin 2024-08-06 07:13:55 +08:00
parent 5d2cd70142
commit f46372b346
30 changed files with 61 additions and 61 deletions

View File

@ -82,7 +82,7 @@
(count ent-maps) " entities, "
(count (filter :block/name ent-maps)) " pages, "
(count (filter :block/title ent-maps)) " blocks, "
(count (filter ldb/tag? ent-maps)) " tags, "
(count (filter ldb/class? ent-maps)) " tags, "
(count (filter #(seq (:block/tags %)) ent-maps)) " objects, "
(count (filter ldb/property? ent-maps)) " properties and "
(count (mapcat db-property/properties ent-maps)) " property pairs"))

View File

@ -85,7 +85,7 @@
(throw e))))))))
(def page? sqlite-util/page?)
(def tag? sqlite-util/tag?)
(def class? sqlite-util/class?)
(def property? sqlite-util/property?)
(def closed-value? sqlite-util/closed-value?)
(def whiteboard? sqlite-util/whiteboard?)
@ -437,7 +437,7 @@
"Whether property a built-in property for the specific class"
[class-entity property-entity]
(and (built-in? class-entity)
(tag? class-entity)
(class? class-entity)
(built-in? property-entity)
(contains? (set (map :db/ident (:class/schema.properties class-entity)))
(:db/ident property-entity))))
@ -541,7 +541,7 @@
(loop [current-parent parent]
(when (and
current-parent
(tag? parent)
(class? parent)
(not (contains? @*classes (:db/id parent))))
(swap! *classes conj (:db/id current-parent))
(recur (:class/parent current-parent)))))

View File

@ -214,7 +214,7 @@
"Common attributes for pages"
[[:block/name :string]
[:block/title :string]
[:block/type [:enum "page" "tag" "property" "whiteboard" "journal" "hidden"]]
[:block/type [:enum "page" "class" "property" "whiteboard" "journal" "hidden"]]
[:block/alias {:optional true} [:set :int]]
;; TODO: Should this be here or in common?
[:block/path-refs {:optional true} [:set :int]]
@ -431,7 +431,7 @@
(cond
(sqlite-util/property? d)
:property
(sqlite-util/tag? d)
(sqlite-util/class? d)
:class
(sqlite-util/hidden? d)
:hidden

View File

@ -13,7 +13,7 @@
;; :block/type is a string type of the current block
;; "whiteboard" for whiteboards
;; "property" for property blocks
;; "tag" for structured page
;; "class" for structured page
:block/type {:db/index true}
:block/schema {}
:block/uuid {:db/unique :db.unique/identity}

View File

@ -221,7 +221,7 @@
(d/datoms db :eavt (:e d))))))
[
;; property and class pages are pulled from `get-all-pages` already
;; "property" "tag"
;; "property" "class"
"closed value"]))
(defn get-favorites

View File

@ -113,7 +113,7 @@
{:pre [(qualified-keyword? (:db/ident block))]}
(block-with-timestamps
(cond-> (merge block
{:block/type "tag"
{:block/type "class"
:block/format :markdown})
(not= (:db/ident block) :logseq.class/Root)
(assoc :class/parent :logseq.class/Root))))
@ -130,12 +130,12 @@
(defn page?
[block]
(contains? #{"page" "journal" "whiteboard" "tag" "property" "hidden"}
(contains? #{"page" "journal" "whiteboard" "class" "property" "hidden"}
(:block/type block)))
(defn tag?
(defn class?
[entity]
(= (:block/type entity) "tag"))
(= (:block/type entity) "class"))
(defn property?
[entity]
(= (:block/type entity) "property"))

View File

@ -14,13 +14,13 @@
[{:page {:block/title "page1"}
:blocks [{:block/title "Jrue Holiday" :build/tags [:Person]}]}
{:page {:block/title "Jayson Tatum" :build/tags [:Person]}}])]
(is (= {:block/tags [{:block/title "Person", :block/type "tag"}]}
(is (= {:block/tags [{:block/title "Person", :block/type "class"}]}
(first (d/q '[:find [(pull ?b [{:block/tags [:block/title :block/type]}]) ...]
:where [?b :block/title "Jrue Holiday"]]
@conn)))
"Person class is created and correctly associated to a block")
(is (= {:block/tags [{:block/title "Person", :block/type "tag"}]}
(is (= {:block/tags [{:block/title "Person", :block/type "class"}]}
(first (d/q '[:find [(pull ?b [{:block/tags [:block/title :block/type]}]) ...]
:where [?b :block/title "Jayson Tatum"]]
@conn)))

View File

@ -61,7 +61,7 @@
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
task (d/entity @conn :logseq.class/Task)]
(is (ldb/tag? task)
(is (ldb/class? task)
"Task class has correct type")
(is (= 3 (count (:class/schema.properties task)))
"Has correct number of task properties")

View File

@ -358,7 +358,7 @@
:else
nil)]
(when page
(let [type (if class? "tag" (or (:block/type page) "page"))]
(let [type (if class? "class" (or (:block/type page) "page"))]
(assoc page :block/type type))))))
(defn- with-page-refs-and-tags

View File

@ -68,7 +68,7 @@
(if-let [existing-tag-uuid (first
(d/q '[:find [?uuid ...]
:in $ ?name
:where [?b :block/uuid ?uuid] [?b :block/type "tag"] [?b :block/name ?name]]
:where [?b :block/uuid ?uuid] [?b :block/type "class"] [?b :block/name ?name]]
db
(:block/name tag-block)))]
[:block/uuid existing-tag-uuid]
@ -1017,7 +1017,7 @@
(defn- export-class-properties
[conn repo-or-conn]
(let [user-classes (->> (d/q '[:find (pull ?b [:db/id :db/ident])
:where [?b :block/type "tag"]] @conn)
:where [?b :block/type "class"]] @conn)
(map first)
(remove #(db-class/built-in-classes (:db/ident %))))
class-to-prop-uuids

View File

@ -377,7 +377,7 @@
"tagged block tag converts tag to page ref")
(is (= [(:db/id tag-page)] (map :db/id (:block/refs block)))
"tagged block has correct refs")
(is (and tag-page (not (ldb/tag? tag-page)))
(is (and tag-page (not (ldb/class? tag-page)))
"tag page is not a class")
(is (= {:logseq.property/page-tags #{"Movie"}}
@ -406,9 +406,9 @@
(:block/tags (readable-properties @conn block)))
"tagged block has configured tag imported as a class")
(is (= "tag" (:block/type tag-page))
(is (= "class" (:block/type tag-page))
"configured tag page in :tag-classes is a class")
(is (and another-tag-page (not (ldb/tag? another-tag-page)))
(is (and another-tag-page (not (ldb/class? another-tag-page)))
"unconfigured tag page is not a class")
(is (= {:block/tags [:user.class/Movie]}
@ -445,7 +445,7 @@
(is (= #{:user.class/Property :user.class/Movie}
(->> @conn
(d/q '[:find [?ident ...]
:where [?b :block/type "tag"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
:where [?b :block/type "class"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
set))
"All classes are correctly defined by :type")
@ -467,7 +467,7 @@
"tagged block can have another property that references the same class it is tagged with,
without creating a duplicate class")
(is (= "tag" (:block/type tag-page))
(is (= "class" (:block/type tag-page))
"configured tag page derived from :property-classes is a class")
(is (nil? (find-page-by-name @conn "type"))
"No page exists for configured property")
@ -499,7 +499,7 @@
(is (= #{:user.class/Movie :user.class/CreativeWork :user.class/Thing}
(->> @conn
(d/q '[:find [?ident ...]
:where [?b :block/type "tag"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
:where [?b :block/type "class"] [?b :db/ident ?ident] (not [?b :logseq.property/built-in?])])
set))
"All classes are correctly defined by :type")

View File

@ -79,7 +79,7 @@
(let [refs (:block/_refs page)]
(and (or (zero? (count refs))
(= #{db-id} (set (map :db/id refs))))
(not (some #{"tag" "property"} (:block/type page))))))}))]
(not (some #{"class" "property"} (:block/type page))))))}))]
(when (seq orphaned-pages)
(let [tx (mapv (fn [page] [:db/retractEntity (:db/id page)]) orphaned-pages)]
(swap! txs-state (fn [state] (vec (concat state tx)))))))))

View File

@ -335,7 +335,7 @@
(defn ^:api get-class-parents
[tags]
(let [tags' (filter ldb/tag? tags)]
(let [tags' (filter ldb/class? tags)]
(set (mapcat ldb/get-class-parents tags'))))
(defn ^:api get-class-properties
@ -351,7 +351,7 @@
(let [block (d/entity db eid)
classes (->> (:block/tags block)
(sort-by :block/name)
(filter ldb/tag?))
(filter ldb/class?))
class-parents (get-class-parents classes)
all-classes (->> (concat classes class-parents)
(filter (fn [class]
@ -514,7 +514,7 @@
(defn class-add-property!
[conn class-id property-id]
(when-let [class (d/entity @conn class-id)]
(if (ldb/tag? class)
(if (ldb/class? class)
(ldb/transact! conn
[[:db/add (:db/id class) :class/schema.properties property-id]]
{:outliner-op :save-block})
@ -524,7 +524,7 @@
(defn class-remove-property!
[conn class-id property-id]
(when-let [class (d/entity @conn class-id)]
(when (ldb/tag? class)
(when (ldb/class? class)
(when-let [property (d/entity @conn property-id)]
(when-not (ldb/built-in-class-property? class property)
(ldb/transact! conn [[:db/retract (:db/id class) :class/schema.properties property-id]]

View File

@ -13,7 +13,7 @@
(sr/defkeyword :block/type
"block type"
[:enum "page" "property" "tag" "whiteboard" "hidden"])
[:enum "page" "property" "class" "whiteboard" "hidden"])
(sr/defkeyword :block/parent
"page blocks don't have this attr")

View File

@ -223,7 +223,7 @@
(let [entity (db/entity [:block/uuid (:block/uuid page)])
source-page (model/get-alias-source-page repo (:db/id entity))
icon (cond
(ldb/tag? entity)
(ldb/class? entity)
"hash"
(ldb/property? entity)
"letter-p"

View File

@ -52,7 +52,7 @@
[state page *mode]
(let [*mode *mode
mode (rum/react *mode)
class? (ldb/tag? page)
class? (ldb/class? page)
property? (ldb/property? page)
page-opts {:configure? true}]
(when (nil? mode)
@ -75,7 +75,7 @@
(rum/defc mode-switch < rum/reactive
[type *mode]
(let [current-mode (rum/react *mode)
class? (= type "tag")
class? (= type "class")
property? (= type "property")
modes (->
(cond
@ -106,7 +106,7 @@
*hover? (::hover? state)
*mode (::mode state)
type (:block/type page)
class? (ldb/tag? page)
class? (ldb/class? page)
collapsed? (not @*show-info?)
has-properties? (or
(seq (:block/tags page))
@ -131,7 +131,7 @@
(reset! *hover? false))
:on-click (if config/publishing?
(fn [_]
(when (contains? #{"tag" "property"} type)
(when (contains? #{"class" "property"} type)
(swap! *show-info? not)))
#(do
(swap! *show-info? not)

View File

@ -172,7 +172,7 @@
[:div.flex.flex-row.items-center.gap-1
(when-not db-tag?
(cond
(ldb/tag? block)
(ldb/class? block)
[:div (ui/icon "hash" {:size 14})]
(ldb/property? block)
[:div (ui/icon "letter-p" {:size 14})]

View File

@ -32,7 +32,7 @@
(defn get-node-icon
[node-entity opts]
(let [default-icon-id (cond
(ldb/tag? node-entity)
(ldb/class? node-entity)
"hash"
(ldb/property? node-entity)
"letter-p"

View File

@ -239,7 +239,7 @@
{:entities (count entities)
:pages (count (filter :block/name entities))
:blocks (count (filter :block/title entities))
:classes (count (filter ldb/tag? entities))
:classes (count (filter ldb/class? entities))
:objects (count (filter #(seq (:block/tags %)) entities))
:properties (count (filter ldb/property? entities))
:property-values (count (mapcat :block/properties entities))})

View File

@ -336,7 +336,7 @@
journal? (ldb/journal? page)
icon (or (get page (pu/get-pid :logseq.property/icon))
(when db-based?
(or (when (ldb/tag? page)
(or (when (ldb/class? page)
{:type :tabler-icon
:id "hash"})
(when (ldb/property? page)
@ -557,14 +557,14 @@
(cond
(and db-based? (not block?))
(db-page/page-info page
(if (and (ldb/tag? page) sidebar?)
(if (and (ldb/class? page) sidebar?)
(atom true)
(::show-page-info? state)))
(and (not db-based?) (not block?))
[:div.pb-2])
(when (and db-based? (ldb/tag? page))
(when (and db-based? (ldb/class? page))
[:div.mt-8
(objects/class-objects page)])
@ -572,7 +572,7 @@
[:div.mt-8
(objects/property-related-objects page)])
(when-not (and db-based? (or (ldb/tag? page) (ldb/property? page)))
(when-not (and db-based? (or (ldb/class? page) (ldb/property? page)))
[:div
(when (and block? (not sidebar?) (not whiteboard?))
(let [config (merge config {:id "block-parent"
@ -595,7 +595,7 @@
(when (and (not block?) (not db-based?))
(tagged-pages repo page page-title))
(when (ldb/tag? page)
(when (ldb/class? page)
(class-component/class-children page))
;; referenced blocks

View File

@ -113,7 +113,7 @@
(defn- handle-delete-property!
[block property & {:keys [class? class-schema?]}]
(let [class? (or class? (ldb/tag? block))
(let [class? (or class? (ldb/class? block))
remove! #(let [repo (state/get-current-repo)]
(if (and class? class-schema?)
(db-property-handler/class-remove-property! (:db/id block) (:db/id property))
@ -131,7 +131,7 @@
[entity property-uuid-or-name schema {:keys [class-schema? page-configure?]}]
(p/let [repo (state/get-current-repo)
;; Both conditions necessary so that a class can add its own page properties
add-class-property? (and (ldb/tag? entity) page-configure? class-schema?)
add-class-property? (and (ldb/class? entity) page-configure? class-schema?)
result (when (uuid? property-uuid-or-name)
(db-async/<get-block repo property-uuid-or-name {:children? false}))
;; In block context result is in :block
@ -193,7 +193,7 @@
(reset! *show-new-property-config? :adding-property))
(p/let [property' (when block (<add-property-from-dropdown block property-name schema opts))
property (or property' property)
add-class-property? (and (ldb/tag? block) page-configure? class-schema?)]
add-class-property? (and (ldb/class? block) page-configure? class-schema?)]
(when *property (reset! *property property))
(p/do!
(when *show-new-property-config? (reset! *show-new-property-config? false))
@ -475,7 +475,7 @@
(reset! *show-new-property-config? true))
(reset! *property property)
(when property
(let [add-class-property? (and (ldb/tag? block) class-schema?)
(let [add-class-property? (and (ldb/class? block) class-schema?)
type (get-in property [:block/schema :type])]
(cond
add-class-property?

View File

@ -101,7 +101,7 @@
([block property-id property-value' {:keys [exit-edit? class-schema?]
:or {exit-edit? true}}]
(let [repo (state/get-current-repo)
class? (ldb/tag? block)
class? (ldb/class? block)
property (db/entity property-id)
many? (db-property/many? property)
checkbox? (= :checkbox (get-in property [:block/schema :type]))]
@ -313,7 +313,7 @@
(defn- get-node-icon
[node]
(cond
(ldb/tag? node)
(ldb/class? node)
"hash"
(ldb/property? node)
"letter-p"
@ -569,7 +569,7 @@
(if (state/sub-async-query-loading value)
[:div.text-sm.opacity-70 "loading"]
(if-let [v-block (db/sub-block (:db/id value))]
(let [class? (ldb/tag? v-block)
(let [class? (ldb/class? v-block)
invalid-warning [:div.warning.text-sm
"Invalid block value, please delete the current property."]]
(when v-block

View File

@ -62,7 +62,7 @@
[page-entity *filters total filter-n filtered-ref-blocks *ref-pages]
(let [filters @*filters
threshold (state/get-linked-references-collapsed-threshold)
default-collapsed? (or (>= total threshold) (ldb/tag? page-entity))
default-collapsed? (or (>= total threshold) (ldb/class? page-entity))
*collapsed? (atom nil)]
(ui/foldable
[:div.flex.flex-row.flex-1.justify-between.items-center

View File

@ -288,7 +288,7 @@
(<q graph {:transact-db? false}
'[:find [(pull ?tag [:db/id :block/title])]
:where
[?tag :block/type "tag"]]))
[?tag :block/type "class"]]))
(comment
(defn <fetch-all-pages

View File

@ -758,7 +758,7 @@ independent of format as format specific heading characters are stripped"
[repo & {:keys [except-root-class?]
:or {except-root-class? false}}]
(let [db (conn/get-db repo)
classes (->> (d/datoms db :avet :block/type "tag")
classes (->> (d/datoms db :avet :block/type "class")
(map (fn [d]
(db-utils/entity db (:e d)))))]
(if except-root-class?

View File

@ -341,7 +341,7 @@
(let [chosen (:block/title chosen-result)
class? (and db-based? hashtag?
(or (string/includes? chosen (str (t :new-tag) " "))
(ldb/tag? (db/get-page chosen))))
(ldb/class? (db/get-page chosen))))
chosen (-> chosen
(string/replace-first (str (t :new-tag) " ") "")
(string/replace-first (str (t :new-page) " ") ""))

View File

@ -103,7 +103,7 @@
type (if (set? types)
(cond
(contains? types "class")
"tag"
"class"
(contains? types "property")
"property"
(contains? types "whiteboard")

View File

@ -15,7 +15,7 @@
(defn- build-page-tx [conn properties page {:keys [whiteboard? class? tags]}]
(when (:block/uuid page)
(let [page (assoc page :block/type (cond class? "tag"
(let [page (assoc page :block/type (cond class? "class"
whiteboard? "whiteboard"
(:block/type page) (:block/type page)
:else "page"))

View File

@ -16,7 +16,7 @@
:block/created-at 1720017595872,
:block/format :markdown,
:db/ident :user.class/yyy,
:block/type "tag",
:block/type "class",
:block/name "yyy",
:block/title "yyy"}])]
(is (= {:update
@ -26,7 +26,7 @@
:av-coll
[[:block/name "[\"~#'\",\"yyy\"]" 1 true]
[:block/title "[\"~#'\",\"yyy\"]" 1 true]
[:block/type "[\"~#'\",\"tag\"]" 1 true]]}}
[:block/type "[\"~#'\",\"class\"]" 1 true]]}}
(:remote-ops
(#'subject/local-block-ops->remote-ops
db
@ -36,7 +36,7 @@
:av-coll
[[:block/name (ldb/write-transit-str "yyy") 1 true]
[:block/title (ldb/write-transit-str "yyy") 1 true]
[:block/type (ldb/write-transit-str "tag") 1 true]]}]}))))))
[:block/type (ldb/write-transit-str "class") 1 true]]}]}))))))
(testing "user.property/xxx creation"
(let [block-uuid (random-uuid)

View File

@ -91,7 +91,7 @@
[:db/add 62 :block/created-at 1720019497643 536870954]
[:db/add 62 :block/format :markdown 536870954]
[:db/add 62 :db/ident :user.class/zzz 536870954]
[:db/add 62 :block/type "tag" 536870954]
[:db/add 62 :block/type "class" 536870954]
[:db/add 62 :block/name "zzz" 536870954]
[:db/add 62 :block/title "zzz" 536870954]]
{:keys [db-before db-after tx-data]} (d/transact! conn tx-data)
@ -105,7 +105,7 @@
[[:block/updated-at "[\"~#'\",1720019497643]"]
[:block/created-at "[\"~#'\",1720019497643]"]
[:block/title "[\"~#'\",\"zzz\"]"]
[:block/type "[\"~#'\",\"tag\"]"]
[:block/type "[\"~#'\",\"class\"]"]
;;1. no :class/parent, because db/id 4 block doesn't exist in empty-db
;;2. shouldn't have :db/ident, :db/ident is special, will be handled later
]}]]