fix: add pre-configured properties when creating a new db graph

This commit is contained in:
Tienson Qin
2023-08-02 01:49:23 +08:00
parent 791bd90d88
commit 15cb78fbf7
10 changed files with 108 additions and 39 deletions

View File

@@ -47,6 +47,7 @@
[:div.grid.grid-cols-4.gap-1.leading-8
[:label "Schema type:"]
(let [schema-types (->> (keys property-handler/builtin-schema-types)
(remove gp-property/db-built-in-properties-keys)
(map (comp string/capitalize name))
(map (fn [type]
{:label type
@@ -548,7 +549,7 @@
(:properties (:block/schema e))))))
(map (fn [id]
[id nil])))
built-in-properties (set (map name (gp-property/full-built-in-properties)))
built-in-properties (set (map name gp-property/db-built-in-properties-keys))
properties (->> (concat (seq properties) class-properties)
(util/distinct-by first)
(remove (fn [[k _v]]

View File

@@ -110,9 +110,11 @@
(defn get-columns [current-block result {:keys [page?]}]
(let [properties (:block/properties current-block)
query-properties (or (pu/lookup properties :query-properties) "")
query-properties (some-> query-properties
(common-handler/safe-read-string "Parsing query properties failed"))
query-properties (pu/lookup properties :query-properties)
query-properties (if (config/db-based-graph? (state/get-current-repo))
query-properties
(some-> query-properties
(common-handler/safe-read-string "Parsing query properties failed")))
query-properties (if page? (remove #{:block} query-properties) query-properties)
columns (if (seq query-properties)
query-properties

View File

@@ -192,11 +192,11 @@
ref-block)
(let [text (:text content)
wrap-props #(if-let [stamp (:image content)]
(assoc % :hl-type "area" :hl-stamp stamp)
(assoc % :hl-type :area :hl-stamp stamp)
%)
properties (->>
(wrap-props
{:ls-type "annotation"
{:ls-type :annotation
:hl-page page
:hl-color (:color properties)
;; force custom uuid

View File

@@ -56,7 +56,14 @@
logseq-block?]
:object [:fn
{:error/message "should be an object"}
logseq-object?]})
logseq-object?]
;; internal usage
:map map?
:coll coll?
:any some?})
(def internal-builtin-schema-types #{:map :coll :any})
;; schema -> type, cardinality, object's class
;; min, max -> string length, number range, cardinality size limit

View File

@@ -804,19 +804,26 @@
[block-id all-properties key add?]
(when-let [block (db/entity [:block/uuid block-id])]
(let [properties (:block/properties block)
query-properties (or (pu/lookup properties :query-properties) "")
query-properties (-> query-properties
(common-handler/safe-read-string "Failed to parse query properties"))
query-properties (pu/lookup properties :query-properties)
repo (state/get-current-repo)
db-based? (config/db-based-graph? repo)
query-properties (if db-based?
query-properties
(some-> query-properties
(common-handler/safe-read-string "Parsing query properties failed")))
query-properties (if (seq query-properties)
query-properties
all-properties)
query-properties (if add?
(distinct (conj query-properties key))
(remove #{key} query-properties))
query-properties (vec query-properties)
repo (state/get-current-repo)]
query-properties (vec query-properties)]
(if (seq query-properties)
(property-handler/set-block-property! repo block-id :query-properties (str query-properties))
(property-handler/set-block-property! repo block-id
:query-properties
(if db-based?
query-properties
(str query-properties)))
(property-handler/remove-block-property! repo block-id :query-properties)))))
(defn set-block-timestamp!

View File

@@ -949,16 +949,20 @@
(let [name (:block/name p)]
(or (util/uuid-string? name)
(gp-config/draw? name)
(db/built-in-pages-names (string/upper-case name))))))
(db/built-in-pages-names (string/upper-case name))
(gp-property/db-built-in-properties-keys-str name)
(contains? #{"macro"} (:block/type p))))))
(common-handler/fix-pages-timestamps)))
(defn get-filters
[page-name]
(let [properties (db/get-page-properties page-name)
properties-str (or (pu/lookup properties :filters) "{}")]
(try (reader/read-string properties-str)
(catch :default e
(log/error :syntax/filters e)))))
(let [properties (db/get-page-properties page-name)]
(if (config/db-based-graph? (state/get-current-repo))
(pu/lookup properties :filters)
(let [properties-str (or (:filters properties) "{}")]
(try (reader/read-string properties-str)
(catch :default e
(log/error :syntax/filters e)))))))
(defn save-filter!
[page-name filter-state]

View File

@@ -12,7 +12,7 @@
(let [repo (state/get-current-repo)]
(if (and (config/db-based-graph? repo)
(keyword? key)
(contains? (gp-property/full-built-in-properties) key))
(contains? gp-property/db-built-in-properties-keys key))
(when-let [property (db/entity repo [:block/name (gp-util/page-name-sanity-lc (name key))])]
(get coll (:block/uuid property)))
(get coll key))))

View File

@@ -26,6 +26,7 @@
[frontend.db.persist :as db-persist]
[logseq.graph-parser :as graph-parser]
[logseq.graph-parser.config :as gp-config]
[logseq.graph-parser.property :as gp-property]
[electron.ipc :as ipc]
[cljs-bean.core :as bean]
[clojure.core.async :as async]
@@ -34,7 +35,8 @@
[logseq.common.path :as path]
[logseq.common.config :as common-config]
[frontend.db.react :as react]
[frontend.db.listener :as db-listener]))
[frontend.db.listener :as db-listener]
[frontend.modules.outliner.core :as outliner-core]))
;; Project settings should be checked in two situations:
;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
@@ -544,16 +546,27 @@
_ (state/add-repo! {:url full-graph-name})
_ (route-handler/redirect-to-home!)
_ (db/transact! full-graph-name [(react/kv :db/type "db")]
{:skip-persist? true})
initial-data [{:block/uuid (db/new-block-id)
:file/path (str "logseq/" "config.edn")
:file/content config/config-default-content}
{:block/uuid (db/new-block-id)
:file/path (str "logseq/" "custom.css")
:file/content ""}
{:block/uuid (db/new-block-id)
:file/path (str "logseq/" "custom.js")
:file/content ""}]
{:skip-persist? true})
initial-files [{:block/uuid (db/new-block-id)
:file/path (str "logseq/" "config.edn")
:file/content config/config-default-content}
{:block/uuid (db/new-block-id)
:file/path (str "logseq/" "custom.css")
:file/content ""}
{:block/uuid (db/new-block-id)
:file/path (str "logseq/" "custom.js")
:file/content ""}]
default-properties (map
(fn [[k-keyword {:keys [schema]}]]
(let [k-name (name k-keyword)]
(outliner-core/block-with-timestamps
{:block/schema schema
:block/original-name k-name
:block/name (util/page-name-sanity-lc k-name)
:block/uuid (db/new-block-id)
:block/type "property"})))
gp-property/db-built-in-properties)
initial-data (concat initial-files default-properties)
_ (db/transact! full-graph-name initial-data)
_ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
;; TODO: handle global graph