🐛 Fix repair for child not found situations

This commit is contained in:
Alejandro Alonso 2023-11-21 20:10:50 +01:00 committed by Andrey Antukh
parent 8325818da2
commit 37e9d9819b
2 changed files with 6 additions and 12 deletions

View file

@ -68,16 +68,10 @@
(defmethod repair-error :child-not-found (defmethod repair-error :child-not-found
[_ {:keys [shape page-id args] :as error} file-data _] [_ {:keys [shape page-id args] :as error} file-data _]
(let [repair-shape (log/info :hint "Repairing shape :child-not-found" :id (:id shape) :name (:name shape) :page-id page-id)
(fn [parent-shape] (-> (pcb/empty-changes nil page-id)
; Remove child shape from children list (pcb/with-file-data file-data)
(log/debug :hint " -> Remove child " :child-id (:child-id args)) (pcb/change-parent (:parent-id args) [shape] nil {:component-swap true})))
(update parent-shape :shapes (partial d/removev #(= % (:child-id args)))))]
(log/info :hint "Repairing shape :child-not-found" :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 [(:id shape)] repair-shape))))
(defmethod repair-error :frame-not-found (defmethod repair-error :frame-not-found
[_ {:keys [shape page-id] :as error} file-data _] [_ {:keys [shape page-id] :as error} file-data _]

View file

@ -126,8 +126,8 @@
(when (or (nil? child) (not= (:parent-id child) (:id shape))) (when (or (nil? child) (not= (:parent-id child) (:id shape)))
(report-error! :child-not-found (report-error! :child-not-found
(str/ffmt "Child % not found" child-id) (str/ffmt "Child % not found" child-id)
shape file page child file page
:child-id child-id)))))))) :parent-id (:id shape)))))))))
(defn validate-frame! (defn validate-frame!
"Validate that the frame-id shape exists and is indeed a frame. Also "Validate that the frame-id shape exists and is indeed a frame. Also