fix: remove existing properties when auto-complete property key

This commit is contained in:
Tienson Qin
2023-07-03 12:19:46 +08:00
parent e0028a39fa
commit 72913c7e62
3 changed files with 17 additions and 9 deletions

View File

@@ -101,8 +101,12 @@
shortcut/disable-all-shortcuts
[state entity *property-key *property-value]
(let [*search? (::search? state)
entity-properties (->> (keys (:block/properties entity))
(map #(:block/original-name (db/entity [:block/uuid %])))
(set))
result (when-not (string/blank? @*property-key)
(search/property-search @*property-key))]
(->> (search/property-search @*property-key)
(remove entity-properties)))]
[:div
[:div.ls-property-add.grid.grid-cols-4.gap-1.flex.flex-row.items-center
[:input#add-property.form-input.simple-input.block.col-span-1.focus:outline-none
@@ -117,15 +121,17 @@
"Escape"
(exit-edit-property *property-key *property-value)
"Enter"
(list "Tab" "Enter")
(do
(util/stop e)
(reset! *search? false)
(.focus (js/document.getElementById "add-property-value")))
nil))}]
[:input#add-property-value.block-properties
{:on-change #(reset! *property-value (util/evalue %))
[:input#add-property-value.form-input.simple-input.block.col-span-1.focus:outline-none
{:placeholder "Value"
:on-change #(reset! *property-value (util/evalue %))
:on-key-down (fn [e]
(case (util/ekey e)
"Enter"

View File

@@ -1171,7 +1171,7 @@ independent of format as format specific heading characters are stripped"
distinct
(map (fn [k]
(if (uuid? k)
(keyword (:block/name (d/entity db [:block/uuid k])))
(:block/original-name (d/entity db [:block/uuid k]))
k)))
sort)))

View File

@@ -163,10 +163,12 @@
;; cardinality changed from :one to :many
(fix-cardinality-many-values! property-uuid))
(let [tx-data (cond-> {:block/uuid property-uuid}
property-name (assoc :block/name property-name)
property-schema (assoc :block/schema property-schema)
true outliner-core/block-with-updated-at)]
(db/transact! repo [tx-data]))))
property-name (merge
{:block/original-name property-name
:block/name (gp-util/page-name-sanity-lc property-name)})
property-schema (assoc :block/schema property-schema)
true outliner-core/block-with-updated-at)]
(db/transact! repo [tx-data]))))
(defn delete-property-value!
"Delete value if a property has multiple values"