1
0
Эх сурвалжийг харах

Fix regression on configure page with properties

Was unable to add multiple page or schema properties. Caused by move to
select component which exited page modal by default
Gabriel Horner 2 жил өмнө
parent
commit
023a47562d

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

@@ -249,8 +249,7 @@
                                 editor-id dom-id row?
                                 editor-box editor-args
                                 editing? editing-atom
-                                blocks-container-id]
-                         :as opts}]
+                                blocks-container-id]}]
   (let [property (model/sub-block (:db/id property))
         multiple-values? (= :many (:cardinality (:block/schema property)))
         editor-id (or editor-id (str "ls-property-" blocks-container-id "-" (:db/id block) "-" (:db/id property)))
@@ -347,20 +346,24 @@
 (defn- add-property-from-dropdown
   "Adds an existing or new property from dropdown. Used from a block or page context.
    For pages, used to add both schema properties or properties for a page"
-  [entity property-name {:keys [class-schema? blocks-container-id]}]
+  [entity property-name {:keys [class-schema? blocks-container-id page-configure?]}]
   (let [repo (state/get-current-repo)]
+    ;; existing property selected or entered
     (if-let [property (get-property-from-db property-name)]
       (if (contains? gp-property/db-hidden-built-in-properties (keyword property-name))
         (do (notification/show! "This is a built-in property that can't be used." :error)
             (exit-edit-property))
         (if (= "class" (:block/type entity))
-          (add-property! entity property-name "" {:class-schema? class-schema?})
+          (add-property! entity property-name "" {:class-schema? class-schema?
+                                                  ;; Only enter property names from sub-modal as inputting
+                                                  ;; property values is buggy in sub-modal
+                                                  :exit-edit? page-configure?})
           (let [editor-id (str "ls-property-" blocks-container-id (:db/id entity) "-" (:db/id property))]
             (set-editing! property editor-id "" ""))))
-      ;; new property
+      ;; new property entered
       (if (gp-property/db-valid-property-name? property-name)
         (if (= "class" (:block/type entity))
-          (add-property! entity property-name "" {:class-schema? class-schema?})
+          (add-property! entity property-name "" {:class-schema? class-schema? :exit-edit? page-configure?})
           (do
             (db-property/upsert-property! repo property-name {:type :default} {})
             ;; configure new property
@@ -371,7 +374,7 @@
 
 (rum/defcs property-input < rum/reactive
   shortcut/disable-all-shortcuts
-  [state entity *property-key *property-value {:keys [class-schema?]
+  [state entity *property-key *property-value {:keys [class-schema? page-configure?]
                                                :as opts}]
   (let [entity-properties (->> (keys (:block/properties entity))
                                (map #(:block/original-name (db/entity [:block/uuid %])))
@@ -400,10 +403,10 @@
                        :dropdown? true
                        :show-new-when-not-exact-match? true
                        :exact-match-exclude-items exclude-properties
+                       :sub-modal? page-configure?
                        :input-default-placeholder "Add a property"
                        :on-chosen (fn [{:keys [value]}]
                                     (reset! *property-key value)
-                                    ;; property already exists?
                                     (add-property-from-dropdown entity value opts))})])))
 
 (rum/defcs new-property < rum/reactive

+ 13 - 3
src/main/frontend/components/select.cljs

@@ -31,7 +31,15 @@
        [:div.tip.flex
         [:code.opacity-20.bg-transparent (:id result)]])]))
 
-(rum/defcs select < rum/reactive
+(rum/defcs select
+  "Provides a select dropdown powered by a fuzzy search. Takes the following options:
+   * :items - Vec of things to select from. Assumes a vec of maps with :value key by default. Required option
+   * :limit - Limit number of items to search. Default is 100
+   * :extract-fn - Fn applied to each item when extracting a value from it. Default is :value
+   * :show-new-when-not-exact-match? - Boolean to allow new values be entered. Default is false
+   * :sub-modal? - Boolean to indicate if in a sub-modal. Useful for closing behavior
+   TODO: Describe more options"
+  < rum/reactive
   shortcut/disable-all-shortcuts
   (rum/local "" ::input)
   {:init (fn [state]
@@ -48,7 +56,8 @@
                  extract-fn host-opts on-input input-opts
                  item-cp transform-fn tap-*input-val
                  multiple-choices? on-apply _selected-choices
-                 dropdown? show-new-when-not-exact-match? exact-match-exclude-items]
+                 dropdown? show-new-when-not-exact-match? exact-match-exclude-items
+                 sub-modal?]
           :or {limit 100
                prompt-key :select/default-prompt
                empty-placeholder (fn [_t] [:div])
@@ -96,7 +105,8 @@
                                                        (swap! *selected-choices disj x)
                                                        (swap! *selected-choices conj x))
                                                      (do
-                                                       (when close-modal? (state/close-modal!))
+                                                       (when close-modal?
+                                                         (if sub-modal? (state/close-sub-modal!) (state/close-modal!)))
                                                        (when on-chosen
                                                          (on-chosen (if multiple-choices? @*selected-choices x))))))
                               :empty-placeholder (empty-placeholder t)})]