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

Add info in modal

This commit is contained in:
Eva 2022-07-01 07:50:44 +02:00 committed by Andrés Moya
parent a5bf1c03e7
commit c108974ad2
19 changed files with 327 additions and 58 deletions

View file

@ -384,7 +384,7 @@
(s/def ::file-data-for-thumbnail
(s/keys :req-un [::profile-id ::file-id]
:opt-in [::components-v2]))
:opt-un [::components-v2]))
(sv/defmethod ::file-data-for-thumbnail
"Retrieves the data for generate the thumbnail of the file. Used
@ -464,6 +464,24 @@
(check-read-permissions! pool profile-id file-id)
(retrieve-file-libraries cfg false file-id))
;; --- Query: Files that use this File library
(def ^:private sql:library-using-files
"SELECT f.id,
f.name
FROM file_library_rel AS flr
INNER JOIN file AS f ON f.id = flr.file_id
WHERE flr.library_file_id = ?;")
(s/def ::library-using-files
(s/keys :req-un [::profile-id ::file-id]))
(sv/defmethod ::library-using-files
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
(check-read-permissions! pool profile-id file-id)
(db/exec! pool [sql:library-using-files file-id]))
;; --- QUERY: team-recent-files
(def sql:team-recent-files

View file

@ -15,14 +15,7 @@
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf]
[app.common.types.page :as ctp]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
[cuerdas.core :as str]))

View file

@ -4,9 +4,7 @@
;;
;; Copyright (c) UXBOX Labs SL
(ns app.common.types.colors-list
(:require
[app.common.data :as d]))
(ns app.common.types.colors-list)
(defn colors-seq
[file-data]

View file

@ -20,8 +20,8 @@
[app.common.types.page :as ctp]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape-tree :as ctst]
[app.common.types.typography :as cty]
[app.common.types.typographies-list :as ctyl]
[app.common.types.typography :as cty]
[app.common.uuid :as uuid]
[clojure.spec.alpha :as s]
[cuerdas.core :as str]))
@ -155,11 +155,11 @@
[[container instances]])))
find-asset-usages
(fn [file-data library-id asset-type asset]
(fn [file-data asset]
(mapcat #(find-usages-in-container % asset) (containers-seq file-data)))]
(mapcat (fn [asset]
(let [instances (find-asset-usages file-data (:id library-data) asset-type asset)]
(let [instances (find-asset-usages file-data asset)]
(when (d/not-empty? instances)
[[asset instances]])))
assets-seq)))
@ -252,7 +252,7 @@
(assoc-in [:options :components-v2] true))))))
(defn- absorb-components
[file-data library-data used-components]
[file-data used-components]
(let [grid-gap 50
; Search for the library page. If not exists, create it.
@ -336,7 +336,7 @@
(add-component-grid file-data (sort-by #(:name (first %)) used-components))))
(defn- absorb-colors
[file-data library-data used-colors]
[file-data used-colors]
(let [absorb-color
(fn [file-data [color usages]]
(let [remap-shape #(ctc/remap-colors % (:id file-data) color)
@ -360,7 +360,7 @@
used-colors)))
(defn- absorb-typographies
[file-data library-data used-typographies]
[file-data used-typographies]
(let [absorb-typography
(fn [file-data [typography usages]]
(let [remap-shape #(cty/remap-typographies % (:id file-data) typography)
@ -393,13 +393,13 @@
(cond-> file-data
(d/not-empty? used-components)
(absorb-components library-data used-components)
(absorb-components used-components)
(d/not-empty? used-colors)
(absorb-colors library-data used-colors)
(absorb-colors used-colors)
(d/not-empty? used-typographies)
(absorb-typographies library-data used-typographies))))
(absorb-typographies used-typographies))))
;; Debug helpers

View file

@ -4,9 +4,7 @@
;;
;; Copyright (c) UXBOX Labs SL
(ns app.common.types.typographies-list
(:require
[app.common.data :as d]))
(ns app.common.types.typographies-list)
(defn typographies-seq
[file-data]

View file

@ -134,6 +134,12 @@
font-size: $fs16;
font-weight: 400;
}
&.delete-shared {
padding: 15px 32px;
.modal-item-element {
font-size: $fs16;
}
}
}
.modal-footer {

View file

@ -18,6 +18,7 @@
[app.main.ui :as ui]
[app.main.ui.alert]
[app.main.ui.confirm]
[app.main.ui.delete-shared]
[app.main.ui.modal :refer [modal]]
[app.main.ui.routes :as rt]
[app.main.worker :as worker]

View file

@ -247,6 +247,32 @@
(->> (rp/query :team-shared-files {:team-id team-id})
(rx/map shared-files-fetched))))))
;; --- EVENT: Get files that use this shared-file
(defn clean-temp-shared
[]
(ptk/reify ::clean-temp-shared
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:dashboard-local :files-with-shared] nil))))
(defn library-using-files-fetched
[files]
(ptk/reify ::library-using-files-fetched
ptk/UpdateEvent
(update [_ state]
(let [files (d/index-by :id files)]
(assoc-in state [:dashboard-local :files-with-shared] files)))))
(defn fetch-library-using-files
[file]
(ptk/reify ::fetch-library-using-files
ptk/WatchEvent
(watch [_ _ _]
(let [file-id (:id file)]
(->> (rp/query :library-using-files {:file-id file-id})
(rx/map library-using-files-fetched))))))
;; --- EVENT: recent-files
(defn recent-files-fetched

View file

@ -11,7 +11,6 @@
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.shape :as cts]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu]

View file

@ -686,7 +686,7 @@
:library-id library-id})))
(when (and (seq (:redo-changes library-changes))
sync-components?)
(rx/of (sync-file-2nd-stage file-id library-id))))))))))
(rx/of (sync-file-2nd-stage file-id library-id asset-id))))))))))
(defn- sync-file-2nd-stage
"If some components have been modified, we need to launch another synchronization

View file

@ -9,14 +9,13 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.proportions :as gpr]
[app.common.pages :as cp]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.page :as ctp]
[app.common.types.shape :as cts]
[app.common.types.shape.interactions :as ctsi]
[app.common.types.shape-tree :as ctst]
[app.common.types.shape.interactions :as ctsi]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.edition :as dwe]

