mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
🔧 Validate components with unneeded objects
This commit is contained in:
@@ -1766,6 +1766,17 @@
|
|||||||
(update :pages-index d/update-vals update-container)
|
(update :pages-index d/update-vals update-container)
|
||||||
(d/update-when :components d/update-vals update-container))))
|
(d/update-when :components d/update-vals update-container))))
|
||||||
|
|
||||||
|
(defmethod migrate-data "0017-remove-unneeded-objects-from-components"
|
||||||
|
[data _]
|
||||||
|
;; Some components have an `:objects` attribute, despite not being
|
||||||
|
;; deleted. This migration removes it.
|
||||||
|
(letfn [(check-component [component]
|
||||||
|
(if (and (not (:deleted component))
|
||||||
|
(contains? component :objects))
|
||||||
|
(dissoc component :objects)
|
||||||
|
component))]
|
||||||
|
(d/update-when data :components check-component)))
|
||||||
|
|
||||||
(def available-migrations
|
(def available-migrations
|
||||||
(into (d/ordered-set)
|
(into (d/ordered-set)
|
||||||
["legacy-2"
|
["legacy-2"
|
||||||
|
|||||||
@@ -499,7 +499,7 @@
|
|||||||
(pcb/update-shapes [(:id shape)] repair-shape))))
|
(pcb/update-shapes [(:id shape)] repair-shape))))
|
||||||
|
|
||||||
(defmethod repair-error :component-nil-objects-not-allowed
|
(defmethod repair-error :component-nil-objects-not-allowed
|
||||||
[_ {:keys [shape] :as error} file-data _]
|
[_ {component :shape} file-data _] ; in this error the :shape argument is the component
|
||||||
(let [repair-component
|
(let [repair-component
|
||||||
(fn [component]
|
(fn [component]
|
||||||
; Remove the objects key, or set it to {} if the component is deleted
|
; Remove the objects key, or set it to {} if the component is deleted
|
||||||
@@ -511,10 +511,26 @@
|
|||||||
(log/debug :hint " -> remove :objects")
|
(log/debug :hint " -> remove :objects")
|
||||||
(dissoc component :objects))))]
|
(dissoc component :objects))))]
|
||||||
|
|
||||||
(log/dbg :hint "repairing component :component-nil-objects-not-allowed" :id (:id shape) :name (:name shape))
|
(log/dbg :hint "repairing component :component-nil-objects-not-allowed" :id (:id component) :name (:name component))
|
||||||
(-> (pcb/empty-changes nil)
|
(-> (pcb/empty-changes nil)
|
||||||
(pcb/with-library-data file-data)
|
(pcb/with-library-data file-data)
|
||||||
(pcb/update-component (:id shape) repair-component))))
|
(pcb/update-component (:id component) repair-component))))
|
||||||
|
|
||||||
|
(defmethod repair-error :non-deleted-component-cannot-have-objects
|
||||||
|
[_ {component :shape} file-data _] ; in this error the :shape argument is the component
|
||||||
|
(let [repair-component
|
||||||
|
(fn [component]
|
||||||
|
; Remove the :objects field
|
||||||
|
(if-not (:deleted component)
|
||||||
|
(do
|
||||||
|
(log/debug :hint " -> remove :objects")
|
||||||
|
(dissoc component :objects))
|
||||||
|
component))]
|
||||||
|
|
||||||
|
(log/dbg :hint "repairing component :non-deleted-component-cannot-have-objects" :id (:id component) :name (:name component))
|
||||||
|
(-> (pcb/empty-changes nil)
|
||||||
|
(pcb/with-library-data file-data)
|
||||||
|
(pcb/update-component (:id component) repair-component))))
|
||||||
|
|
||||||
(defmethod repair-error :invalid-text-touched
|
(defmethod repair-error :invalid-text-touched
|
||||||
[_ {:keys [shape page-id] :as error} file-data _]
|
[_ {:keys [shape page-id] :as error} file-data _]
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
:not-head-copy-not-allowed
|
:not-head-copy-not-allowed
|
||||||
:not-component-not-allowed
|
:not-component-not-allowed
|
||||||
:component-nil-objects-not-allowed
|
:component-nil-objects-not-allowed
|
||||||
|
:non-deleted-component-cannot-have-objects
|
||||||
:instance-head-not-frame
|
:instance-head-not-frame
|
||||||
:invalid-text-touched
|
:invalid-text-touched
|
||||||
:misplaced-slot
|
:misplaced-slot
|
||||||
@@ -648,6 +649,13 @@
|
|||||||
"Component main not allowed inside other component"
|
"Component main not allowed inside other component"
|
||||||
main-instance file component-page))))
|
main-instance file component-page))))
|
||||||
|
|
||||||
|
(defn- check-not-objects
|
||||||
|
[component file]
|
||||||
|
(when (d/not-empty? (:objects component))
|
||||||
|
(report-error :non-deleted-component-cannot-have-objects
|
||||||
|
"A non-deleted component cannot have shapes inside"
|
||||||
|
component file nil)))
|
||||||
|
|
||||||
(defn- check-component
|
(defn- check-component
|
||||||
"Validate semantic coherence of a component. Report all errors found."
|
"Validate semantic coherence of a component. Report all errors found."
|
||||||
[component file]
|
[component file]
|
||||||
@@ -656,7 +664,8 @@
|
|||||||
"Objects list cannot be nil"
|
"Objects list cannot be nil"
|
||||||
component file nil))
|
component file nil))
|
||||||
(when-not (:deleted component)
|
(when-not (:deleted component)
|
||||||
(check-main-inside-main component file))
|
(check-main-inside-main component file)
|
||||||
|
(check-not-objects component file))
|
||||||
(when (:deleted component)
|
(when (:deleted component)
|
||||||
(check-component-duplicate-swap-slot component file)
|
(check-component-duplicate-swap-slot component file)
|
||||||
(check-ref-cycles component file))
|
(check-ref-cycles component file))
|
||||||
|
|||||||
@@ -60,6 +60,9 @@
|
|||||||
(some? objects)
|
(some? objects)
|
||||||
(assoc :objects objects)
|
(assoc :objects objects)
|
||||||
|
|
||||||
|
(nil? objects)
|
||||||
|
(dissoc :objects)
|
||||||
|
|
||||||
(some? modified-at)
|
(some? modified-at)
|
||||||
(assoc :modified-at modified-at)
|
(assoc :modified-at modified-at)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user