Browse Source

chore: remove unused vars in property.type

We used to use these vars when :block/schema contained cardinality and
classes
Gabriel Horner 1 year ago
parent
commit
3bc6a27173

+ 0 - 1
deps/db/.carve/config.edn

@@ -1,6 +1,5 @@
 {:paths ["src"]
  :api-namespaces [logseq.db.sqlite.common-db
-                  logseq.db.sqlite.rtc
                   logseq.db.sqlite.util
                   logseq.db.sqlite.cli
                   logseq.db.frontend.property

+ 4 - 10
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -257,14 +257,11 @@
     page-attrs
     page-or-block-attrs)))
 
-(def property-type-schema-attrs
-  "Property :schema attributes that vary by :type"
-  [;; For closed values
-   [:position {:optional true} [:enum :properties :block-left :block-right :block-below]]])
 
 (def property-common-schema-attrs
   "Property :schema attributes common to all properties"
-  [[:hide? {:optional true} :boolean]])
+  [[:hide? {:optional true} :boolean]
+   [:position {:optional true} [:enum :properties :block-left :block-right :block-below]]])
 
 (def internal-property
   (vec
@@ -280,8 +277,7 @@
          [:public? {:optional true} :boolean]
          [:view-context {:optional true} [:enum :page :block]]
          [:shortcut {:optional true} :string]]
-        property-common-schema-attrs
-        property-type-schema-attrs))]]
+        property-common-schema-attrs))]]
     property-attrs
     page-attrs
     page-or-block-attrs)))
@@ -297,9 +293,7 @@
          [:map
           ;; Once a schema is defined it must have :type as this is an irreversible decision
           [:type :keyword]]
-         property-common-schema-attrs
-         (remove #(not (db-property-type/property-type-allows-schema-attribute? prop-type (first %)))
-                 property-type-schema-attrs)))])
+         property-common-schema-attrs))])
     db-property-type/user-built-in-property-types)))
 
 (def user-property

+ 1 - 25
deps/db/src/logseq/db/frontend/property/type.cljs

@@ -32,10 +32,6 @@
 (assert (set/subset? closed-value-property-types (set user-built-in-property-types))
         "All closed value types are valid property types")
 
-(def position-property-types
-  "Valid property :type for position"
-  #{:default :number :date :checkbox :url :node})
-
 (def original-value-ref-property-types
   "Property value ref types where the refed entity stores its value in
   :property.value/content e.g. :number is stored as a number. new value-ref-property-types
@@ -58,20 +54,6 @@
                      (set user-built-in-property-types))
         "All ref types are valid property types")
 
-(def ^:private user-built-in-allowed-schema-attributes
-  "Map of types to their set of allowed :schema attributes"
-  (merge-with into
-              (zipmap closed-value-property-types (repeat #{:values}))
-              (zipmap position-property-types (repeat #{:position}))
-              {:default #{:cardinality}
-               :number #{:cardinality}
-               :date #{:cardinality}
-               :url #{:cardinality}
-               :node #{:cardinality :classes}
-               :checkbox #{}}))
-
-(assert (= (set user-built-in-property-types) (set (keys user-built-in-allowed-schema-attributes)))
-        "Each user built in type should have an allowed schema attribute")
 
 ;; Property value validation
 ;; =========================
@@ -171,12 +153,6 @@
 
 ;; Helper fns
 ;; ==========
-(defn property-type-allows-schema-attribute?
-  "Returns boolean to indicate if property type allows the given :schema attribute"
-  [property-type schema-attribute]
-  (contains? (get user-built-in-allowed-schema-attributes property-type)
-             schema-attribute))
-
 (defn infer-property-type-from-value
   "Infers a user defined built-in :type from property value(s)"
   [val]
@@ -184,4 +160,4 @@
     (number? val) :number
     (url? val) :url
     (contains? #{true false} val) :checkbox
-    :else :default))
+    :else :default))

+ 1 - 1
scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs

@@ -166,7 +166,7 @@
                              [[% {:block/schema {:type %} :build/schema-classes [:TestClass]}]
                               [:node-without-classes {:block/schema {:type %}}]]
                              [[% {:block/schema {:type %}}]])
-                     (db-property-type/property-type-allows-schema-attribute? % :cardinality)
+                     (contains? db-property-type/cardinality-property-types %)
                      (conj [(keyword (str (name %) "-many"))
                             (cond-> {:block/schema {:type % :cardinality :many}}
                               (= :node %)

+ 11 - 16
src/main/frontend/components/property.cljs

@@ -71,6 +71,7 @@
             (db/entity (:db/id result))))
         (notification/show! "This is an invalid property name. A property name cannot start with page reference characters '#' or '[['." :error)))))
 
+;; TODO: This component should be cleaned up as it's only used for new properties and used to be used for existing properties
 (rum/defcs property-type-select <
   shortcut/disable-all-shortcuts
   [state property {:keys [*property *property-name *property-schema built-in? disabled?
@@ -94,13 +95,7 @@
         :on-value-change
         (fn [v]
           (let [type (keyword (string/lower-case v))
-                update-schema-fn (apply comp
-                                        #(assoc % :type type)
-                                        (keep
-                                         (fn [attr]
-                                           (when-not (db-property-type/property-type-allows-schema-attribute? type attr)
-                                             #(dissoc % attr)))
-                                         [:cardinality :position]))]
+                update-schema-fn #(assoc % :type type)]
             (when *property-schema
               (swap! *property-schema update-schema-fn))
             (let [schema (or (and *property-schema @*property-schema)
@@ -244,17 +239,17 @@
                             (fn [_e icon]
                               (if icon
                                 (db-property-handler/upsert-property! (:db/ident property)
-                                  (:block/schema property)
-                                  {:properties {:logseq.property/icon icon}})
+                                                                      (:block/schema property)
+                                                                      {:properties {:logseq.property/icon icon}})
                                 (db-property-handler/remove-block-property! (:db/id property)
-                                  (pu/get-pid :logseq.property/icon)))
+                                                                            (pu/get-pid :logseq.property/icon)))
                               (shui/popup-hide! id))
                             :del-btn? (boolean icon)}))]
 
          (shui/trigger-as
-           :button
-           (-> (when-not config/publishing?
-                 {:on-click (fn [^js e]
+          :button
+          (-> (when-not config/publishing?
+                {:on-click (fn [^js e]
                              (shui/popup-show! (.-target e) content-fn
                                                {:as-dropdown? true :auto-focus? true
                                                 :content-props {:onEscapeKeyDown #(.preventDefault %)}}))})
@@ -423,9 +418,9 @@
             date? (= type :date)
             checkbox? (= type :checkbox)
             property-key-cp' (property-key-cp block property (assoc (select-keys opts [:class-schema?])
-                                                           :block? block?
-                                                           :inline-text inline-text
-                                                           :page-cp page-cp))]
+                                                                    :block? block?
+                                                                    :inline-text inline-text
+                                                                    :page-cp page-cp))]
         [:div {:class (cond
                         (or date? checkbox?)
                         "property-pair items-center"