mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 09:36:40 +02:00
✨ Add a few small enhancements
This commit is contained in:
parent
6c1c780758
commit
dcd347ab4f
3 changed files with 22 additions and 18 deletions
|
@ -284,7 +284,7 @@
|
||||||
[component]
|
[component]
|
||||||
(if (and (contains? component :objects) (nil? (:objects component)))
|
(if (and (contains? component :objects) (nil? (:objects component)))
|
||||||
(if (:deleted component)
|
(if (:deleted component)
|
||||||
(assoc component :objects [])
|
(assoc component :objects {})
|
||||||
(dissoc component :objects))
|
(dissoc component :objects))
|
||||||
component))]
|
component))]
|
||||||
(-> file-data
|
(-> file-data
|
||||||
|
|
|
@ -408,11 +408,11 @@
|
||||||
[_ {:keys [shape] :as error} file-data _]
|
[_ {:keys [shape] :as error} file-data _]
|
||||||
(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
|
||||||
(if (:deleted component)
|
(if (:deleted component)
|
||||||
(do
|
(do
|
||||||
(log/debug :hint " -> Set :objects []")
|
(log/debug :hint " -> Set :objects {}")
|
||||||
(assoc component :objects []))
|
(assoc component :objects {}))
|
||||||
(do
|
(do
|
||||||
(log/debug :hint " -> Remove :objects")
|
(log/debug :hint " -> Remove :objects")
|
||||||
(dissoc component :objects))))]
|
(dissoc component :objects))))]
|
||||||
|
|
|
@ -46,7 +46,8 @@
|
||||||
:nested-copy-not-allowed
|
:nested-copy-not-allowed
|
||||||
:not-head-main-not-allowed
|
:not-head-main-not-allowed
|
||||||
:not-head-copy-not-allowed
|
:not-head-copy-not-allowed
|
||||||
:not-component-not-allowed})
|
:not-component-not-allowed
|
||||||
|
:component-nil-objects-not-allowed})
|
||||||
|
|
||||||
(def validation-error
|
(def validation-error
|
||||||
[:map {:title "ValidationError"}
|
[:map {:title "ValidationError"}
|
||||||
|
@ -328,8 +329,7 @@
|
||||||
|
|
||||||
(defn validate-shape!
|
(defn validate-shape!
|
||||||
"Validate referential integrity and semantic coherence of
|
"Validate referential integrity and semantic coherence of
|
||||||
a shape and all its children. Raises an exception on first
|
a shape and all its children. Report all errors found.
|
||||||
error found.
|
|
||||||
|
|
||||||
The context is the situation of the parent in respect to components:
|
The context is the situation of the parent in respect to components:
|
||||||
- :not-component
|
- :not-component
|
||||||
|
@ -406,22 +406,27 @@
|
||||||
(validate-shape-not-component! shape file page libraries)))))))
|
(validate-shape-not-component! shape file page libraries)))))))
|
||||||
|
|
||||||
(defn validate-shape
|
(defn validate-shape
|
||||||
"Validate referential integrity and semantic coherence of
|
"Validate a shape and all its children. Returns a list of errors."
|
||||||
a shape and all its children. Returns a list of errors."
|
|
||||||
[shape-id file page libraries]
|
[shape-id file page libraries]
|
||||||
(binding [*errors* (volatile! [])]
|
(binding [*errors* (volatile! [])]
|
||||||
(validate-shape! shape-id file page libraries)
|
(validate-shape! shape-id file page libraries)
|
||||||
(deref *errors*)))
|
(deref *errors*)))
|
||||||
|
|
||||||
(defn validate-component!
|
(defn validate-component!
|
||||||
" Validate semantic coherence of a component. Raises an exception
|
"Validate semantic coherence of a component. Report all errors found."
|
||||||
on first error found."
|
|
||||||
[component file]
|
[component file]
|
||||||
(when (and (contains? component :objects) (nil? (:objects component)))
|
(when (and (contains? component :objects) (nil? (:objects component)))
|
||||||
(report-error! :component-nil-objects-not-allowed
|
(report-error! :component-nil-objects-not-allowed
|
||||||
"Objects list cannot be nil"
|
"Objects list cannot be nil"
|
||||||
component file 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?
|
(def valid-fdata?
|
||||||
"Structural validation of file data using defined schema"
|
"Structural validation of file data using defined schema"
|
||||||
(sm/lazy-validator ::ctf/data))
|
(sm/lazy-validator ::ctf/data))
|
||||||
|
@ -451,14 +456,13 @@
|
||||||
;; If `libraries` is provided, this means the full file
|
;; If `libraries` is provided, this means the full file
|
||||||
;; validation is activated so we proceed to execute the
|
;; validation is activated so we proceed to execute the
|
||||||
;; validation
|
;; validation
|
||||||
(when (some? libraries)
|
(when (some? libraries)
|
||||||
(when (:components data)
|
(doseq [page (filter :id (ctpl/pages-seq data))]
|
||||||
(doseq [component (vals (:components data))]
|
(validate-shape! uuid/zero file page libraries))
|
||||||
(validate-component! component file)))
|
(doseq [component (vals (:components data))]
|
||||||
(doseq [page (filter :id (ctpl/pages-seq data))]
|
(validate-component! component file)))
|
||||||
(validate-shape! uuid/zero file page libraries)))
|
|
||||||
|
|
||||||
file))
|
file))
|
||||||
|
|
||||||
(defn validate-file
|
(defn validate-file
|
||||||
"Validate referencial integrity and semantic coherence of
|
"Validate referencial integrity and semantic coherence of
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue