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

Add label and id support for debug snapshot helpers

This commit is contained in:
Andrey Antukh 2024-08-27 15:14:40 +02:00
parent 2643dae0a7
commit 569674452a
3 changed files with 21 additions and 14 deletions

View file

@ -41,8 +41,8 @@
FROM file_change FROM file_change
WHERE file_id = ? WHERE file_id = ?
AND created_at < ? AND created_at < ?
AND label is not null AND label IS NOT NULL
ORDER BY created_at desc ORDER BY created_at DESC
LIMIT ?") LIMIT ?")
(defn get-file-snapshots (defn get-file-snapshots
@ -50,7 +50,6 @@
:or {limit Long/MAX_VALUE}}] :or {limit Long/MAX_VALUE}}]
(let [start-at (or start-at (dt/now)) (let [start-at (or start-at (dt/now))
limit (min limit 20)] limit (min limit 20)]
(->> (db/exec! conn [sql:get-file-snapshots file-id start-at limit]) (->> (db/exec! conn [sql:get-file-snapshots file-id start-at limit])
(mapv (fn [row] (mapv (fn [row]
(update row :created-at dt/format-instant :rfc1123)))))) (update row :created-at dt/format-instant :rfc1123))))))

View file

@ -73,7 +73,6 @@
(str x)))] (str x)))]
(f x)))) (f x))))
#?(:cljs #?(:cljs
(defn ->clj (defn ->clj
[o & {:keys [key-fn val-fn] :or {key-fn read-kebab-key val-fn identity}}] [o & {:keys [key-fn val-fn] :or {key-fn read-kebab-key val-fn identity}}]

View file

@ -12,6 +12,7 @@
[app.common.files.validate :as cfv] [app.common.files.validate :as cfv]
[app.common.json :as json] [app.common.json :as json]
[app.common.logging :as l] [app.common.logging :as l]
[app.common.schema :as sm]
[app.common.transit :as t] [app.common.transit :as t]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.uri :as u] [app.common.uri :as u]
@ -482,7 +483,7 @@
(rx/map http/conditional-decode-transit) (rx/map http/conditional-decode-transit)
(rx/mapcat rp/handle-response) (rx/mapcat rp/handle-response)
(rx/subs! (fn [{:keys [id]}] (rx/subs! (fn [{:keys [id]}]
(println "Snapshot saved:" (str id))) (println "Snapshot saved:" (str id) label))
(fn [cause] (fn [cause]
(js/console.log "EE:" cause)))))) (js/console.log "EE:" cause))))))
@ -490,13 +491,21 @@
[label file-id] [label file-id]
(when-let [file-id (or (d/parse-uuid file-id) (when-let [file-id (or (d/parse-uuid file-id)
(:current-file-id @st/state))] (:current-file-id @st/state))]
(let [snapshot-id (sm/parse-uuid label)
label (if snapshot-id nil label)
params (cond-> {:file-id file-id}
(uuid? snapshot-id)
(assoc :id snapshot-id)
(string? label)
(assoc :label label))]
(->> (http/send! {:method :post (->> (http/send! {:method :post
:uri (u/join cf/public-uri "api/rpc/command/restore-file-snapshot") :uri (u/join cf/public-uri "api/rpc/command/restore-file-snapshot")
:body (http/transit-data {:file-id file-id :label label})}) :body (http/transit-data params)})
(rx/map http/conditional-decode-transit) (rx/map http/conditional-decode-transit)
(rx/mapcat rp/handle-response) (rx/mapcat rp/handle-response)
(rx/subs! (fn [_] (rx/subs! (fn [_]
(println "Snapshot restored " label) (println "Snapshot restored " (or snapshot-id label)))
#_(.reload js/location)) #_(.reload js/location))
(fn [cause] (fn [cause]
(js/console.log "EE:" cause)))))) (js/console.log "EE:" cause))))))