fix: Page property autocomplete not filtering

fixes LOG-3203
This commit is contained in:
Tienson Qin
2025-02-20 21:12:42 +08:00
parent 3ceb147451
commit 32f56f016b

View File

@@ -372,26 +372,30 @@
(rum/defc property-search
[id]
(let [input (gdom/getElement id)
[matched-properties set-matched-properties!] (rum/use-state nil)]
[matched-properties set-matched-properties!] (rum/use-state nil)
[q set-q!] (rum/use-state "")]
(when input
(let [q (or (:searching-property (editor-handler/get-searching-property input))
"")]
(hooks/use-effect!
(fn []
(p/let [matched-properties (editor-handler/<get-matched-properties q)]
(set-matched-properties! matched-properties)))
[q])
(let [q-property (string/replace (string/lower-case q) #"\s+" "-")
non-exist-handler (fn [_state]
((editor-handler/property-on-chosen-handler id q-property) nil))]
(ui/auto-complete
matched-properties
{:on-chosen (editor-handler/property-on-chosen-handler id q-property)
:on-enter non-exist-handler
:empty-placeholder [:div.px-4.py-2.text-sm (str "Create a new property: " q-property)]
:header [:div.px-4.py-2.text-sm.font-medium "Matched properties: "]
:item-render (fn [property] property)
:class "black"}))))))
(hooks/use-effect!
(fn []
(.addEventListener input "input" (fn [_e]
(set-q! (or (:searching-property (editor-handler/get-searching-property input)) "")))))
[])
(hooks/use-effect!
(fn []
(p/let [matched-properties (editor-handler/<get-matched-properties q)]
(set-matched-properties! matched-properties)))
[q])
(let [q-property (string/replace (string/lower-case q) #"\s+" "-")
non-exist-handler (fn [_state]
((editor-handler/property-on-chosen-handler id q-property) nil))]
(ui/auto-complete
matched-properties
{:on-chosen (editor-handler/property-on-chosen-handler id q-property)
:on-enter non-exist-handler
:empty-placeholder [:div.px-4.py-2.text-sm (str "Create a new property: " q-property)]
:header [:div.px-4.py-2.text-sm.font-medium "Matched properties: "]
:item-render (fn [property] property)
:class "black"})))))
(rum/defc property-value-search-aux
[id property q]