From e44ea47497f684ead207cb7bb1332b1acb96b417 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 9 Dec 2021 17:35:05 +0100 Subject: [PATCH] :bug: Fix issue when typography name is empty. --- common/src/app/common/pages/helpers.cljc | 2 +- common/test/app/common/pages_helpers_test.cljc | 9 +++++++++ frontend/src/app/main/data/workspace/libraries.cljs | 10 +++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 7f071576d..5dee3e165 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -441,7 +441,7 @@ [path-name] (let [path-name-split (split-path path-name) path (str/join " / " (butlast path-name-split)) - name (last path-name-split)] + name (or (last path-name-split) "")] [path name])) (defn merge-path-item diff --git a/common/test/app/common/pages_helpers_test.cljc b/common/test/app/common/pages_helpers_test.cljc index 34bc3e3cb..058ff6422 100644 --- a/common/test/app/common/pages_helpers_test.cljc +++ b/common/test/app/common/pages_helpers_test.cljc @@ -48,3 +48,12 @@ [:a :b :c :d])) ) + + +(t/deftest parse-path-name + (t/is (= ["foo" "bar"] (cph/parse-path-name "foo/bar"))) + (t/is (= ["" "foo"] (cph/parse-path-name "foo"))) + (t/is (= ["" "foo"] (cph/parse-path-name "/foo"))) + (t/is (= ["" ""] (cph/parse-path-name ""))) + (t/is (= ["" ""] (cph/parse-path-name nil))) + ) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index adbbb5672..3458ae1d4 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -242,11 +242,11 @@ (watch [it state _] (let [[path name] (cp/parse-path-name (:name typography)) typography (assoc typography :path path :name name) - prev (get-in state [:workspace-data :typographies (:id typography)]) - rchg {:type :mod-typography - :typography typography} - uchg {:type :mod-typography - :typography prev}] + prev (get-in state [:workspace-data :typographies (:id typography)]) + rchg {:type :mod-typography + :typography typography} + uchg {:type :mod-typography + :typography prev}] (rx/of (dwu/start-undo-transaction) (dch/commit-changes {:redo-changes [rchg] :undo-changes [uchg]