mirror of
https://github.com/penpot/penpot.git
synced 2026-09-24 12:56:15 +00:00
🐛 Fix ambiguation on import modal (#11747)
This commit is contained in:
parent
e34c618c3a
commit
683e0aed40
@ -390,25 +390,49 @@
|
|||||||
(mf/defc library-resolution*
|
(mf/defc library-resolution*
|
||||||
{::mf/private true}
|
{::mf/private true}
|
||||||
[{:keys [unresolved-file selection on-select on-disconnect]}]
|
[{:keys [unresolved-file selection on-select on-disconnect]}]
|
||||||
(let [candidates (:pending unresolved-file)
|
(let [file-id (:id unresolved-file)
|
||||||
|
candidates (:pending unresolved-file)
|
||||||
|
file-selection (get selection file-id)
|
||||||
|
|
||||||
|
on-select-file
|
||||||
|
(mf/use-fn
|
||||||
|
(mf/deps file-id on-select)
|
||||||
|
(partial on-select file-id))
|
||||||
|
|
||||||
|
on-disconnect-file
|
||||||
|
(mf/use-fn
|
||||||
|
(mf/deps file-id on-disconnect)
|
||||||
|
(partial on-disconnect file-id))
|
||||||
|
|
||||||
on-change-disconnected
|
on-change-disconnected
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps selection candidates on-select on-disconnect)
|
(mf/deps file-selection candidates on-select-file on-disconnect-file)
|
||||||
(fn [id]
|
(fn [id]
|
||||||
(if (contains? selection id)
|
(if (contains? file-selection id)
|
||||||
(on-disconnect id)
|
(on-disconnect-file id)
|
||||||
(let [{:keys [candidates]} (d/seek #(= id (:id %)) candidates)]
|
(let [{:keys [candidates]} (d/seek #(= id (:id %)) candidates)]
|
||||||
(when-let [first-c (first candidates)]
|
(when-let [first-c (first candidates)]
|
||||||
(on-select id (str (:id first-c))))))))]
|
(on-select-file id (str (:id first-c))))))))]
|
||||||
|
|
||||||
;; Pre-select first candidate for each library
|
;; Default each pending library to another file's choice for it, if any, else the first candidate.
|
||||||
(mf/with-effect [candidates]
|
(mf/with-effect [candidates file-id]
|
||||||
(doseq [{:keys [id candidates]} candidates]
|
(doseq [{:keys [id candidates]} candidates]
|
||||||
(when-not (contains? selection id)
|
(when-not (contains? file-selection id)
|
||||||
(when-let [first-c (first candidates)]
|
(let [other-choice (some #(get % id) (vals selection))
|
||||||
(on-select id (str (:id first-c)))))))
|
default-id (or other-choice (some-> candidates first :id str))]
|
||||||
|
(when default-id
|
||||||
|
(on-select-file id default-id))))))
|
||||||
|
|
||||||
[:div {:class (stl/css :library-resolution)}
|
[:div {:class (stl/css :library-resolution)}
|
||||||
|
[:div {:class (stl/css :library-resolution-file-header)}
|
||||||
|
[:> icon* {:icon-id i/document
|
||||||
|
:class (stl/css :library-resolution-file-icon)
|
||||||
|
:size "s"}]
|
||||||
|
[:> text* {:class (stl/css :library-resolution-file-name)
|
||||||
|
:as "span"
|
||||||
|
:typography t/body-medium}
|
||||||
|
(:name unresolved-file)]]
|
||||||
|
|
||||||
[:> text* {:class (stl/css :library-resolution-message)
|
[:> text* {:class (stl/css :library-resolution-message)
|
||||||
:as "p"
|
:as "p"
|
||||||
:typography t/body-large}
|
:typography t/body-large}
|
||||||
@ -435,8 +459,8 @@
|
|||||||
{:id (str (:id c))
|
{:id (str (:id c))
|
||||||
:label (str (:name c) " (" (:project-name c) ")")})
|
:label (str (:name c) " (" (:project-name c) ")")})
|
||||||
candidates)
|
candidates)
|
||||||
selected (get selection id)
|
selected (get file-selection id)
|
||||||
is-conected (contains? selection id)]
|
is-conected (contains? file-selection id)]
|
||||||
[:tr {:class (stl/css :library-resolution-item)
|
[:tr {:class (stl/css :library-resolution-item)
|
||||||
:key (dm/str id)}
|
:key (dm/str id)}
|
||||||
[:td {:class (stl/css :library-resolution-item-name)}
|
[:td {:class (stl/css :library-resolution-item-name)}
|
||||||
@ -453,7 +477,7 @@
|
|||||||
:class (stl/css :library-resolution-select)
|
:class (stl/css :library-resolution-select)
|
||||||
:default-selected (or (some-> selected str) "")
|
:default-selected (or (some-> selected str) "")
|
||||||
:has-portal true
|
:has-portal true
|
||||||
:on-change (partial on-select id)}]
|
:on-change (partial on-select-file id)}]
|
||||||
|
|
||||||
[:> text* {:class (stl/css :library-resolution-no-selection)
|
[:> text* {:class (stl/css :library-resolution-no-selection)
|
||||||
:as "span"
|
:as "span"
|
||||||
@ -465,8 +489,9 @@
|
|||||||
(mf/defc library-resolution-summary-file*
|
(mf/defc library-resolution-summary-file*
|
||||||
{::mf/private true}
|
{::mf/private true}
|
||||||
[{:keys [resolution-file selection]}]
|
[{:keys [resolution-file selection]}]
|
||||||
(let [done (:done resolution-file)
|
(let [done (:done resolution-file)
|
||||||
pending (:pending resolution-file)]
|
pending (:pending resolution-file)
|
||||||
|
file-selection (get selection (:id resolution-file))]
|
||||||
[:div {:class (stl/css :summary-file)}
|
[:div {:class (stl/css :summary-file)}
|
||||||
[:div {:class (stl/css :summary-file-header)}
|
[:div {:class (stl/css :summary-file-header)}
|
||||||
[:> icon* {:icon-id i/document
|
[:> icon* {:icon-id i/document
|
||||||
@ -486,6 +511,9 @@
|
|||||||
:key (dm/str name)}
|
:key (dm/str name)}
|
||||||
[:span {:class (stl/css :summary-item-name)} name]
|
[:span {:class (stl/css :summary-item-name)} name]
|
||||||
[:span {:class (stl/css :summary-linked-badge)}
|
[:span {:class (stl/css :summary-linked-badge)}
|
||||||
|
[:> icon* {:icon-id i/status-tick
|
||||||
|
:class (stl/css :summary-badge-icon)
|
||||||
|
:size "s"}]
|
||||||
(tr "dashboard.import.summary.linked")]])]])
|
(tr "dashboard.import.summary.linked")]])]])
|
||||||
|
|
||||||
(when (seq pending)
|
(when (seq pending)
|
||||||
@ -504,7 +532,7 @@
|
|||||||
[:span {:class (stl/css :summary-item-name-header)}
|
[:span {:class (stl/css :summary-item-name-header)}
|
||||||
(tr "dashboard.import.summary.new")]]
|
(tr "dashboard.import.summary.new")]]
|
||||||
(for [{:keys [id name] :as cand} pending]
|
(for [{:keys [id name] :as cand} pending]
|
||||||
(let [selected-id (get selection id)
|
(let [selected-id (get file-selection id)
|
||||||
selected-c (when selected-id
|
selected-c (when selected-id
|
||||||
(d/seek #(= (str (:id %)) (str selected-id)) (:candidates cand)))]
|
(d/seek #(= (str (:id %)) (str selected-id)) (:candidates cand)))]
|
||||||
[:li {:class (stl/css :summary-list-item)
|
[:li {:class (stl/css :summary-list-item)
|
||||||
@ -647,7 +675,7 @@
|
|||||||
(mf/defc import-library-resolution-stage*
|
(mf/defc import-library-resolution-stage*
|
||||||
{::mf/private true}
|
{::mf/private true}
|
||||||
[{:keys [current-unresolved-file selection on-select on-disconnect
|
[{:keys [current-unresolved-file selection on-select on-disconnect
|
||||||
visited all-visited?
|
visited last-file?
|
||||||
on-wizard-prev on-wizard-next on-wizard-skip]}]
|
on-wizard-prev on-wizard-next on-wizard-skip]}]
|
||||||
[:*
|
[:*
|
||||||
[:div {:class (stl/css :modal-content)}
|
[:div {:class (stl/css :modal-content)}
|
||||||
@ -673,9 +701,9 @@
|
|||||||
[:> button* {:class (stl/css :accept-btn)
|
[:> button* {:class (stl/css :accept-btn)
|
||||||
:variant "primary"
|
:variant "primary"
|
||||||
:on-click on-wizard-next}
|
:on-click on-wizard-next}
|
||||||
(if all-visited?
|
(if last-file?
|
||||||
(tr "labels.next")
|
(tr "dashboard.import.connect-selected-libraries")
|
||||||
(tr "dashboard.import.connect-selected-libraries"))]]]]])
|
(tr "dashboard.import.next-file"))]]]]])
|
||||||
|
|
||||||
(mf/defc import-library-summary-stage*
|
(mf/defc import-library-summary-stage*
|
||||||
{::mf/private true}
|
{::mf/private true}
|
||||||
@ -724,7 +752,7 @@
|
|||||||
resolution* (mf/use-state nil)
|
resolution* (mf/use-state nil)
|
||||||
resolution (not-empty (deref resolution*))
|
resolution (not-empty (deref resolution*))
|
||||||
|
|
||||||
;; User selection for multi-match candidates: {old-lib-id candidate-id}
|
;; Per-file selection for multi-match candidates: {file-id {old-lib-id candidate-id}}
|
||||||
selection* (mf/use-state {})
|
selection* (mf/use-state {})
|
||||||
selection (deref selection*)
|
selection (deref selection*)
|
||||||
|
|
||||||
@ -745,16 +773,19 @@
|
|||||||
[]
|
[]
|
||||||
resolution)))
|
resolution)))
|
||||||
|
|
||||||
all-visited?
|
|
||||||
(mf/with-memo [visited unresolved-files]
|
|
||||||
(when (seq unresolved-files)
|
|
||||||
(every? #(contains? visited (:id %)) unresolved-files)))
|
|
||||||
|
|
||||||
;; Current file shown in the wizard step: first unresolved file not yet visited.
|
;; Current file shown in the wizard step: first unresolved file not yet visited.
|
||||||
current-unresolved-file
|
current-unresolved-file
|
||||||
(mf/with-memo [unresolved-files visited]
|
(mf/with-memo [unresolved-files visited]
|
||||||
(d/seek #(not (contains? visited (:id %))) unresolved-files))
|
(d/seek #(not (contains? visited (:id %))) unresolved-files))
|
||||||
|
|
||||||
|
;; True once every other unresolved file has already been visited.
|
||||||
|
last-unresolved-file?
|
||||||
|
(mf/with-memo [unresolved-files visited current-unresolved-file]
|
||||||
|
(when (some? current-unresolved-file)
|
||||||
|
(every? #(or (= (:id %) (:id current-unresolved-file))
|
||||||
|
(contains? visited (:id %)))
|
||||||
|
unresolved-files)))
|
||||||
|
|
||||||
continue-entries
|
continue-entries
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps entries)
|
(mf/deps entries)
|
||||||
@ -837,7 +868,7 @@
|
|||||||
(->> (rx/from (:pending resolution-file))
|
(->> (rx/from (:pending resolution-file))
|
||||||
(rx/merge-map
|
(rx/merge-map
|
||||||
(fn [{:keys [id]}]
|
(fn [{:keys [id]}]
|
||||||
(when-let [selected-lib (get slc id)]
|
(when-let [selected-lib (get-in slc [file-id id])]
|
||||||
(link-files-to-library! [file-id] selected-lib)))))))
|
(link-files-to-library! [file-id] selected-lib)))))))
|
||||||
(rx/subs! (constantly nil)
|
(rx/subs! (constantly nil)
|
||||||
(constantly nil)
|
(constantly nil)
|
||||||
@ -855,12 +886,11 @@
|
|||||||
|
|
||||||
on-wizard-prev
|
on-wizard-prev
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps current-unresolved-file)
|
(mf/deps visited)
|
||||||
(fn []
|
(fn []
|
||||||
;; Remove the current file from visited; it becomes current again after re-render,
|
;; Disj makes the last-visited file current again on next render.
|
||||||
;; because it's no longer in visited.
|
(let [last-id (last visited)]
|
||||||
(let [file-id (:id current-unresolved-file)]
|
(swap! visited* disj last-id))))
|
||||||
(swap! visited* disj file-id))))
|
|
||||||
|
|
||||||
on-wizard-skip
|
on-wizard-skip
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
@ -868,7 +898,7 @@
|
|||||||
(fn []
|
(fn []
|
||||||
(let [file-id (:id current-unresolved-file)
|
(let [file-id (:id current-unresolved-file)
|
||||||
pending-ids (mapv :id (:pending current-unresolved-file))]
|
pending-ids (mapv :id (:pending current-unresolved-file))]
|
||||||
(swap! selection* #(apply dissoc % pending-ids))
|
(swap! selection* update file-id (fn [file-sel] (apply dissoc file-sel pending-ids)))
|
||||||
(swap! visited* conj file-id))))
|
(swap! visited* conj file-id))))
|
||||||
|
|
||||||
on-summary-back
|
on-summary-back
|
||||||
@ -913,14 +943,13 @@
|
|||||||
|
|
||||||
manage-on-select
|
manage-on-select
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps selection)
|
(fn [file-id old-lib-id candidate-id]
|
||||||
(fn [old-lib-id candidate-id]
|
(swap! selection* assoc-in [file-id old-lib-id] candidate-id)))
|
||||||
(swap! selection* assoc old-lib-id candidate-id)))
|
|
||||||
|
|
||||||
manage-on-disconnect
|
manage-on-disconnect
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [old-lib-id]
|
(fn [file-id old-lib-id]
|
||||||
(swap! selection* dissoc old-lib-id)))]
|
(swap! selection* update file-id (fnil dissoc {}) old-lib-id)))]
|
||||||
|
|
||||||
(mf/with-effect [visited unresolved-files]
|
(mf/with-effect [visited unresolved-files]
|
||||||
(when (and (seq unresolved-files)
|
(when (and (seq unresolved-files)
|
||||||
@ -991,7 +1020,7 @@
|
|||||||
:on-select manage-on-select
|
:on-select manage-on-select
|
||||||
:on-disconnect manage-on-disconnect
|
:on-disconnect manage-on-disconnect
|
||||||
:visited visited
|
:visited visited
|
||||||
:all-visited? all-visited?
|
:last-file? last-unresolved-file?
|
||||||
:on-wizard-prev on-wizard-prev
|
:on-wizard-prev on-wizard-prev
|
||||||
:on-wizard-next on-wizard-next
|
:on-wizard-next on-wizard-next
|
||||||
:on-wizard-skip on-wizard-skip}]
|
:on-wizard-skip on-wizard-skip}]
|
||||||
|
|||||||
15
frontend/src/app/main/ui/dashboard/import.scss
vendored
15
frontend/src/app/main/ui/dashboard/import.scss
vendored
@ -267,6 +267,21 @@
|
|||||||
margin-block-end: var(--sp-s);
|
margin-block-end: var(--sp-s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.library-resolution-file-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--sp-s);
|
||||||
|
}
|
||||||
|
|
||||||
|
.library-resolution-file-icon {
|
||||||
|
color: var(--color-foreground-secondary);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.library-resolution-file-name {
|
||||||
|
color: var(--color-foreground-primary);
|
||||||
|
}
|
||||||
|
|
||||||
.library-resolution-header {
|
.library-resolution-header {
|
||||||
@include use-typography("body-small");
|
@include use-typography("body-small");
|
||||||
|
|
||||||
|
|||||||
@ -831,6 +831,10 @@ msgstr[1] "%s files have been imported successfully."
|
|||||||
msgid "dashboard.import.import-warning"
|
msgid "dashboard.import.import-warning"
|
||||||
msgstr "Some files containted invalid objects that have been removed."
|
msgstr "Some files containted invalid objects that have been removed."
|
||||||
|
|
||||||
|
#: src/app/main/ui/dashboard/import.cljs:704
|
||||||
|
msgid "dashboard.import.next-file"
|
||||||
|
msgstr "Next file"
|
||||||
|
|
||||||
#: src/app/main/ui/dashboard.cljs:265
|
#: src/app/main/ui/dashboard.cljs:265
|
||||||
msgid "dashboard.import.no-perms"
|
msgid "dashboard.import.no-perms"
|
||||||
msgstr "You don’t have permission to import to this team"
|
msgstr "You don’t have permission to import to this team"
|
||||||
@ -885,6 +889,10 @@ msgstr "original library"
|
|||||||
msgid "dashboard.import.connect-selected-libraries"
|
msgid "dashboard.import.connect-selected-libraries"
|
||||||
msgstr "Connect selected libraries"
|
msgstr "Connect selected libraries"
|
||||||
|
|
||||||
|
#: src/app/main/ui/dashboard/import.cljs:703
|
||||||
|
msgid "dashboard.import.review-links"
|
||||||
|
msgstr "Review library links"
|
||||||
|
|
||||||
#, unused
|
#, unused
|
||||||
msgid "dashboard.import.summary.auto-linked"
|
msgid "dashboard.import.summary.auto-linked"
|
||||||
msgstr "Auto-linked"
|
msgstr "Auto-linked"
|
||||||
|
|||||||
@ -829,6 +829,10 @@ msgstr[1] "%s ficheros se han importado correctamente."
|
|||||||
msgid "dashboard.import.import-warning"
|
msgid "dashboard.import.import-warning"
|
||||||
msgstr "Algunos ficheros contenían objetos erroneos que no han sido importados."
|
msgstr "Algunos ficheros contenían objetos erroneos que no han sido importados."
|
||||||
|
|
||||||
|
#: src/app/main/ui/dashboard/import.cljs:704
|
||||||
|
msgid "dashboard.import.next-file"
|
||||||
|
msgstr "Siguiente archivo"
|
||||||
|
|
||||||
#: src/app/main/ui/dashboard.cljs:265
|
#: src/app/main/ui/dashboard.cljs:265
|
||||||
msgid "dashboard.import.no-perms"
|
msgid "dashboard.import.no-perms"
|
||||||
msgstr "No tienes permisos para importar en este equipo"
|
msgstr "No tienes permisos para importar en este equipo"
|
||||||
@ -883,6 +887,10 @@ msgstr "biblioteca original"
|
|||||||
msgid "dashboard.import.connect-selected-libraries"
|
msgid "dashboard.import.connect-selected-libraries"
|
||||||
msgstr "Conectar bibliotecas seleccionadas"
|
msgstr "Conectar bibliotecas seleccionadas"
|
||||||
|
|
||||||
|
#: src/app/main/ui/dashboard/import.cljs:703
|
||||||
|
msgid "dashboard.import.review-links"
|
||||||
|
msgstr "Revisar vínculos de biblioteca"
|
||||||
|
|
||||||
#, unused
|
#, unused
|
||||||
msgid "dashboard.import.summary.auto-linked"
|
msgid "dashboard.import.summary.auto-linked"
|
||||||
msgstr "Vinculadas automáticamente"
|
msgstr "Vinculadas automáticamente"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user