View file

@ -92,19 +92,26 @@
on-delete
(fn [event]
(dom/stop-propagation event)
(if multi?
(st/emit! (modal/show
{:type :confirm
:title (tr "modals.delete-file-multi-confirm.title" file-count)
:message (tr "modals.delete-file-multi-confirm.message" file-count)
:accept-label (tr "modals.delete-file-multi-confirm.accept" file-count)
:on-accept delete-fn}))
(st/emit! (modal/show
{:type :confirm
:title (tr "modals.delete-file-confirm.title")
:message (tr "modals.delete-file-confirm.message")
:accept-label (tr "modals.delete-file-confirm.accept")
:on-accept delete-fn}))))
(if (:is-shared file)
(do (st/emit! (dd/fetch-library-using-files file))
(st/emit! (modal/show
{:type :delete-shared
:origin :delete
:on-accept delete-fn})))
(if multi?
(st/emit! (modal/show
{:type :confirm
:title (tr "modals.delete-file-multi-confirm.title" file-count)
:message (tr "modals.delete-file-multi-confirm.message" file-count)
:accept-label (tr "modals.delete-file-multi-confirm.accept" file-count)
:on-accept delete-fn}))
(st/emit! (modal/show
{:type :confirm
:title (tr "modals.delete-file-confirm.title")
:message (tr "modals.delete-file-confirm.message")
:accept-label (tr "modals.delete-file-confirm.accept")
:on-accept delete-fn})))))
on-move-success
(fn [team-id project-id]
@ -148,13 +155,10 @@
(fn [event]
(dom/prevent-default event)
(dom/stop-propagation event)
(st/emit! (dd/fetch-library-using-files file))
(st/emit! (modal/show
{:type :confirm
:message ""
:title (tr "modals.remove-shared-confirm.message" (:name file))
:hint (tr "modals.remove-shared-confirm.hint")
:cancel-label :omit
:accept-label (tr "modals.remove-shared-confirm.accept")
{:type :delete-shared
:origin :unpublish
:on-accept del-shared})))
on-export-files
@ -233,7 +237,7 @@
(when (or (seq current-projects) (seq other-teams))
[(tr "dashboard.move-to") nil sub-options "file-move-to"])
(if (:is-shared file)
[(tr "dashboard.remove-shared") on-del-shared nil "file-del-shared"]
[(tr "dashboard.unpublish-shared") on-del-shared nil "file-del-shared"]
[(tr "dashboard.add-shared") on-add-shared nil "file-add-shared"])
[:separator]
[(tr "dashboard.download-binary-file") on-export-binary-files nil "download-binary-file"]

View file

@ -127,5 +127,6 @@
[:section.dashboard-container
[:& grid {:project project
:files files
:on-create-clicked on-create-clicked}]]]))
:on-create-clicked on-create-clicked
:origin :files}]]]))

View file

@ -75,12 +75,13 @@
(mf/defc grid-item
{:wrap [mf/memo]}
[{:keys [file navigate?] :as props}]
[{:keys [file navigate? origin] :as props}]
(let [file-id (:id file)
local (mf/use-state {:menu-open false
:menu-pos nil
:edition false})
selected-files (mf/deref refs/dashboard-selected-files)
dashboard-local (mf/deref refs/dashboard-local)
item-ref (mf/use-ref)
menu-ref (mf/use-ref)
selected? (contains? selected-files file-id)
@ -205,10 +206,12 @@
:top (:y (:menu-pos @local))
:navigate? navigate?
:on-edit on-edit
:on-menu-close on-menu-close}])]]]))
:on-menu-close on-menu-close
:origin origin
:dashboard-local dashboard-local}])]]]))
(mf/defc grid
[{:keys [files project on-create-clicked] :as props}]
[{:keys [files project on-create-clicked origin] :as props}]
(let [dragging? (mf/use-state false)
project-id (:id project)
@ -268,7 +271,8 @@
[:& grid-item
{:file item
:key (:id item)
:navigate? true}])]
:navigate? true
:origin origin}])]
:else
[:& empty-placeholder {:default? (:is-default project)
@ -276,7 +280,7 @@
:project project}])]))
(mf/defc line-grid-row
[{:keys [files selected-files on-load-more dragging?] :as props}]
[{:keys [files selected-files on-load-more dragging? origin] :as props}]
(let [rowref (mf/use-ref)
width (mf/use-state nil)
@ -322,7 +326,8 @@
:file item
:selected-files selected-files
:key (:id item)
:navigate? false}])
:navigate? false
:origin origin}])
(when (and (> limit 0)
(> (count files) limit))
[:div.grid-item.placeholder {:on-click on-load-more}
@ -331,7 +336,7 @@
(tr "dashboard.show-all-files")]])]))
(mf/defc line-grid
[{:keys [project team files on-load-more on-create-clicked] :as props}]
[{:keys [project team files on-load-more on-create-clicked origin] :as props}]
(let [dragging? (mf/use-state false)
project-id (:id project)
team-id (:id team)
@ -415,7 +420,8 @@
:team-id team-id
:selected-files selected-files
:on-load-more on-load-more
:dragging? @dragging?}]
:dragging? @dragging?
:origin origin}]
:else
[:& empty-placeholder {:dragging? @dragging?

View file

@ -42,5 +42,6 @@
[:h1 (tr "dashboard.libraries-title")]]]
[:section.dashboard-container
[:& grid {:files files
:project default-project}]]]))
:project default-project
:origin :libraries}]]]))

View file

