From 934cdb85321e95d88df9a1d288ee53913f6bff1f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 19 Nov 2026 09:59:16 +0100 Subject: [PATCH] :bug: List each file once when deleting libraries it uses Deleting or unpublishing several libraries at once listed a file that uses more than one of them once per library, and React logged a duplicate key error for the repeated rows. The references of each library were joined without removing repeated files. The dialog now lists each file once (`distinct-references`). Found by the components Qase run (PENPOT-1473). Test: `delete-shared-test`. AI-assisted-by: claude-opus-5-5 --- frontend/src/app/main/ui/delete_shared.cljs | 8 ++++++++ frontend/test/frontend_tests/runner.cljs | 2 ++ .../frontend_tests/ui/delete_shared_test.cljs | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 frontend/test/frontend_tests/ui/delete_shared_test.cljs diff --git a/frontend/src/app/main/ui/delete_shared.cljs b/frontend/src/app/main/ui/delete_shared.cljs index 4acd9b066d..f16be9f21a 100644 --- a/frontend/src/app/main/ui/delete_shared.cljs +++ b/frontend/src/app/main/ui/delete_shared.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.delete-shared (:require-macros [app.main.style :as stl]) (:require + [app.common.data :as d] [app.common.data.macros :as dm] [app.main.data.modal :as modal] [app.main.repo :as rp] @@ -24,6 +25,12 @@ (def ^:private noop (constantly nil)) +(defn- distinct-references + "The `[file-id file-name]` pairs of `references` without repeated files: a + file that uses several of the libraries is listed once." + [references] + (into [] (d/distinct-xf first) references)) + (mf/defc delete-shared-dialog {::mf/register modal/components ::mf/register-as :delete-shared-libraries @@ -84,6 +91,7 @@ (rx/mapcat identity) (rx/map (juxt :id :name)) (rx/reduce conj []) + (rx/map distinct-references) (rx/subs! #(reset! references* %)))) (mf/with-effect [accept-fn] diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index f7fc1a5877..00fed64f24 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -190,6 +190,7 @@ [frontend-tests.ui.context-menu-prototype-test] [frontend-tests.ui.dashboard-import-errors-test] [frontend-tests.ui.dashboard-import-linking-test] + [frontend-tests.ui.delete-shared-test] [frontend-tests.ui.drawarea-test] [frontend-tests.ui.ds-controls-numeric-input-test] [frontend-tests.ui.ds-input-with-meta-test] @@ -448,6 +449,7 @@ 'frontend-tests.ui.context-menu-prototype-test 'frontend-tests.ui.dashboard-import-errors-test 'frontend-tests.ui.dashboard-import-linking-test + 'frontend-tests.ui.delete-shared-test 'frontend-tests.ui.drawarea-test 'frontend-tests.ui.ds-controls-numeric-input-test 'frontend-tests.ui.ds-input-with-meta-test diff --git a/frontend/test/frontend_tests/ui/delete_shared_test.cljs b/frontend/test/frontend_tests/ui/delete_shared_test.cljs new file mode 100644 index 0000000000..28b6018152 --- /dev/null +++ b/frontend/test/frontend_tests/ui/delete_shared_test.cljs @@ -0,0 +1,20 @@ +;; 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) KALEIDOS SUBSIDIARY SL + +(ns frontend-tests.ui.delete-shared-test + (:require + [app.common.uuid :as uuid] + [app.main.ui.delete-shared :as delete-shared] + [cljs.test :as t :include-macros true])) + +(def ^:private distinct-references + @#'delete-shared/distinct-references) + +(t/deftest a-file-using-several-of-the-libraries-is-listed-once + (let [file-a (uuid/next) + file-b (uuid/next)] + (t/is (= [[file-a "File A"] [file-b "File B"]] + (distinct-references [[file-a "File A"] [file-b "File B"] [file-a "File A"]])))))