0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-18 10:41:29 -05:00

🐛 Add undo to set default grid options operation

This commit is contained in:
Andrés Moya 2020-06-10 14:14:51 +02:00 committed by Andrey Antukh
parent 51acd2b529
commit f63657509f
4 changed files with 36 additions and 11 deletions

View file

@ -36,7 +36,14 @@
res (cp/process-changes data chgs)]
(t/is (= {:a "a" :b "b"} (get-in res [:options :values :test])))))
(t/testing "Remove option"
(t/testing "Remove option single"
(let [chg {:type :set-option
:option :test
:value nil}
res (cp/process-changes data [chg])]
(t/is (empty? (keys (get res :options))))))
(t/testing "Remove option nested 1"
(let [chgs [{:type :set-option
:option [:values :test :a]
:value "a"}
@ -47,7 +54,20 @@
:option [:values :test]
:value nil}]
res (cp/process-changes data chgs)]
(t/is (= nil (get-in res [:options :values :test])))))))
(t/is (empty? (keys (get res :options))))))
(t/testing "Remove option nested 2"
(let [chgs [{:type :set-option
:option [:values :test1 :a]
:value "a"}
{:type :set-option
:option [:values :test2 :b]
:value "b"}
{:type :set-option
:option [:values :test2]
:value nil}]
res (cp/process-changes data chgs)]
(t/is (= [:test1] (keys (get-in res [:options :values]))))))))
(t/deftest process-change-add-obj
(let [data cp/default-page-data

View file

@ -407,8 +407,9 @@
(defmethod process-change :set-option
[data {:keys [option value]}]
(let [path (if (seqable? option) option [option])]
(-> data
(assoc-in (into [:options] path) value))))
(if value
(assoc-in data (into [:options] path) value)
(assoc data :options (d/dissoc-in (:options data) path)))))
(defmethod process-change :add-obj
[data {:keys [id obj frame-id parent-id index] :as change}]

View file

@ -649,8 +649,6 @@
:left (gpt/point (- 1) 0)
:right (gpt/point 1 0)))
(s/def ::loc #{:up :down :bottom :top})
;; --- Delete Selected
(defn- delete-shapes
[ids]
@ -724,6 +722,8 @@
;; --- Shape Vertical Ordering
(s/def ::loc #{:up :down :bottom :top})
(defn vertical-order-selected
[loc]
(us/verify ::loc loc)

View file

@ -76,8 +76,12 @@
(ptk/reify ::set-default-grid
ptk/WatchEvent
(watch [_ state stream]
(rx/of (dwc/commit-changes [{:type :set-option
:option [:saved-grids type]
:value params}]
[]
{:commit-local? true})))))
(let [pid (:current-page-id state)
prev-value (get-in state [:workspace-data pid :options :saved-grids type])]
(rx/of (dwc/commit-changes [{:type :set-option
:option [:saved-grids type]
:value params}]
[{:type :set-option
:option [:saved-grids type]
:value prev-value}]
{:commit-local? true}))))))