@ -153,7 +153,8 @@
:team team
:on-load-more on-nav
:files files
:on-create-clicked (partial create-file "dashboard:empty-folder-placeholder")}]]))
:on-create-clicked (partial create-file "dashboard:empty-folder-placeholder")
:origin :project}]]))
(def recent-files-ref
(l/derived :dashboard-recent-files st/state))

View file

@ -0,0 +1,117 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) UXBOX Labs SL
(ns app.main.ui.delete-shared
(:require
[app.main.data.dashboard :as dd]
[app.main.data.modal :as modal]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as k]
[goog.events :as events]
[rumext.alpha :as mf])
(:import goog.events.EventType))
(mf/defc delete-shared-dialog
{::mf/register modal/components
::mf/register-as :delete-shared}
[{:keys [on-accept
on-cancel
accept-style
origin] :as props}]
(let [on-accept (or on-accept identity)
on-cancel (or on-cancel identity)
cancel-label (tr "labels.cancel")
accept-style (or accept-style :danger)
is-delete? (= origin :delete)
dashboard-local (mf/deref refs/dashboard-local)
files->shared (:files-with-shared dashboard-local)
count-files (count (keys files->shared))
title (if is-delete?
(tr "modals.delete-shared-confirm.title")
(tr "modals.unpublish-shared-confirm.title"))
message (if is-delete?
(tr "modals.delete-shared-confirm.message")
(tr "modals.unpublish-shared-confirm.message"))
accept-label (if is-delete?
(tr "modals.delete-shared-confirm.accept")
(tr "modals.unpublish-shared-confirm.accept"))
scd-message (if is-delete?
(tr "modals.delete-shared-confirm.scd-message" (i18n/c count-files))
(tr "modals.unpublish-shared-confirm.scd-message" (i18n/c count-files)))
hint (if is-delete?
""
(tr "modals.unpublish-shared-confirm.hint" (i18n/c count-files)))
accept-fn
(mf/use-callback
(fn [event]
(dom/prevent-default event)
(st/emit! (modal/hide))
(on-accept props)))
cancel-fn
(mf/use-callback
(fn [event]
(dom/prevent-default event)
(st/emit! (modal/hide))
(on-cancel props)))]
(mf/with-effect
(letfn [(on-keydown [event]
(when (k/enter? event)
(dom/prevent-default event)
(dom/stop-propagation event)
(st/emit! (modal/hide))
(on-accept props)))]
(->> (events/listen js/document EventType.KEYDOWN on-keydown)
(partial events/unlistenByKey)))
#(st/emit! (dd/clean-temp-shared)))
[:div.modal-overlay
[:div.modal-container.confirm-dialog
[:div.modal-header
[:div.modal-header-title
[:h2 title]]
[:div.modal-close-button
{:on-click cancel-fn} i/close]]
[:div.modal-content.delete-shared
(when (and (string? message) (not= message ""))
[:h3 message])
(when (> (count files->shared) 0)
[:*
[:div
(when (and (string? scd-message) (not= scd-message ""))
[:h3 scd-message])
[:ul.file-list
(for [[id file] files->shared]
[:li.modal-item-element
{:key id}
[:span "- " (:name file)]])]]
(when (and (string? hint) (not= hint ""))
[:h3 hint])])]
[:div.modal-footer
[:div.action-buttons
(when-not (= cancel-label :omit)
[:input.cancel-button
{:type "button"
:value cancel-label
:on-click cancel-fn}])
[:input.accept-button
{:class (dom/classnames
:danger (= accept-style :danger)
:primary (= accept-style :primary))
:type "button"
:value accept-label
:on-click accept-fn}]]]]]))

View file

@ -539,6 +539,10 @@ msgstr "Want to remove your account?"
msgid "dashboard.remove-shared"
msgstr "Remove as Shared Library"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "dashboard.unpublish-shared"
msgstr "Unpublish Library"
#: src/app/main/ui/settings/profile.cljs
msgid "dashboard.save-settings"
msgstr "Save settings"
@ -1775,6 +1779,49 @@ msgstr ""
msgid "modals.remove-shared-confirm.message"
msgstr "Remove “%s” as Shared Library"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.title"
msgstr "Unpublish library"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.message"
msgstr "Are you sure you want to unpublish this library?"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.scd-message"
msgid_plural "modals.unpublish-shared-confirm.scd-message"
msgstr[0] "It's in use in this file:"
msgstr[1] "It's in use in these files:"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.hint"
msgid_plural "modals.unpublish-shared-confirm.hint"
msgstr[0] "If you unpublish it, the assets in it became a library of this file."
msgstr[1] "If you unpublish it, the assets in it became a library of these files."
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.accept"
msgstr "Unpublish"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.title"
msgstr "Deleting file"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.message"
msgstr "Are you sure you want to delete this file?"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.scd-message"
msgid_plural "modals.delete-shared-confirm.scd-message"
msgstr[0] "This file has libraries that are being used in this file:"
msgstr[1] "This file has libraries that are being used in these files:"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.accept"
msgstr "Delete file"
#: src/app/main/ui/workspace/nudge.cljs
msgid "modals.small-nudge"
msgstr "Small nudge"
@ -1807,6 +1854,10 @@ msgstr ""
msgid "modals.update-remote-component.message"
msgstr "Update a component in a shared library"
#: src/app/main/ui/delete_shared.cljs
msgid "modals.delete-shared.title"
msgstr "Deleting file"
#: src/app/main/ui/dashboard/team.cljs
msgid "notifications.invitation-email-sent"
msgstr "Invitation sent successfully"

View file

@ -551,6 +551,10 @@ msgstr "¿Quieres borrar tu cuenta?"
msgid "dashboard.remove-shared"
msgstr "Eliminar como Biblioteca Compartida"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "dashboard.unpublish-shared"
msgstr "Despublicar Biblioteca"
#: src/app/main/ui/settings/profile.cljs
msgid "dashboard.save-settings"
msgstr "Guardar opciones"
@ -1849,6 +1853,48 @@ msgstr ""
msgid "modals.remove-shared-confirm.message"
msgstr "Añadir “%s” como Biblioteca Compartida"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.title"
msgstr "Despublicar biblioteca"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.message"
msgstr "¿Seguro que quieres despublicar esta biblioteca?"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.scd-message"
msgid_plural "modals.unpublish-shared-confirm.scd-message"
msgstr[0] "Está siendo usada en este archivo:"
msgstr[1] "Está siendo usada en estos archivos:"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.hint"
msgid_plural "modals.unpublish-shared-confirm.hint"
msgstr[0] "Si la despublicas, los elementos pasarán a formar parte de la biblioteca del archivo."
msgstr[1] "Si la despublicas, los elementos pasarán a formar parte de la biblioteca de los archivos."
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.unpublish-shared-confirm.accept"
msgstr "Despublicar"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.title"
msgstr "Borrar archivo"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.message"
msgstr "¿Seguro que quieres borrar este archivo?"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.scd-message"
msgid_plural "modals.delete-shared-confirm.scd-message"
msgstr[0] "El archivo que quieres borrar tiene una librería que se está usando en este archivo:"
msgstr[1] "El archivo que quieres borrar tiene una librería que se está usando en estos archivos:"
#: src/app/main/ui/workspace/header.cljs, src/app/main/ui/dashboard/file_menu.cljs
msgid "modals.delete-shared-confirm.accept"
msgstr "Borrar archivo"
#: src/app/main/ui/workspace/nudge.cljs
msgid "modals.small-nudge"
msgstr "Mínimo"
@ -1887,6 +1933,10 @@ msgstr ""
msgid "modals.update-remote-component.message"
msgstr "Actualizar un componente en librería"
#: src/app/main/ui/delete_shared.cljs
msgid "modals.delete-shared.title"
msgstr "Borrar archivo"
#: src/app/main/ui/dashboard/team.cljs
msgid "notifications.invitation-email-sent"
msgstr "Invitación enviada con éxito"