diff --git a/frontend/src/app/main/ui/workspace/sidebar/options.cljs b/frontend/src/app/main/ui/workspace/sidebar/options.cljs index fffd6aa97b..4e303f802c 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options.cljs @@ -115,6 +115,14 @@ (recur (pop queue) visited))) (sequence (keep (d/getf objects)) visited)))) +(defn- editing-existing-path? + "Whether the path `edition` is being edited. The shape can leave the + page while its edit state stays, e.g. deleted by another user or undone; + then there is no path to edit." + [edit-path edition objects] + (and (path.state/editing? edit-path edition) + (contains? objects edition))) + (mf/defc design-menu* {::mf/private true} [{:keys [selected objects page-id file-id shapes]}] @@ -129,7 +137,7 @@ (path.state/current-edit-state edit-path edition) path-editing? - (path.state/editing? edit-path edition) + (editing-existing-path? edit-path edition objects) path-content (dm/get-in drawing [:object :content]) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index 6649d80d2f..e8ca1d8a1b 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -175,6 +175,7 @@ [frontend-tests.ui.mcp-authorize-test] [frontend-tests.ui.measurements-test] [frontend-tests.ui.measures-menu-props-test] + [frontend-tests.ui.options-path-editing-test] [frontend-tests.ui.organization-team-switch-test] [frontend-tests.ui.routes-test] [frontend-tests.ui.settings-password-schema-test] @@ -393,6 +394,7 @@ 'frontend-tests.ui.layout-container-multiple-test 'frontend-tests.ui.measurements-test 'frontend-tests.ui.measures-menu-props-test + 'frontend-tests.ui.options-path-editing-test 'frontend-tests.ui.organization-team-switch-test 'frontend-tests.ui.mcp-authorize-test 'frontend-tests.ui.routes-test diff --git a/frontend/test/frontend_tests/ui/options_path_editing_test.cljs b/frontend/test/frontend_tests/ui/options_path_editing_test.cljs new file mode 100644 index 0000000000..a25050f0b9 --- /dev/null +++ b/frontend/test/frontend_tests/ui/options_path_editing_test.cljs @@ -0,0 +1,33 @@ +;; 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.options-path-editing-test + "The design panel shows the path edition options only while the edited + path is on the page. Its edit state can outlive the shape (deleted by + another user, undone), and the panel crashed on the missing shape." + (:require + [app.common.uuid :as uuid] + [app.main.ui.workspace.sidebar.options :as options] + [cljs.test :as t :include-macros true])) + +(def ^:private editing-existing-path? + @#'options/editing-existing-path?) + +(t/deftest path-editing-while-the-path-is-on-the-page + (let [id (uuid/next) + edit-path {id {:edit-mode :move}} + objects {id {:id id :type :path}}] + (t/is (true? (editing-existing-path? edit-path id objects))))) + +(t/deftest no-path-editing-when-the-edited-path-left-the-page + (let [id (uuid/next) + edit-path {id {:edit-mode :move}}] + (t/is (false? (editing-existing-path? edit-path id {}))))) + +(t/deftest no-path-editing-without-edit-state + (let [id (uuid/next) + objects {id {:id id :type :path}}] + (t/is (false? (editing-existing-path? {} id objects)))))