Skip to content

Commit

Permalink
update property edit
Browse files Browse the repository at this point in the history
  • Loading branch information
RCmerci committed Jun 20, 2023
1 parent d22ff99 commit 7a6972b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
(:block/page block) 1
(:block/name block) 2
(:file/content block) 3
(= :property (:block/type block)) 6
(= "property" (:block/type block)) 6
:else 5))

(defmethod handle :db-transact-data [_window [_ repo data-str]]
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2879,8 +2879,9 @@

(when @*show-right-menu?
(block-right-menu config block edit?))]

(when (config/db-based-graph? repo)
(property-component/properties-area block (:block/properties block)))
(property-component/properties-area block (:block/properties block)))

(block-children config block children collapsed?)

Expand Down
30 changes: 20 additions & 10 deletions src/main/frontend/components/property.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -222,25 +222,35 @@
;; (properties-area entity properties refs-properties' block-components-m)))

(rum/defcs properties-area <
rum/static
(rum/local nil ::new-property)
rum/reactive
[state block properties]
(rum/local nil ::properties)
{:will-mount (fn [state]
(reset! (::properties state) (second (:rum/args state)))
state)}
[state block _properties]
(let [*new-property (::new-property state)
*properties (::properties state)
repo (state/get-current-repo)]
[:div.ls-properties-area.pl-6
(when (seq properties)
(prn :properties properties)
(when (seq @*properties)
[:div
(for [[prop-uuid-or-built-in-prop v] properties]
(if (uuid? prop-uuid-or-built-in-prop)
(when-let [property-class (db/pull [:block/uuid prop-uuid-or-built-in-prop])]
(for [[prop-uuid-or-built-in-prop v] @*properties]
(if (and (string? prop-uuid-or-built-in-prop)
(util/uuid-string? prop-uuid-or-built-in-prop))
(when-let [property-class (db/pull [:block/uuid (uuid prop-uuid-or-built-in-prop)])]
[:div
[:a.mr-2 (:property/name property-class)]
[:input {:value v}]])
[:span v]
[:a.ml-8 {:on-click
(fn []
(property-handler/remove-property! repo block prop-uuid-or-built-in-prop)
(reset! *properties (:block/properties (db/pull [:block/uuid (:block/uuid block)]))))}
"DEL"]])
;; builtin
[:div
[:a.mr-2 (str prop-uuid-or-built-in-prop)]
[:input {:value v}]]))])
[:span v]]))])
(if (nil? @*new-property)
[:a {:title "Add another value"
:on-click (fn [] (reset! *new-property {}))}
Expand All @@ -251,7 +261,7 @@
[:input.block-properties {:on-change #(swap! *new-property assoc :v (util/evalue %))}]
[:a {:on-click (fn []
(when (and (:k @*new-property) (:k @*new-property))
(prn :*new-property @*new-property)
(property-handler/add-property! repo block (:k @*new-property) (:v @*new-property))
(reset! *properties (:block/properties (db/pull [:block/uuid (:block/uuid block)])))
(reset! *new-property nil)))}
"Save"]])]))

0 comments on commit 7a6972b

Please sign in to comment.