Просмотр исходного кода

fix: property value search for file graphs

Looks like this was introduced with move to db.async
Gabriel Horner 2 лет назад
Родитель
Сommit
ec916de768
2 измененных файлов с 22 добавлено и 14 удалено
  1. 20 12
      src/main/frontend/components/editor.cljs
  2. 2 2
      src/main/frontend/search.cljs

+ 20 - 12
src/main/frontend/components/editor.cljs

@@ -343,6 +343,24 @@
             :item-render (fn [property] property)
             :class       "black"}))))))
 
+(rum/defc property-value-search-aux
+  [id property q]
+  (let [[values set-values!] (rum/use-state nil)]
+    (rum/use-effect!
+     (fn []
+       (p/let [result (editor-handler/get-matched-property-values property q)]
+         (set-values! result)))
+     [property q])
+    (ui/auto-complete
+         values
+         {:on-chosen (editor-handler/property-value-on-chosen-handler id q)
+          :on-enter (fn [_state]
+                      ((editor-handler/property-value-on-chosen-handler id q) nil))
+          :empty-placeholder [:div.px-4.py-2.text-sm (str "Create a new property value: " q)]
+          :header [:div.px-4.py-2.text-sm.font-medium "Matched property values: "]
+          :item-render (fn [property-value] property-value)
+          :class       "black"})))
+
 (rum/defc property-value-search < rum/reactive
   [id]
   (let [property (:property (state/get-editor-action-data))
@@ -357,18 +375,8 @@
                (when (>= current-pos (+ start-idx 2))
                  (subs edit-content (+ start-idx 2) current-pos))
                "")
-            q (string/triml q)
-            matched-values (editor-handler/get-matched-property-values property q)
-            non-exist-handler (fn [_state]
-                                ((editor-handler/property-value-on-chosen-handler id q) nil))]
-        (ui/auto-complete
-         matched-values
-         {:on-chosen (editor-handler/property-value-on-chosen-handler id q)
-          :on-enter non-exist-handler
-          :empty-placeholder [:div.px-4.py-2.text-sm (str "Create a new property value: " q)]
-          :header [:div.px-4.py-2.text-sm.font-medium "Matched property values: "]
-          :item-render (fn [property-value] property-value)
-          :class       "black"})))))
+            q (string/triml q)]
+        (property-value-search-aux id property q)))))
 
 (rum/defc code-block-mode-keyup-listener
   [_q _edit-content last-pos current-pos]

+ 2 - 2
src/main/frontend/search.cljs

@@ -96,8 +96,8 @@
   ([property q limit]
    (when-let [repo (state/get-current-repo)]
      (when q
-      (let [q (fuzzy/clean-str q)
-            result (db-async/<get-property-values repo (keyword property))]
+      (p/let [q (fuzzy/clean-str q)
+              result (db-async/<get-property-values repo (keyword property))]
         (when (seq result)
           (if (string/blank? q)
             result