From 28e637e8555f81dbf7aaaa8a03410bbaaa90ba62 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Mon, 29 Jan 2024 09:55:34 -0500 Subject: [PATCH] chore: merge 2 new property fns together refactor possible since page-name-sanity-lc in common-util --- deps/db/src/logseq/db/frontend/property/util.cljs | 13 +------------ deps/db/src/logseq/db/sqlite/create_graph.cljs | 7 +++---- deps/db/src/logseq/db/sqlite/util.cljs | 13 ++++++++----- .../src/logseq/tasks/db_graph/create_graph.cljs | 14 +++++++------- src/main/frontend/handler/db_based/property.cljs | 7 +------ 5 files changed, 20 insertions(+), 34 deletions(-) diff --git a/deps/db/src/logseq/db/frontend/property/util.cljs b/deps/db/src/logseq/db/frontend/property/util.cljs index 5c301f098..b131f74cc 100644 --- a/deps/db/src/logseq/db/frontend/property/util.cljs +++ b/deps/db/src/logseq/db/frontend/property/util.cljs @@ -47,16 +47,6 @@ (assoc :block/type #{"hidden"} :block/format :markdown)))) -(defn new-property-tx - "Provide attributes for a new built-in property given name, schema and uuid. - TODO: Merge this with sqlite-util/build-new-property once common-util/page-name-sanity-lc - is available to deps/db" - [prop-name prop-schema prop-uuid] - {:block/uuid prop-uuid - :block/schema (merge {:type :default} prop-schema) - :block/original-name (name prop-name) - :block/name (common-util/page-name-sanity-lc (name prop-name))}) - (defn build-closed-values "Builds all the tx needed for property with closed values including the hidden page and closed value blocks as needed" @@ -76,8 +66,7 @@ (:closed-values property))) property-schema (assoc (:block/schema property) :values (mapv :block/uuid closed-value-blocks-tx)) - property-tx (merge (sqlite-util/build-new-property - (new-property-tx prop-name property-schema (:block/uuid property))) + property-tx (merge (sqlite-util/build-new-property prop-name property-schema (:block/uuid property)) property-attributes)] (into [property-tx page-tx] (when-not closed-value-page-uuids? closed-value-blocks-tx)))) diff --git a/deps/db/src/logseq/db/sqlite/create_graph.cljs b/deps/db/src/logseq/db/sqlite/create_graph.cljs index b0bc1fa39..9aa330e06 100644 --- a/deps/db/src/logseq/db/sqlite/create_graph.cljs +++ b/deps/db/src/logseq/db/sqlite/create_graph.cljs @@ -22,10 +22,9 @@ {:block/schema schema :block/uuid (d/squuid) :closed-values closed-values} {:icon-id (get default-property-uuids :icon)}) [(sqlite-util/build-new-property - {:block/schema schema - :block/original-name (or original-name k-name) - :block/name (common-util/page-name-sanity-lc k-name) - :block/uuid (get default-property-uuids k-keyword (d/squuid))})]))) + (or original-name k-name) + schema + (get default-property-uuids k-keyword (d/squuid)))]))) db-property/built-in-properties))) (defn build-db-initial-data diff --git a/deps/db/src/logseq/db/sqlite/util.cljs b/deps/db/src/logseq/db/sqlite/util.cljs index 7782dae00..c540704d6 100644 --- a/deps/db/src/logseq/db/sqlite/util.cljs +++ b/deps/db/src/logseq/db/sqlite/util.cljs @@ -35,12 +35,15 @@ (defn build-new-property "Build a standard new property so that it is is consistent across contexts" - [block] + [prop-name prop-schema prop-uuid] (block-with-timestamps - (merge {:block/type "property" - :block/journal? false - :block/format :markdown} - block))) + {:block/type "property" + :block/journal? false + :block/format :markdown + :block/uuid prop-uuid + :block/schema (merge {:type :default} prop-schema) + :block/original-name (name prop-name) + :block/name (common-util/page-name-sanity-lc (name prop-name))})) (defn build-new-class diff --git a/scripts/src/logseq/tasks/db_graph/create_graph.cljs b/scripts/src/logseq/tasks/db_graph/create_graph.cljs index feb466815..461ea7610 100644 --- a/scripts/src/logseq/tasks/db_graph/create_graph.cljs +++ b/scripts/src/logseq/tasks/db_graph/create_graph.cljs @@ -176,13 +176,13 @@ :property-attributes {:db/id (or (property-db-ids (name prop-name)) (throw (ex-info "No :db/id for property" {:property prop-name})))}}) - [(sqlite-util/build-new-property - (merge (db-property-util/new-property-tx prop-name (get-in properties [prop-name :block/schema]) uuid) - {:db/id (or (property-db-ids (name prop-name)) - (throw (ex-info "No :db/id for property" {:property prop-name})))} - (when-let [props (not-empty (get-in properties [prop-name :properties]))] - {:block/properties (->block-properties-tx props uuid-maps) - :block/refs (build-property-refs props property-db-ids)})))])) + [(merge + (sqlite-util/build-new-property prop-name (get-in properties [prop-name :block/schema]) uuid) + {:db/id (or (property-db-ids (name prop-name)) + (throw (ex-info "No :db/id for property" {:property prop-name})))} + (when-let [props (not-empty (get-in properties [prop-name :properties]))] + {:block/properties (->block-properties-tx props uuid-maps) + :block/refs (build-property-refs props property-db-ids)}))])) property-uuids)) pages-and-blocks-tx (vec diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index f1fa4ca5d..56ea096f8 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -105,12 +105,7 @@ :block/uuid property-uuid :block/type "property"})] {:outliner-op :save-block}) - (db/transact! repo [(sqlite-util/build-new-property - (cond-> {:block/original-name k-name - :block/name (util/page-name-sanity-lc k-name) - :block/uuid property-uuid} - (seq schema) - (assoc :block/schema schema)))] + (db/transact! repo [(sqlite-util/build-new-property k-name schema property-uuid)] {:outliner-op :insert-blocks})))) (defn validate-property-value