fix: built-in property id changes after app reload

This commit is contained in:
Tienson Qin
2023-08-07 20:32:38 +08:00
parent 7a5ee44f85
commit 3a530496e3
5 changed files with 46 additions and 21 deletions

View File

@@ -463,7 +463,8 @@
[:div#edit-new-property
(property-input block *property-key *property-value opts)]
(or (seq properties)
(or (and (seq properties)
(not (pu/all-built-in-properties? (keys (:block/properties block)))))
(:page-configure? opts))
[:a {:style {:margin-left 2}
:title "Add another property"

View File

@@ -69,12 +69,18 @@
[conn]
(let [txs (keep
(fn [[k-keyword {:keys [schema original-name]}]]
(let [k-name (name k-keyword)]
(let [property (d/entity @conn [:block/name k-name])]
(when-not (= {:schema schema
:original-name original-name}
{:schema (:block/schema property)
:original-name (:block/original-name property)})
(let [k-name (name k-keyword)
property (d/entity @conn [:block/name k-name])]
(when-not (= {:schema schema
:original-name (or original-name k-name)}
{:schema (:block/schema property)
:original-name (:block/original-name property)})
(if property
{:block/schema schema
:block/original-name (or original-name k-name)
:block/name (util/page-name-sanity-lc k-name)
:block/uuid (:block/uuid property)
:block/type "property"}
(outliner-core/block-with-timestamps
{:block/schema schema
:block/original-name (or original-name k-name)

View File

@@ -38,7 +38,9 @@
(get-in b [:block/left :db/id])])
page (d/entity db page-id)
blocks (:block/_page page)
parent-left->es (group-by parent-left-f blocks)
parent-left->es (->> (group-by parent-left-f blocks)
(remove (fn [[k _v]] (= k [nil nil])))
(into {}))
conflicted (filter #(> (count (second %)) 1) parent-left->es)]
(if (seq conflicted)
[:conflict-parent-left conflicted]

View File

@@ -3353,18 +3353,20 @@
([block-id {:keys [semantic?]
:or {semantic? false}}]
(when block-id
(if-let [block (db-model/query-block-by-uuid block-id)]
(or (db-model/has-children? block-id)
(valid-dsl-query-block? block)
(valid-custom-query-block? block)
(seq (:block/properties block))
(seq (:block/alias block))
(and
(:outliner/block-title-collapse-enabled? (state/get-config))
(block-with-title? (:block/format block)
(:block/content block)
semantic?)))
false))))
(let [repo (state/get-current-repo)]
(if-let [block (db/entity [:block/uuid block-id])]
(or (db-model/has-children? block-id)
(valid-dsl-query-block? block)
(valid-custom-query-block? block)
(and (config/db-based-graph? repo)
(seq (:block/properties block))
(not (pu/all-built-in-properties? (keys (:block/properties block)))))
(and
(:outliner/block-title-collapse-enabled? (state/get-config))
(block-with-title? (:block/format block)
(:block/content block)
semantic?)))
false)))))
(defn all-blocks-with-level
"Return all blocks associated with correct level

View File

@@ -4,7 +4,8 @@
[frontend.config :as config]
[logseq.graph-parser.property :as gp-property]
[logseq.graph-parser.util :as gp-util]
[frontend.db :as db]))
[frontend.db :as db]
[clojure.set :as set]))
(defn lookup
"Get the value of coll's (a map) `key`"
@@ -32,3 +33,16 @@
(defn shape-block? [block]
(= :whiteboard-shape (get-property block :ls-type)))
(defonce *db-built-in-properties (atom {}))
(defn all-built-in-properties?
[properties]
(let [repo (state/get-current-repo)]
(when (empty? @*db-built-in-properties)
(let [built-in-properties (set (map
(fn [p]
(:block/uuid (db/entity [:block/name (name p)])))
gp-property/db-built-in-properties-keys))]
(swap! *db-built-in-properties assoc repo built-in-properties)))
(set/subset? (set properties) (get @*db-built-in-properties repo))))