mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 04:49:03 -05:00
🐛 Fix import from components v1 to v2
This commit is contained in:
parent
7f4bc246c6
commit
9ea440b6f7
2 changed files with 33 additions and 12 deletions
|
@ -14,6 +14,7 @@
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.db.sql :as sql]
|
[app.db.sql :as sql]
|
||||||
|
[app.features.components-v2 :as feat.compv2]
|
||||||
[app.features.fdata :as fdata]
|
[app.features.fdata :as fdata]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.commands.files :as files]
|
[app.rpc.commands.files :as files]
|
||||||
|
@ -46,22 +47,26 @@
|
||||||
[cfg {:keys [::rpc/profile-id project-id] :as params}]
|
[cfg {:keys [::rpc/profile-id project-id] :as params}]
|
||||||
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||||
(projects/check-edition-permissions! conn profile-id project-id)
|
(projects/check-edition-permissions! conn profile-id project-id)
|
||||||
(let [team (teams/get-team conn
|
(let [team (teams/get-team conn :profile-id profile-id :project-id project-id)
|
||||||
:profile-id profile-id
|
|
||||||
:project-id project-id)
|
|
||||||
|
|
||||||
;; When we create files, we only need to respect the team
|
;; When we create files, we only need to respect the team
|
||||||
;; features, because some features can be enabled
|
;; features, because some features can be enabled
|
||||||
;; globally, but the team is still not migrated properly.
|
;; globally, but the team is still not migrated properly.
|
||||||
features (-> (cfeat/get-team-enabled-features cf/flags team)
|
input-features (:features params #{})
|
||||||
(cfeat/check-client-features! (:features params)))
|
|
||||||
|
;; If the imported project doesn't contain v2 we need to remove it
|
||||||
|
team-features
|
||||||
|
(cond-> (cfeat/get-team-enabled-features cf/flags team)
|
||||||
|
(not (contains? input-features "components/v2"))
|
||||||
|
(disj "components/v2"))
|
||||||
|
|
||||||
|
|
||||||
;; We also include all no migration features declared by
|
;; We also include all no migration features declared by
|
||||||
;; client; that enables the ability to enable a runtime
|
;; client; that enables the ability to enable a runtime
|
||||||
;; feature on frontend and make it permanent on file
|
;; feature on frontend and make it permanent on file
|
||||||
features (-> (:features params #{})
|
features (-> input-features
|
||||||
(set/intersection cfeat/no-migration-features)
|
(set/intersection cfeat/no-migration-features)
|
||||||
(set/union features))
|
(set/union team-features))
|
||||||
|
|
||||||
params (-> params
|
params (-> params
|
||||||
(assoc :profile-id profile-id)
|
(assoc :profile-id profile-id)
|
||||||
|
@ -100,7 +105,7 @@
|
||||||
;; --- MUTATION COMMAND: persist-temp-file
|
;; --- MUTATION COMMAND: persist-temp-file
|
||||||
|
|
||||||
(defn persist-temp-file
|
(defn persist-temp-file
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [id] :as params}]
|
[{:keys [::db/conn] :as cfg} {:keys [id ::rpc/profile-id] :as params}]
|
||||||
(let [file (files/get-file cfg id
|
(let [file (files/get-file cfg id
|
||||||
:migrate? false
|
:migrate? false
|
||||||
:lock-for-update? true)]
|
:lock-for-update? true)]
|
||||||
|
@ -109,6 +114,7 @@
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :cant-persist-already-persisted-file))
|
:code :cant-persist-already-persisted-file))
|
||||||
|
|
||||||
|
|
||||||
(let [changes (->> (db/cursor conn
|
(let [changes (->> (db/cursor conn
|
||||||
(sql/select :file-change {:file-id id}
|
(sql/select :file-change {:file-id id}
|
||||||
{:order-by [[:revn :asc]]})
|
{:order-by [[:revn :asc]]})
|
||||||
|
@ -133,6 +139,19 @@
|
||||||
:revn 1
|
:revn 1
|
||||||
:data (blob/encode (:data file))}
|
:data (blob/encode (:data file))}
|
||||||
{:id id})
|
{:id id})
|
||||||
|
|
||||||
|
(let [team (teams/get-team conn :profile-id profile-id :project-id (:project-id file))
|
||||||
|
file-features (:features file)
|
||||||
|
team-features (cfeat/get-team-enabled-features cf/flags team)]
|
||||||
|
(when (and (contains? team-features "components/v2")
|
||||||
|
(not (contains? file-features "components/v2")))
|
||||||
|
;; Migrate components v2
|
||||||
|
(feat.compv2/migrate-file! cfg
|
||||||
|
(:id file)
|
||||||
|
:max-procs 2
|
||||||
|
:validate? true
|
||||||
|
:throw-on-validate? true)))
|
||||||
|
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(def ^:private schema:persist-temp-file
|
(def ^:private schema:persist-temp-file
|
||||||
|
|
|
@ -524,7 +524,10 @@
|
||||||
(dissoc :main-instance-y))
|
(dissoc :main-instance-y))
|
||||||
|
|
||||||
obj (-> (cts/setup-shape attrs)
|
obj (-> (cts/setup-shape attrs)
|
||||||
(check-name file root-type))]
|
(check-name file root-type)
|
||||||
|
;; Components need to have nil values for frame and parent
|
||||||
|
(assoc :frame-id nil)
|
||||||
|
(assoc :parent-id nil))]
|
||||||
|
|
||||||
(-> file
|
(-> file
|
||||||
(commit-change
|
(commit-change
|
||||||
|
@ -537,10 +540,9 @@
|
||||||
:shapes [obj]})
|
:shapes [obj]})
|
||||||
|
|
||||||
(assoc :last-id (:id obj))
|
(assoc :last-id (:id obj))
|
||||||
(update :parent-stack conjv (:id obj))
|
(assoc :parent-stack [(:id obj)])
|
||||||
(assoc :current-component-id (:id obj))
|
(assoc :current-component-id (:id obj))
|
||||||
(assoc :current-frame-id (when (= (:type obj) :frame)
|
(assoc :current-frame-id (if (= (:type obj) :frame) (:id obj) uuid/zero))))))
|
||||||
(:id obj)))))))
|
|
||||||
|
|
||||||
(defn finish-component
|
(defn finish-component
|
||||||
[file]
|
[file]
|
||||||
|
|
Loading…
Add table
Reference in a new issue