Browse Source

enhance: display enum icon in block's title only if it has a value

Tienson Qin 2 years ago
parent
commit
38c96018b5

+ 2 - 2
src/main/frontend/components/property.cljs

@@ -752,7 +752,7 @@
                         (if one-class?
                           (concat block-own-properties' class-own-properties)
                           block-own-properties')
-                        (remove (fn [[id _]] (property-handler/enum-other-position? id))))
+                        (remove (fn [[id _]] (property-handler/enum-other-position? id block-properties))))
         full-hidden-properties (concat block-hidden-properties class-hidden-properties)
         new-property? (= edit-input-id (state/sub :ui/new-property-input-id))
         class->properties (loop [classes all-classes
@@ -762,7 +762,7 @@
                               (let [cur-properties (->> (:properties (:block/schema class))
                                                         (remove properties)
                                                         (remove hide-with-property-id)
-                                                        (remove property-handler/enum-other-position?))]
+                                                        (remove (fn [id] (property-handler/enum-other-position? id block-properties))))]
                                 (recur (rest classes)
                                        (set/union properties (set cur-properties))
                                        (conj result [class cur-properties])))

+ 7 - 5
src/main/frontend/handler/property.cljs

@@ -131,10 +131,12 @@
      :classes-properties all-properties}))
 
 (defn enum-other-position?
-  [property-id]
-  (let [schema (:block/schema (db/entity [:block/uuid property-id]))]
-    (and (= :enum (:type schema))
-         (not= (:position schema) "properties"))))
+  [property-id block-properties]
+  (and
+   (some? (get block-properties property-id))
+   (let [schema (:block/schema (db/entity [:block/uuid property-id]))]
+     (and (= :enum (:type schema))
+          (not= (:position schema) "properties")))))
 
 (defn get-block-enum-other-position-properties
   [eid]
@@ -142,5 +144,5 @@
         own-properties (keys (:block/properties block))]
     (->> (:classes-properties (get-block-classes-properties eid))
          (concat own-properties)
-         (filter (fn [id] (enum-other-position? id)))
+         (filter (fn [id] (enum-other-position? id (:block/properties block))))
          (distinct))))