🐛 Fix select all checkbox on shared link config

This commit is contained in:
Eva 2023-07-04 07:47:12 +02:00 committed by Andrey Antukh
parent 7216a514e6
commit acfeae8638
2 changed files with 49 additions and 37 deletions

View file

@ -38,6 +38,7 @@
- Fix email change: validation error displaying even after both fields are identical [Taiga #5514](https://tree.taiga.io/project/penpot/issue/5514) - Fix email change: validation error displaying even after both fields are identical [Taiga #5514](https://tree.taiga.io/project/penpot/issue/5514)
- Fix scroll on viewer comment list [Taiga #5563](https://tree.taiga.io/project/penpot/issue/5563) - Fix scroll on viewer comment list [Taiga #5563](https://tree.taiga.io/project/penpot/issue/5563)
- Fix context menu z-index [Taiga #5561](https://tree.taiga.io/project/penpot/issue/5561) - Fix context menu z-index [Taiga #5561](https://tree.taiga.io/project/penpot/issue/5561)
- Fix select all checkbox on shared link config [Taiga #5566](https://tree.taiga.io/project/penpot/issue/5566)
### :arrow_up: Deps updates ### :arrow_up: Deps updates

View file

@ -46,13 +46,18 @@
confirm (mf/use-state false) confirm (mf/use-state false)
open-ops (mf/use-state false) open-ops (mf/use-state false)
opts (mf/use-state opts* (mf/use-state
{:pages-mode "current" {:pages-mode "current"
:all-pages false :all-pages false
:pages #{(:id page)} :pages #{(:id page)}
:who-comment "team" :who-comment "team"
:who-inspect "team"}) :who-inspect "team"})
opts (deref opts*)
selected-pages (:pages opts)
file-pages (->> (get-in file [:data :pages])
(map #(get-in file [:data :pages-index %])))
close close
(fn [event] (fn [event]
@ -63,7 +68,7 @@
toggle-all toggle-all
(fn [] (fn []
(reset! confirm false) (reset! confirm false)
(swap! opts (swap! opts*
(fn [state] (fn [state]
(if (= true (:all-pages state)) (if (= true (:all-pages state))
(-> state (-> state
@ -74,23 +79,29 @@
(assoc :pages (into #{} (get-in file [:data :pages])))))))) (assoc :pages (into #{} (get-in file [:data :pages]))))))))
mark-checked-page mark-checked-page
(mf/use-fn
(mf/deps selected-pages)
(fn [event id] (fn [event id]
(let [target (dom/get-target event) (let [target (dom/get-target event)
checked? (.-checked ^js target) not-checked? (.-checked ^js target)
dif-pages? (not= id (first (:pages @opts))) dif-pages? (not= id (first selected-pages))
no-one-page (< 1 (count (:pages @opts))) no-one-page (< 1 (count selected-pages))
should-change (or no-one-page dif-pages?)] should-change (or no-one-page dif-pages?)]
(when should-change (when should-change
(reset! confirm false) (reset! confirm false)
(swap! opts update :pages (swap! opts*
(fn [pages] (fn [state]
(if checked? (let [actual-pages (:pages state)
(conj pages id) updated-pages (if not-checked?
(disj pages id))))))) (conj actual-pages id)
(disj actual-pages id))]
(-> state
(assoc :pages updated-pages)
(assoc :all-pages (= (count updated-pages) (count file-pages)))))))))))
create-link create-link
(fn [_] (fn [_]
(let [params (prepare-params @opts) (let [params (prepare-params opts)
params (assoc params :file-id (:id file))] params (assoc params :file-id (:id file))]
(st/emit! (dc/create-share-link params) (st/emit! (dc/create-share-link params)
(ptk/event ::ev/event {::ev/name "create-shared-link" (ptk/event ::ev/event {::ev/name "create-shared-link"
@ -111,7 +122,7 @@
delete-link delete-link
(fn [_] (fn [_]
(let [params (prepare-params @opts) (let [params (prepare-params opts)
slink (d/seek #(= (:flags %) (:flags params)) slinks)] slink (d/seek #(= (:flags %) (:flags params)) slinks)]
(reset! confirm false) (reset! confirm false)
(st/emit! (dc/delete-share-link slink)))) (st/emit! (dc/delete-share-link slink))))
@ -127,13 +138,13 @@
value (keyword value)] value (keyword value)]
(reset! confirm false) (reset! confirm false)
(if (= type :comment) (if (= type :comment)
(swap! opts assoc :who-comment (d/name value)) (swap! opts* assoc :who-comment (d/name value))
(swap! opts assoc :who-inspect (d/name value)))))] (swap! opts* assoc :who-inspect (d/name value)))))]
(mf/use-effect (mf/use-effect
(mf/deps file slinks @opts) (mf/deps file slinks opts)
(fn [] (fn []
(let [{:keys [pages who-comment who-inspect] :as params} (prepare-params @opts) (let [{:keys [pages who-comment who-inspect] :as params} (prepare-params opts)
slink (d/seek #(and (= (:who-inspect %) who-inspect) (= (:who-comment %) who-comment) (= (:pages %) pages)) slinks) slink (d/seek #(and (= (:who-inspect %) who-inspect) (= (:who-comment %) who-comment) (= (:pages %) pages)) slinks)
href (when slink href (when slink
(let [pparams (:path-params route) (let [pparams (:path-params route)
@ -204,10 +215,10 @@
[:div.title (tr "common.share-link.manage-ops")]] [:div.title (tr "common.share-link.manage-ops")]]
(when @open-ops (when @open-ops
[:* [:*
(let [all-selected? (:all-pages @opts) (let [all-selected? (:all-pages opts)
pages (->> (get-in file [:data :pages]) pages (->> (get-in file [:data :pages])
(map #(get-in file [:data :pages-index %]))) (map #(get-in file [:data :pages-index %])))
selected (:pages @opts)] selected selected-pages]
[:* [:*
[:div.view-mode [:div.view-mode
@ -253,7 +264,7 @@
(tr "common.share-link.permissions-can-comment")] (tr "common.share-link.permissions-can-comment")]
[:div.items [:div.items
[:select.input-select {:on-change (partial on-who-change :comment) [:select.input-select {:on-change (partial on-who-change :comment)
:value (:who-comment @opts)} :value (:who-comment opts)}
[:option {:value "team"} (tr "common.share-link.team-members")] [:option {:value "team"} (tr "common.share-link.team-members")]
[:option {:value "all"} (tr "common.share-link.all-users")]]]] [:option {:value "all"} (tr "common.share-link.all-users")]]]]
[:div.inspect-mode [:div.inspect-mode
@ -262,7 +273,7 @@
(tr "common.share-link.permissions-can-inspect")] (tr "common.share-link.permissions-can-inspect")]
[:div.items [:div.items
[:select.input-select {:on-change (partial on-who-change :inspect) [:select.input-select {:on-change (partial on-who-change :inspect)
:value (:who-inspect @opts)} :value (:who-inspect opts)}
[:option {:value "team"} (tr "common.share-link.team-members")] [:option {:value "team"} (tr "common.share-link.team-members")]
[:option {:value "all"} (tr "common.share-link.all-users")]]]]])]]])) [:option {:value "all"} (tr "common.share-link.all-users")]]]]])]]]))