0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

Add a few small enhancements

This commit is contained in:
Andrés Moya 2023-11-17 13:45:06 +01:00 committed by Andrés Moya
parent 6c1c780758
commit dcd347ab4f
3 changed files with 22 additions and 18 deletions

View file

@ -284,7 +284,7 @@
[component]
(if (and (contains? component :objects) (nil? (:objects component)))
(if (:deleted component)
(assoc component :objects [])
(assoc component :objects {})
(dissoc component :objects))
component))]
(-> file-data

View file

@ -408,11 +408,11 @@
[_ {:keys [shape] :as error} file-data _]
(let [repair-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
(if (:deleted component)
(do
(log/debug :hint " -> Set :objects []")
(assoc component :objects []))
(log/debug :hint " -> Set :objects {}")
(assoc component :objects {}))
(do
(log/debug :hint " -> Remove :objects")
(dissoc component :objects))))]

View file

@ -46,7 +46,8 @@
:nested-copy-not-allowed
:not-head-main-not-allowed
:not-head-copy-not-allowed
:not-component-not-allowed})
:not-component-not-allowed
:component-nil-objects-not-allowed})
(def validation-error
[:map {:title "ValidationError"}
@ -328,8 +329,7 @@
(defn validate-shape!
"Validate referential integrity and semantic coherence of
a shape and all its children. Raises an exception on first
error found.
a shape and all its children. Report all errors found.
The context is the situation of the parent in respect to components:
- :not-component
@ -406,22 +406,27 @@
(validate-shape-not-component! shape file page libraries)))))))
(defn validate-shape
"Validate referential integrity and semantic coherence of
a shape and all its children. Returns a list of errors."
"Validate a shape and all its children. Returns a list of errors."
[shape-id file page libraries]
(binding [*errors* (volatile! [])]
(validate-shape! shape-id file page libraries)
(deref *errors*)))
(defn validate-component!
" Validate semantic coherence of a component. Raises an exception
on first error found."
"Validate semantic coherence of a component. Report all errors found."
[component file]
(when (and (contains? component :objects) (nil? (:objects component)))
(report-error! :component-nil-objects-not-allowed
"Objects list cannot be nil"
component file nil)))
(defn validate-component
"Validate a component. Returns a list of errors."
[component file]
(binding [*errors* (volatile! [])]
(validate-component! component file)
(deref *errors*)))
(def valid-fdata?
"Structural validation of file data using defined schema"
(sm/lazy-validator ::ctf/data))
@ -451,14 +456,13 @@
;; If `libraries` is provided, this means the full file
;; validation is activated so we proceed to execute the
;; validation
(when (some? libraries)
(when (:components data)
(doseq [component (vals (:components data))]
(validate-component! component file)))
(doseq [page (filter :id (ctpl/pages-seq data))]
(validate-shape! uuid/zero file page libraries)))
(when (some? libraries)
(doseq [page (filter :id (ctpl/pages-seq data))]
(validate-shape! uuid/zero file page libraries))
(doseq [component (vals (:components data))]
(validate-component! component file)))
file))
file))
(defn validate-file
"Validate referencial integrity and semantic coherence of