diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index c7b8235ac7..53fe58d8bf 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -7,7 +7,7 @@ [frontend.config :as config] [frontend.db :as db] [frontend.db-mixins :as db-mixins] - [frontend.db.model :as db-model] + [frontend.db.model :as model] [frontend.handler.db-based.property :as db-property-handler] [frontend.handler.notification :as notification] [frontend.handler.property :as property-handler] @@ -58,7 +58,7 @@ [:a.text-sm (str "#" page-name)]))))] [:div.opacity-50.pointer.text-sm "Empty"])]) (fn [{:keys [toggle-fn]}] - (let [classes (db-model/get-all-classes (state/get-current-repo)) + (let [classes (model/get-all-classes (state/get-current-repo)) options (cond->> (map (fn [[name id]] {:label name :value id}) classes) @@ -173,14 +173,17 @@ :disabled disabled? :value type :selected (= type (:type @*property-schema))})))] - [:div.col-span-2 - (if property-type - (property-type-label property-type) + (if (and property-type + (seq (model/get-block-property-values (:block/uuid property)))) + [:div.col-span-2 + {:title "Type can only edited if property is not used anywhere"} + (property-type-label property-type)] + [:div.col-span-2 (ui/select schema-types (fn [_e v] (let [type (keyword (string/lower-case v))] (swap! *property-schema assoc :type type) - (components-pu/update-property! property @*property-name @*property-schema)))))])] + (components-pu/update-property! property @*property-name @*property-schema))))]))] (case (:type @*property-schema) :page diff --git a/src/main/frontend/handler/common/page.cljs b/src/main/frontend/handler/common/page.cljs index 1103599380..df0964193b 100644 --- a/src/main/frontend/handler/common/page.cljs +++ b/src/main/frontend/handler/common/page.cljs @@ -279,9 +279,7 @@ (contains? (:block/type page) "property") (cond (seq (model/get-classes-with-property (:block/uuid page))) {:msg "Page content deleted but unable to delete this page because classes use this property"} - (->> (model/get-block-property-values (:block/uuid page)) - (filter (fn [[_ v]] (if (seq? v) (seq v) (some? v)))) - seq) + (seq (model/get-block-property-values (:block/uuid page))) {:msg "Page content deleted but unable to delete this page because blocks use this property"}) (or (seq (:block/_refs page)) (contains? (:block/type page) "hidden")) diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index f660a75abb..5024ac5fc9 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -249,8 +249,11 @@ properties]}] {:pre [(uuid? property-uuid)]} (when-let [property (db/entity [:block/uuid property-uuid])] - (let [type (get-in property [:block/schema :type])] - (when-not (and type (:type property-schema) (not= type (:type property-schema))) ; property type changed + (let [type (get-in property [:block/schema :type]) + type-changed? (and type (:type property-schema) (not= type (:type property-schema)))] + (when (or (not type-changed?) + ;; only change type if property hasn't been used yet + (empty? (model/get-block-property-values property-uuid))) (when (and (= :many (:cardinality property-schema)) (not= :many (:cardinality (:block/schema property)))) ;; cardinality changed from :one to :many diff --git a/src/test/frontend/db/rtc/op_mem_layer_test.cljs b/src/test/frontend/db/rtc/op_mem_layer_test.cljs index 76f53a3910..7419f5b650 100644 --- a/src/test/frontend/db/rtc/op_mem_layer_test.cljs +++ b/src/test/frontend/db/rtc/op_mem_layer_test.cljs @@ -51,7 +51,7 @@ :updated-attrs {:content nil}}] ["update" {:block-uuid "f639f13e-ef6f-4ba5-83b4-67527d27cd02" :epoch 4 :updated-attrs {:content nil :link nil}}]] - {:keys [block-uuid->ops epoch->block-uuid-sorted-map]} + {:keys [block-uuid->ops]} (op-layer/add-ops-to-block-uuid->ops (op-layer/ops-coercer ops) {} (sorted-map-by <))] (is (= ["update" {:block-uuid #uuid "f639f13e-ef6f-4ba5-83b4-67527d27cd02"