From 8ce2eb448c935db840a2802ee5c33e7bdd1fd360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 29 Oct 2021 13:05:39 +0200 Subject: [PATCH 1/2] :sparkles: Auto add http prefix to interaction url --- .../partials/sidebar-element-options.scss | 3 ++ .../sidebar/options/menus/interactions.cljs | 20 +++++++++++-- frontend/src/app/util/dom.cljs | 29 ++++++++++++------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/frontend/resources/styles/main/partials/sidebar-element-options.scss b/frontend/resources/styles/main/partials/sidebar-element-options.scss index b3f555d76..68fab3ded 100644 --- a/frontend/resources/styles/main/partials/sidebar-element-options.scss +++ b/frontend/resources/styles/main/partials/sidebar-element-options.scss @@ -207,6 +207,9 @@ border-color: $color-gray-40; } + &.error { + border-color: $color-danger; + } } .input-select { diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs index 881b95236..c4e86847e 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs @@ -199,8 +199,20 @@ change-url (fn [event] - (let [value (-> event dom/get-target dom/get-value)] - (update-interaction index #(cti/set-url % value)))) + (let [target (dom/get-target event) + value (dom/get-value target) + has-prefix? (or (str/starts-with? value "http://") + (str/starts-with? value "https://")) + value (if has-prefix? + value + (str "http://" value))] + (when-not has-prefix? + (dom/set-value! target value)) + (if (dom/valid? target) + (do + (dom/remove-class! target "error") + (update-interaction index #(cti/set-url % value))) + (dom/add-class! target "error")))) change-overlay-pos-type (fn [event] @@ -287,7 +299,9 @@ (when (cti/has-url interaction) [:div.interactions-element [:span.element-set-subtitle.wide (tr "workspace.options.interaction-url")] - [:input.input-text {:default-value (str (:url interaction)) + [:input.input-text {:type "url" + :placeholder "http://example.com" + :default-value (str (:url interaction)) :on-blur change-url}]]) (when (cti/has-overlay-opts interaction) diff --git a/frontend/src/app/util/dom.cljs b/frontend/src/app/util/dom.cljs index b6c50eb1b..309a04b6e 100644 --- a/frontend/src/app/util/dom.cljs +++ b/frontend/src/app/util/dom.cljs @@ -28,17 +28,6 @@ [e] (.-target e)) -(defn classnames - [& params] - (assert (even? (count params))) - (str/join " " (reduce (fn [acc [k v]] - (if (true? (boolean v)) - (conj acc (name k)) - acc)) - [] - (partition 2 params)))) - - ;; --- New methods (defn set-html-title @@ -293,10 +282,28 @@ (defn get-root [] (query globals/document "#app")) +(defn classnames + [& params] + (assert (even? (count params))) + (str/join " " (reduce (fn [acc [k v]] + (if (true? (boolean v)) + (conj acc (name k)) + acc)) + [] + (partition 2 params)))) + (defn ^boolean class? [node class-name] (let [class-list (.-classList ^js node)] (.contains ^js class-list class-name))) +(defn add-class! [node class-name] + (let [class-list (.-classList ^js node)] + (.add ^js class-list class-name))) + +(defn remove-class! [node class-name] + (let [class-list (.-classList ^js node)] + (.remove ^js class-list class-name))) + (defn child? [node1 node2] (.contains ^js node2 ^js node1)) From bff6768adf1ecc097979bc793cb509441f75d940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 29 Oct 2021 13:12:35 +0200 Subject: [PATCH 2/2] :bug: Fix linter error --- frontend/src/app/util/time.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/util/time.cljs b/frontend/src/app/util/time.cljs index b6c470799..c0a28ffa1 100644 --- a/frontend/src/app/util/time.cljs +++ b/frontend/src/app/util/time.cljs @@ -8,13 +8,13 @@ (:require ["date-fns/formatDistanceToNowStrict" :default dateFnsFormatDistanceToNowStrict] ["date-fns/locale/ar-SA" :default dateFnsLocalesAr] - ["date-fns/locale/he" :default dateFnsLocalesHe] ["date-fns/locale/ca" :default dateFnsLocalesCa] ["date-fns/locale/de" :default dateFnsLocalesDe] ["date-fns/locale/el" :default dateFnsLocalesEl] ["date-fns/locale/en-US" :default dateFnsLocalesEnUs] ["date-fns/locale/es" :default dateFnsLocalesEs] ["date-fns/locale/fr" :default dateFnsLocalesFr] + ["date-fns/locale/he" :default dateFnsLocalesHe] ["date-fns/locale/pt-BR" :default dateFnsLocalesPtBr] ["date-fns/locale/ro" :default dateFnsLocalesRo] ["date-fns/locale/ru" :default dateFnsLocalesRu]