mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 16:30:37 -05:00
Revert "Revert "🐛 Add validator and repair for duplicated slots""
This reverts commit e0906be6e7
.
This commit is contained in:
parent
e0906be6e7
commit
4546e98dc6
2 changed files with 38 additions and 0 deletions
|
@ -473,6 +473,29 @@
|
|||
(pcb/with-file-data file-data)
|
||||
(pcb/update-shapes [(:id shape)] repair-shape))))
|
||||
|
||||
(defmethod repair-error :duplicate-slot
|
||||
[_ {:keys [shape page-id] :as error} file-data _]
|
||||
(let [page (ctpl/get-page file-data page-id)
|
||||
childs (map #(get (:objects page) %) (:shapes shape))
|
||||
child-with-duplicate (let [result (reduce (fn [[seen duplicates] item]
|
||||
(let [swap-slot (ctk/get-swap-slot item)]
|
||||
(if (contains? seen swap-slot)
|
||||
[seen (conj duplicates item)]
|
||||
[(conj seen swap-slot) duplicates])))
|
||||
[#{} []]
|
||||
childs)]
|
||||
(second result))
|
||||
repair-shape
|
||||
(fn [shape]
|
||||
;; Remove the swap slot
|
||||
(log/debug :hint " -> remove swap-slot" :child-id (:id shape))
|
||||
(ctk/remove-swap-slot shape))]
|
||||
|
||||
(log/dbg :hint "repairing shape :duplicated-slot" :id (:id shape) :name (:name shape) :page-id page-id)
|
||||
(-> (pcb/empty-changes nil page-id)
|
||||
(pcb/with-file-data file-data)
|
||||
(pcb/update-shapes (map :id child-with-duplicate) repair-shape))))
|
||||
|
||||
(defmethod repair-error :missing-slot
|
||||
[_ {:keys [shape page-id args] :as error} file-data _]
|
||||
(let [repair-shape
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
:component-not-main
|
||||
:component-main-external
|
||||
:component-not-found
|
||||
:duplicate-slot
|
||||
:invalid-main-instance-id
|
||||
:invalid-main-instance-page
|
||||
:invalid-main-instance
|
||||
|
@ -296,6 +297,18 @@
|
|||
"This shape should not have swap slot"
|
||||
shape file page)))
|
||||
|
||||
(defn- check-duplicate-swap-slot
|
||||
"Validate that the children of this shape does not have duplicated slots."
|
||||
[shape file page]
|
||||
(let [shapes (map #(get (:objects page) %) (:shapes shape))
|
||||
slots (->> (map #(ctk/get-swap-slot %) shapes)
|
||||
(remove nil?))
|
||||
counts (frequencies slots)]
|
||||
(when (some (fn [[_ count]] (> count 1)) counts)
|
||||
(report-error :duplicate-slot
|
||||
"This shape has children with the same swap slot"
|
||||
shape file page))))
|
||||
|
||||
(defn- check-shape-main-root-top
|
||||
"Root shape of a top main instance:
|
||||
|
||||
|
@ -308,6 +321,7 @@
|
|||
(check-component-root shape file page)
|
||||
(check-component-not-ref shape file page)
|
||||
(check-empty-swap-slot shape file page)
|
||||
(check-duplicate-swap-slot shape file page)
|
||||
(run! #(check-shape % file page libraries :context :main-top) (:shapes shape)))
|
||||
|
||||
(defn- check-shape-main-root-nested
|
||||
|
@ -335,6 +349,7 @@
|
|||
(check-component-root shape file page)
|
||||
(check-component-ref shape file page libraries)
|
||||
(check-empty-swap-slot shape file page)
|
||||
(check-duplicate-swap-slot shape file page)
|
||||
(run! #(check-shape % file page libraries :context :copy-top :library-exists library-exists) (:shapes shape))))
|
||||
|
||||
(defn- check-shape-copy-root-nested
|
||||
|
|
Loading…
Reference in a new issue