mirror of
https://github.com/penpot/penpot.git
synced 2025-03-29 08:01:41 -05:00
🐛 Fix backend shape validation after changes apply
This commit is contained in:
parent
390f2b35fc
commit
8ca6055935
1 changed files with 21 additions and 18 deletions
|
@ -240,25 +240,28 @@
|
||||||
;; Changes Processing Impl
|
;; Changes Processing Impl
|
||||||
|
|
||||||
(defn validate-shapes!
|
(defn validate-shapes!
|
||||||
[data objects items]
|
[data-old data-new items]
|
||||||
(letfn [(validate-shape! [[page-id {:keys [id] :as shape}]]
|
(letfn [(validate-shape! [[page-id id]]
|
||||||
(when-not (= shape (dm/get-in data [:pages-index page-id :objects id]))
|
(let [shape-old (dm/get-in data-old [:pages-index page-id :objects id])
|
||||||
;; If object has changed verify is correct
|
shape-new (dm/get-in data-new [:pages-index page-id :objects id])]
|
||||||
(dm/verify! (cts/shape? shape))))]
|
|
||||||
|
|
||||||
(let [lookup (d/getf objects)]
|
;; If object has changed verify is correct
|
||||||
(->> (into #{} (map :page-id) items)
|
(when (and (some? shape-old)
|
||||||
(mapcat (fn [page-id]
|
(some? shape-new)
|
||||||
(filter #(= page-id (:page-id %)) items)))
|
(not= shape-old shape-new))
|
||||||
(mapcat (fn [{:keys [type id page-id] :as item}]
|
(dm/verify! (cts/shape? shape-new)))))]
|
||||||
(sequence
|
|
||||||
(comp (keep lookup)
|
(->> (into #{} (map :page-id) items)
|
||||||
(map (partial vector page-id)))
|
(mapcat (fn [page-id]
|
||||||
(case type
|
(filter #(= page-id (:page-id %)) items)))
|
||||||
(:add-obj :mod-obj :del-obj) (cons id nil)
|
(mapcat (fn [{:keys [type id page-id] :as item}]
|
||||||
(:mov-objects :reg-objects) (:shapes item)
|
(sequence
|
||||||
nil))))
|
(map (partial vector page-id))
|
||||||
(run! validate-shape!)))))
|
(case type
|
||||||
|
(:add-obj :mod-obj :del-obj) (cons id nil)
|
||||||
|
(:mov-objects :reg-objects) (:shapes item)
|
||||||
|
nil))))
|
||||||
|
(run! validate-shape!))))
|
||||||
|
|
||||||
(defmulti process-change (fn [_ change] (:type change)))
|
(defmulti process-change (fn [_ change] (:type change)))
|
||||||
(defmulti process-operation (fn [_ _ op] (:type op)))
|
(defmulti process-operation (fn [_ _ op] (:type op)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue