0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -05:00

🐛 Fix change structure of comp doesn't update copies on another file

This commit is contained in:
Pablo Alba 2024-03-13 21:29:11 +01:00 committed by Andrés Moya
parent d6b60ce43a
commit a5b156e0d6
3 changed files with 39 additions and 9 deletions

View file

@ -732,7 +732,8 @@
:main-instance-id (:main-instance-id new-component) :main-instance-id (:main-instance-id new-component)
:main-instance-page (:main-instance-page new-component) :main-instance-page (:main-instance-page new-component)
:annotation (:annotation new-component) :annotation (:annotation new-component)
:objects (:objects new-component)}) ;; this won't exist in components-v2 (except for deleted components) :objects (:objects new-component) ;; this won't exist in components-v2 (except for deleted components)
:modified-at (:modified-at new-component)})
(update :undo-changes conj {:type :mod-component (update :undo-changes conj {:type :mod-component
:id id :id id
:name (:name prev-component) :name (:name prev-component)

View file

@ -48,7 +48,7 @@
(wrap-object-fn))))))) (wrap-object-fn)))))))
(defn mod-component (defn mod-component
[file-data {:keys [id name path main-instance-id main-instance-page objects annotation]}] [file-data {:keys [id name path main-instance-id main-instance-page objects annotation modified-at]}]
(let [wrap-objects-fn cfeat/*wrap-with-objects-map-fn*] (let [wrap-objects-fn cfeat/*wrap-with-objects-map-fn*]
(d/update-in-when file-data [:components id] (d/update-in-when file-data [:components id]
(fn [component] (fn [component]
@ -69,6 +69,9 @@
(some? objects) (some? objects)
(assoc :objects objects) (assoc :objects objects)
(some? modified-at)
(assoc :modified-at modified-at)
(some? annotation) (some? annotation)
(assoc :annotation annotation) (assoc :annotation annotation)
@ -76,7 +79,7 @@
(dissoc :annotation)) (dissoc :annotation))
diff (set/difference diff (set/difference
(ctk/diff-components component new-comp) (ctk/diff-components component new-comp)
#{:annotation})] ;; The set of properties that doesn't mark a component as touched #{:annotation :modified-at})] ;; The set of properties that doesn't mark a component as touched
(if (empty? diff) (if (empty? diff)
new-comp new-comp

View file

@ -1186,6 +1186,26 @@
:callback do-update}] :callback do-update}]
:tag :sync-dialog))))))) :tag :sync-dialog)))))))
(defn touch-component
"Update the modified-at attribute of the component to now"
[id]
(dm/verify! (uuid? id))
(ptk/reify ::touch-component
cljs.core/IDeref
(-deref [_] [id])
ptk/WatchEvent
(watch [it state _]
(let [data (get state :workspace-data)
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/update-component id #(assoc % :modified-at (dt/now))))]
(rx/of (dch/commit-changes {:origin it
:redo-changes (:redo-changes changes)
:undo-changes []
:save-undo? false}))))))
(defn component-changed (defn component-changed
"Notify that the component with the given id has changed, so it needs to be updated "Notify that the component with the given id has changed, so it needs to be updated
in the current file and in the copies. And also update its thumbnails." in the current file and in the copies. And also update its thumbnails."
@ -1197,6 +1217,7 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (rx/of
(touch-component component-id)
(launch-component-sync component-id file-id undo-group))))) (launch-component-sync component-id file-id undo-group)))))
(defn watch-component-changes (defn watch-component-changes
@ -1244,13 +1265,18 @@
(map (partial ch/components-changed old-data)) (map (partial ch/components-changed old-data))
(reduce into #{})))] (reduce into #{})))]
(if (and (d/not-empty? changed-components) save-undo?) (if (d/not-empty? changed-components)
(do (log/info :msg "DETECTED COMPONENTS CHANGED" (if save-undo?
:ids (map str changed-components) (do (log/info :msg "DETECTED COMPONENTS CHANGED"
:undo-group undo-group) :ids (map str changed-components)
:undo-group undo-group)
(->> (rx/from changed-components) (->> (rx/from changed-components)
(rx/map #(component-changed % (:id old-data) undo-group)))) (rx/map #(component-changed % (:id old-data) undo-group))))
;; even if save-undo? is false, we need to update the :modified-date of the component
;; (for example, for undos)
(->> (rx/from changed-components)
(rx/map #(touch-component %))))
(rx/empty))))) (rx/empty)))))
changes-s changes-s