Skip to content

Commit

Permalink
Fix/jira templates (#614)
Browse files Browse the repository at this point in the history
* refactor(searchbox): remove case sensitive in the search

* fix(jira): remove required from value in the cmdb

* fix(jira template): clear template after create or update jira template

* fix(jira templates): clear state when update or create

* refactor(jira): remove review.id from presets
  • Loading branch information
rogefm authored Dec 20, 2024
1 parent ec91c0f commit 7c5de6d
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 30 deletions.
10 changes: 6 additions & 4 deletions webapp/src/webapp/components/searchbox.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@

(defn- search-options [options pattern searchable-keys]
(filter #(string/includes?
(string/replace (string/join " " (vals
(select-keys % searchable-keys)))
#"-|_" "")
(string/replace pattern #" |-|_" "")) options))
(string/lower-case
(string/replace (string/join " " (vals
(select-keys % searchable-keys)))
#"-|_" ""))
(string/lower-case
(string/replace pattern #" |-|_" ""))) options))

(defn- search-in-multiple-options [options pattern searchable-keys]
(reduce (fn [acc [list-key list-value]]
Expand Down
40 changes: 32 additions & 8 deletions webapp/src/webapp/events/jira_templates.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
(fn [db [_ template]]
(assoc db :jira-templates->submit-template {:status :ready :data template})))

(rf/reg-event-db
:jira-templates->clear-active-template
(fn [db _]
(assoc db :jira-templates->active-template {:status :ready :data nil})))

(rf/reg-event-db
:jira-templates->clear-submit-template
(fn [db _]
Expand All @@ -57,26 +62,36 @@
(rf/reg-event-fx
:jira-templates->create
(fn [_ [_ template]]
{:fx [[:dispatch
{:fx [[:dispatch [:jira-templates->set-submitting true]]
[:dispatch
[:fetch {:method "POST"
:uri "/integrations/jira/issuetemplates"
:body template
:on-success (fn []
(rf/dispatch [:jira-templates->set-submitting false])
(rf/dispatch [:jira-templates->get-all])
(rf/dispatch [:navigate :jira-templates]))
:on-failure #(println :jira-templates->create template %)}]]]}))
(rf/dispatch [:navigate :jira-templates])
(rf/dispatch [:jira-templates->clear-active-template]))
:on-failure (fn [error]
(rf/dispatch [:show-snackbar {:text error :level :error}])
(rf/dispatch [:jira-templates->set-submitting false]))}]]]}))

(rf/reg-event-fx
:jira-templates->update-by-id
(fn [_ [_ template]]
{:fx [[:dispatch
{:fx [[:dispatch [:jira-templates->set-submitting true]]
[:dispatch
[:fetch {:method "PUT"
:uri (str "/integrations/jira/issuetemplates/" (:id template))
:body template
:on-success (fn []
(rf/dispatch [:jira-templates->set-submitting false])
(rf/dispatch [:jira-templates->get-all])
(rf/dispatch [:navigate :jira-templates]))
:on-failure #(println :jira-templates->update-by-id template %)}]]]}))
(rf/dispatch [:navigate :jira-templates])
(rf/dispatch [:jira-templates->clear-active-template]))
:on-failure (fn [error]
(rf/dispatch [:show-snackbar {:text error :level :error}])
(rf/dispatch [:jira-templates->set-submitting false]))}]]]}))

(rf/reg-event-fx
:jira-templates->delete-by-id
Expand All @@ -86,8 +101,12 @@
:uri (str "/integrations/jira/issuetemplates/" id)
:on-success (fn []
(rf/dispatch [:jira-templates->get-all])
(rf/dispatch [:navigate :jira-templates]))
:on-failure #(println :jira-templates->delete-by-id id %)}]]]}))
(rf/dispatch [:navigate :jira-templates]))}]]]}))

(rf/reg-event-db
:jira-templates->set-submitting
(fn [db [_ value]]
(assoc-in db [:jira-templates :submitting?] value)))

;; Subs
(rf/reg-sub
Expand All @@ -104,3 +123,8 @@
:jira-templates->submit-template
(fn [db _]
(:jira-templates->submit-template db)))

(rf/reg-sub
:jira-templates->submitting?
(fn [db]
(get-in db [:jira-templates :submitting?])))
10 changes: 5 additions & 5 deletions webapp/src/webapp/jira_templates/basic_info.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
[:> Box {:class "space-y-radix-7" :grid-column "span 5 / span 5"}
[forms/input
{:label "Name"
:placeholder "banking+prod_mongpdb"
:placeholder "e.g. squad-postgresql"
:required true
:value @name
:on-change #(on-name-change (-> % .-target .-value))}]

[forms/input
{:label "Description (Optional)"
:placeholder "Describe how this is used in your connections"
:placeholder "Describe how this templated will be used."
:required false
:value @description
:on-change #(on-description-change (-> % .-target .-value))}]

[forms/input
{:label "Project Key"
:placeholder "PKEY"
:placeholder "e.g. PKEY"
:required true
:value @project-key
:on-change #(on-project-key-change (-> % .-target .-value))}]

[:div
[forms/input
{:label "Request Type"
:placeholder "Name"
{:label "Request Type ID"
:placeholder "e.g. 10005"
:required true
:value @issue-type
:not-margin-bottom? true
Expand Down
15 changes: 10 additions & 5 deletions webapp/src/webapp/jira_templates/create_update_form.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

(defn jira-form [form-type template scroll-pos]
(let [state (helpers/create-form-state template)
handlers (helpers/create-form-handlers state)]
handlers (helpers/create-form-handlers state)
submitting? (rf/subscribe [:jira-templates->submitting?])]
(fn []
[:> Box {:class "min-h-screen bg-gray-1"}
[:form {:id "jira-form"
Expand All @@ -27,7 +28,8 @@
[form-header/main
{:form-type form-type
:id @(:id state)
:scroll-pos scroll-pos}]
:scroll-pos scroll-pos
:loading? @submitting?}]

[:> Box {:p "7" :class "space-y-radix-9"}
[basic-info/main
Expand Down Expand Up @@ -117,6 +119,9 @@
(finally
(.removeEventListener js/window "scroll" handle-scroll)))

(if (= :loading (:status @jira-template))
[loading]
[jira-form form-type (:data @jira-template) scroll-pos]))))
(r/with-let [_ nil]
(if (= :loading (:status @jira-template))
[loading]
[jira-form form-type (:data @jira-template) scroll-pos])
(finally
(rf/dispatch [:jira-templates->clear-active-template]))))))
5 changes: 4 additions & 1 deletion webapp/src/webapp/jira_templates/form_header.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[webapp.components.button :as button]
[re-frame.core :as rf]))

(defn main [{:keys [form-type id scroll-pos]}]
(defn main [{:keys [form-type loading? id scroll-pos]}]
[:<>
[:> Flex {:p "5" :gap "2"}
[button/HeaderBack]]
Expand All @@ -22,9 +22,12 @@
[:> Button {:size "4"
:variant "ghost"
:color "red"
:disabled loading?
:type "button"
:on-click #(rf/dispatch [:jira-templates->delete-by-id id])}
"Delete"])
[:> Button {:size "3"
:loading loading?
:disabled loading?
:type "submit"}
"Save"]]]]])
1 change: 0 additions & 1 deletion webapp/src/webapp/jira_templates/helpers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@
(defn remove-empty-cmdb [cmdbs]
(remove (fn [cmdb]
(or (empty? (:label cmdb))
(empty? (:value cmdb))
(empty? (:jira_field cmdb))
(empty? (:jira_object_type cmdb))))
cmdbs))
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/webapp/jira_templates/mapping_table.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
{:value "session.connection" :text "Connection name"}
{:value "session.status" :text "Session status"}
{:value "session.start_date" :text "Session start date"}
{:value "session.verb" :text "Session type"}])
{:value "session.verb" :text "Session type"}
{:value "session.script" :text "Session Script"}])

(defn- value-field [rule state idx on-rule-field-change]
(when-not (empty? (:type rule))
Expand Down Expand Up @@ -117,7 +118,7 @@
"Relates hoop.dev fields with Jira fields. "
[:> Strong
"Custom: "]
"Append a custom key-value relation to Jira cards."]]
"Appends a custom key-value relation to Jira cards."]]

[rule-buttons/main
{:on-rule-add #(on-mapping-add state)
Expand Down
2 changes: 0 additions & 2 deletions webapp/src/webapp/jira_templates/prompt_form.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
;; Prompt Fields
(when (seq prompts)
[:> Box {:class "space-y-4"}
[:> Text {:as "h4" :size "3" :weight "medium" :mb "2"} "Command Information"]
(for [{:keys [label required jira_field]} prompts]
^{:key jira_field}
[forms/input
Expand All @@ -54,7 +53,6 @@
(not (some #(= (:name %) value) jira_values))))
cmdb-items))]
[:> Box {:class "space-y-4"}
[:> Text {:as "h4" :size "3" :weight "medium" :mb "2"} "CMDB Information"]
(doall
(for [{:keys [label jira_field jira_values required]} cmdb-fields-to-show]
^{:key jira_field}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/webapp/jira_templates/prompts_table.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns webapp.jira-templates.prompts-table
(:require
["@radix-ui/themes" :refer [Box Table Text]]
["@radix-ui/themes" :refer [Box Table]]
[webapp.components.forms :as forms]
[webapp.jira-templates.rule-buttons :as rule-buttons]))

Expand Down
1 change: 0 additions & 1 deletion webapp/src/webapp/webclient/panel.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@

(letfn [(handle-submit [form-data]
(rf/dispatch [:modal->close])
(rf/dispatch [:jira-templates->clear-submit-template])
(let [exec-data {:script final-script
:connection-name (:name connection)
:metadata (metadata->json-stringify metadata)}
Expand Down

0 comments on commit 7c5de6d

Please sign in to comment.