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

fix: remove existing properties/alias/tags from auto-complete

Tienson Qin 2 лет назад
Родитель
Сommit
a775746d97

+ 13 - 4
src/main/frontend/components/property.cljs

@@ -356,11 +356,19 @@
   (let [entity-properties (->> (keys (:block/properties entity))
                                (map #(:block/original-name (db/entity [:block/uuid %])))
                                (set))
+        existing-tag-alias (cond-> #{}
+                             (seq (:block/tags entity))
+                             (conj "tags")
+                             (seq (:block/alias entity))
+                             (conj "alias"))
+        exclude-properties (set/union
+                            entity-properties
+                            existing-tag-alias
+                            (->> gp-property/db-hidden-built-in-properties
+                                 (map name)
+                                 set))
         properties (->> (search/get-all-properties)
-                        (remove entity-properties)
-                        (remove (->> gp-property/db-hidden-built-in-properties
-                                     (map name)
-                                     set)))]
+                        (remove exclude-properties))]
     (if @*property-key
       (let [property (get-property-from-db @*property-key)]
         [:div.ls-property-add.grid.grid-cols-4.gap-1.flex.flex-row.items-center
@@ -375,6 +383,7 @@
        (select/select {:items (map (fn [x] {:value x}) properties)
                        :dropdown? true
                        :show-new-when-not-exact-match? true
+                       :exact-match-exclude-items exclude-properties
                        :input-default-placeholder "Add a property"
                        :on-chosen (fn [{:keys [value]}]
                                     (reset! *property-key value)

+ 7 - 4
src/main/frontend/components/select.cljs

@@ -48,12 +48,13 @@
                  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?]
+                 dropdown? show-new-when-not-exact-match? exact-match-exclude-items]
           :or {limit 100
                prompt-key :select/default-prompt
                empty-placeholder (fn [_t] [:div])
                close-modal? true
-               extract-fn :value}}]
+               extract-fn :value
+               exact-match-exclude-items #{}}}]
   (let [input (::input state)
         *selected-choices (::selected-choices state)
         search-result' (->>
@@ -63,8 +64,10 @@
                         (remove nil?))
         exact-match? (contains? (set (map (comp string/lower-case extract-fn) search-result'))
                                 (string/lower-case @input))
-        search-result (if (and show-new-when-not-exact-match? (not exact-match?)
-                               (not (string/blank? @input)))
+        search-result (if (and show-new-when-not-exact-match?
+                               (not exact-match?)
+                               (not (string/blank? @input))
+                               (not (exact-match-exclude-items @input)))
                         (cons {:value @input} search-result')
                         search-result')
         input-opts' (if (fn? input-opts) (input-opts (empty? search-result)) input-opts)