mirror of
https://github.com/penpot/penpot.git
synced 2026-05-11 02:58:25 +00:00
🐛 Fix show in assets panel option for component of variants (#7311)
This commit is contained in:
parent
b8c8579ff5
commit
9311ee4c87
@ -569,8 +569,7 @@
|
||||
(let [single? (= (count shapes) 1)
|
||||
objects (deref refs/workspace-page-objects)
|
||||
can-make-component (every? true? (map #(ctn/valid-shape-for-component? objects %) shapes))
|
||||
heads (filter ctk/instance-head? shapes)
|
||||
components-menu-entries (cmm/generate-components-menu-entries heads)
|
||||
components-menu-entries (cmm/generate-components-menu-entries shapes)
|
||||
variant-container? (and single? (ctk/is-variant-container? (first shapes)))
|
||||
all-main? (every? ctk/main-instance? shapes)
|
||||
any-variant? (some ctk/is-variant? shapes)
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
[app.util.array :as array]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.dom.dnd :as dnd]
|
||||
[app.util.i18n :as i18n :refer [tr c]]
|
||||
[app.util.i18n :as i18n :refer [c tr]]
|
||||
[app.util.strings :refer [matches-search]]
|
||||
[app.util.timers :as ts]
|
||||
[cljs.spec.alpha :as s]
|
||||
@ -358,8 +358,10 @@
|
||||
|
||||
;; For when it's only one shape
|
||||
shape (first shapes)
|
||||
id (:id shape)
|
||||
shape-id (:id shape)
|
||||
|
||||
main-instance? (ctk/main-instance? shape)
|
||||
variant-container? (ctk/is-variant-container? shape)
|
||||
|
||||
component-id (:component-id shape)
|
||||
variant-id (:variant-id shape)
|
||||
@ -409,7 +411,7 @@
|
||||
#(st/emit! (dwl/reset-components (map :id touched-not-dangling)))
|
||||
|
||||
do-update-component-sync
|
||||
#(st/emit! (dwl/update-component-sync id library-id))
|
||||
#(st/emit! (dwl/update-component-sync shape-id library-id))
|
||||
|
||||
do-update-remote-component
|
||||
(fn []
|
||||
@ -429,21 +431,24 @@
|
||||
(do-update-remote-component))
|
||||
|
||||
do-show-in-assets
|
||||
#(st/emit! (dw/show-component-in-assets component-id))
|
||||
(let [component-id (if variant-container?
|
||||
(->> (:shapes shape) (mapv #(get objects %)) first :component-id)
|
||||
component-id)]
|
||||
#(st/emit! (dw/show-component-in-assets component-id)))
|
||||
|
||||
do-create-annotation
|
||||
#(st/emit! (dw/set-annotations-id-for-create id))
|
||||
#(st/emit! (dw/set-annotations-id-for-create shape-id))
|
||||
|
||||
do-add-variant
|
||||
#(if (ctk/is-variant? shape)
|
||||
(st/emit!
|
||||
(ptk/event ::ev/event {::ev/name "add-new-variant"
|
||||
:trigger (if for-design-tab? "design-tab-menu-variant" "context-menu-variant")})
|
||||
(dwv/add-new-variant id))
|
||||
(dwv/add-new-variant shape-id))
|
||||
(st/emit!
|
||||
(ptk/event ::ev/event {::ev/name "transform-in-variant"
|
||||
:trigger (if for-design-tab? "design-tab-menu" "context-menu")})
|
||||
(dwv/transform-in-variant id)))
|
||||
(dwv/transform-in-variant shape-id)))
|
||||
|
||||
do-add-new-property
|
||||
#(st/emit!
|
||||
@ -478,7 +483,8 @@
|
||||
(when (= 1 (count comps-to-restore))
|
||||
(ts/schedule 1000 #(do-show-component nil true)))))
|
||||
|
||||
menu-entries [(when (and (or (not multi) same-variant?) main-instance?)
|
||||
menu-entries [(when (or (and (not multi) (or variant-container? main-instance?))
|
||||
(and multi same-variant?))
|
||||
{:title (tr "workspace.shape.menu.show-in-assets")
|
||||
:action do-show-in-assets})
|
||||
(when (and (not multi) main-instance? local-component? lacks-annotation?)
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
(ns app.main.ui.workspace.sidebar.options.menus.component
|
||||
(:require-macros [app.main.style :as stl])
|
||||
(:require
|
||||
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
@ -1069,13 +1068,14 @@
|
||||
|
||||
variants (mapv #(get objects %) (:shapes shape))
|
||||
variant-id (:variant-id (first variants))
|
||||
variant-components (cfv/find-variant-components data objects variant-id)
|
||||
|
||||
malformed-ids (->> variants
|
||||
(filterv #(some? (:variant-error %)))
|
||||
(mapv :id))
|
||||
malformed? (d/not-empty? malformed-ids)
|
||||
|
||||
duplicated-ids (->> (cfv/find-variant-components data objects variant-id)
|
||||
duplicated-ids (->> variant-components
|
||||
get-main-ids-with-duplicated-variant-props-and-values)
|
||||
duplicated? (d/not-empty? duplicated-ids)
|
||||
|
||||
@ -1088,6 +1088,11 @@
|
||||
menu-open* (mf/use-state false)
|
||||
menu-open? (deref menu-open*)
|
||||
|
||||
show-in-assets-panel
|
||||
(mf/use-fn
|
||||
(mf/deps variants)
|
||||
#(st/emit! (dw/show-component-in-assets (:component-id (first variants)))))
|
||||
|
||||
create-variant
|
||||
(mf/use-fn
|
||||
(mf/deps shape)
|
||||
@ -1104,10 +1109,12 @@
|
||||
(dwv/add-new-property variant-id {:property-value "Value 1"
|
||||
:editing? true}))))
|
||||
|
||||
menu-entries [{:title (tr "workspace.shape.menu.add-variant-property")
|
||||
:action (partial add-new-property "design-tab-menu-component")}
|
||||
menu-entries [{:title (tr "workspace.shape.menu.show-in-assets")
|
||||
:action show-in-assets-panel}
|
||||
{:title (tr "workspace.shape.menu.add-variant")
|
||||
:action (partial create-variant "design-tab-menu-component")}]
|
||||
:action (partial create-variant "design-tab-menu-component")}
|
||||
{:title (tr "workspace.shape.menu.add-variant-property")
|
||||
:action (partial add-new-property "design-tab-menu-component")}]
|
||||
|
||||
toggle-content
|
||||
(mf/use-fn
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user