Skip to content

Commit

Permalink
refactor(jira templates): change UX of jira template (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogefm authored Jan 7, 2025
1 parent 2b182a3 commit 216ab21
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 91 deletions.
2 changes: 1 addition & 1 deletion common/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
var (
allowedLicenseTypes = []string{OSSType, EnterpriseType}

ErrNotValid = errors.New("license is not valid, contact your administrator our or support at https://help.hoop.dev")
ErrNotValid = errors.New("license is not valid, contact your administrator or our support at https://help.hoop.dev")
ErrDataMaskingUnsupported = errors.New("data masking is enabled for this connection but is not supported with the open source license, disable it or contact our support at https://help.hoop.dev")
ErrWebhooksUnsupported = errors.New("webhooks is enabled for this connection but is not supported with the open source license, disable it or contact our support at https://help.hoop.dev")
ErrUsedBeforeIssued = errors.New("license used before issued")
Expand Down
2 changes: 1 addition & 1 deletion gateway/api/connections/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ dbs.databases.forEach(function(database) {
"database_name": database.name
});
});
printjson(result);`
JSON.stringify(result);`

default:
log.Warnf("unsupported database type: %v", currentConnectionType)
Expand Down
2 changes: 1 addition & 1 deletion gateway/api/connections/queries_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,5 @@ db.getSiblingDB(dbName).getCollectionNames().forEach(function(collName) {
});
});
printjson(result);`, dbName)
JSON.stringify(result);`, dbName)
}
2 changes: 1 addition & 1 deletion gateway/api/integrations/issuetemplates.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func cmdbTypesWithExternalObjects(ctx *gin.Context, config *models.JiraIntegrati
return nil, fmt.Errorf("jira_object_type is missing, record=%v, item=%#v", i, item)
}
objectType := fmt.Sprintf("%v", item["jira_object_type"])
responseItems, err := jira.FetchObjectsByAQL(config, `objectType = %q`, objectType)
responseItems, err := jira.FetchObjectsByAQL(config, `objectTypeId = %q`, objectType)
if err != nil {
return nil, fmt.Errorf("record=%v, %v", i, err)
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/jira/assetsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

const (
baseAssetsAPI string = "https://api.atlassian.com/jsm/assets/workspace"
defaultMaxResults int = 10
defaultMaxResults int = 50
maxPaginationRequests int = 50
)

Expand Down
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webapp",
"version": "1.35.4",
"version": "1.35.5",
"scripts": {
"ancient": "clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version \"RELEASE\"}}}' -m antq.core",
"genversion": "npx genversion src/webapp/version.js",
Expand Down
19 changes: 8 additions & 11 deletions webapp/src/webapp/events/database_schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,18 @@
(:databases response)]))}]]]}))

(rf/reg-event-db
:database-schema->set-multi-databases
(fn [db [_ connection databases]]
(-> db
(assoc-in [:database-schema :data (:connection-name connection) :databases] databases)
(assoc-in [:database-schema :data (:connection-name connection) :status] :success))))

(rf/reg-event-fx
:database-schema->set-schema-error-size-exceeded
(fn [{:keys [db]} [_ connection error]]
{:db (-> db
;; Mark the general status as error
(assoc-in [:database-schema :data (:connection-name connection) :status] :error)
(assoc-in [:database-schema :data (:connection-name connection) :status] :success)
;; Mark the schema status as error
(assoc-in [:database-schema :data (:connection-name connection) :database-schema-status] :error)
;; Define the error message
Expand All @@ -112,16 +119,6 @@
:on-failure (fn [error]
(rf/dispatch [:database-schema->set-schema-error-size-exceeded connection error]))}]]]}))

(rf/reg-event-fx
:database-schema->set-schema-error-size-exceeded
(fn [{:keys [db]} [_ connection error]]
{:db (-> db
;; Marca só o schema como error
(assoc-in [:database-schema :data (:connection-name connection) :database-schema-status] :error)
;; Define a mensagem de erro
(assoc-in [:database-schema :data (:connection-name connection) :error]
(or error "Schema size too large to display.")))}))

(rf/reg-event-fx
:database-schema->get-multi-database-schema
(fn [{:keys [db]} [_ connection database databases]]
Expand Down
15 changes: 8 additions & 7 deletions webapp/src/webapp/events/jira_templates.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
(rf/reg-event-fx
:jira-templates->get-submit-template
(fn [{:keys [db]} [_ id]]
{:db (assoc db :jira-templates->submit-template {:status :loading
:data {}})
:fx [[:dispatch
[:fetch {:method "GET"
:uri (str "/integrations/jira/issuetemplates/" id "?expand=cmdbtype-values")
:on-success #(rf/dispatch [:jira-templates->set-submit-template %])
:on-failure #(rf/dispatch [:jira-templates->set-submit-template nil])}]]]}))
{:db (assoc db :jira-templates->submit-template {:status :loading :data {}})
:fx [[:dispatch [:jira-templates->clear-submit-template]]
[:dispatch-later
{:ms 1000
:dispatch [:fetch {:method "GET"
:uri (str "/integrations/jira/issuetemplates/" id "?expand=cmdbtype-values")
:on-success #(rf/dispatch [:jira-templates->set-submit-template %])
:on-failure #(rf/dispatch [:jira-templates->set-submit-template nil])}]}]]}))

(rf/reg-event-db
:jira-templates->set-all
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/webapp/jira_templates/cmdb_table.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns webapp.jira-templates.cmdb-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 All @@ -25,7 +25,7 @@
[:> Table.ColumnHeaderCell "Label"]
[:> Table.ColumnHeaderCell "Jira Field"]
[:> Table.ColumnHeaderCell "Value"]
[:> Table.ColumnHeaderCell "Object Type"]
[:> Table.ColumnHeaderCell "Object Type ID"]
[:> Table.ColumnHeaderCell "Description (Optional)"]
[:> Table.ColumnHeaderCell "Required"]]]

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/webapp/jira_templates/create_update_form.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
[:> Flex {:direction "column" :gap "5"}
[:> Box {:grid-column "span 2 / span 2"}
[:> Heading {:as "h3" :size "4" :weight "bold" :class "text-[--gray-12]"}
"Configure CMDB"]
"Set a configuration management database (CMDB)"]
[:> Text {:size "3" :class "text-[--gray-11]"}
"Set up configuration management database relationships."]]
"Create an additional layer of relation between CMDBs and hoop services."]]

[:> Box {:class "space-y-radix-7" :grid-column "span 5 / span 5"}
[cmdb-table/main
Expand Down
17 changes: 11 additions & 6 deletions webapp/src/webapp/jira_templates/prompt_form.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
["@radix-ui/themes" :refer [Button Flex Box Text]]
[re-frame.core :as rf]
[reagent.core :as r]
[webapp.components.forms :as forms]))
[webapp.components.forms :as forms]
[webapp.components.multiselect :as multi-select]))

(defn- create-cmdb-select-options [jira-values]
(mapv (fn [{:keys [id name]}]
{:value id :text name})
{"value" id "label" name})
jira-values))

(defn- get-value-id [jira_values value]
Expand Down Expand Up @@ -56,12 +57,16 @@
(doall
(for [{:keys [label jira_field jira_values required]} cmdb-fields-to-show]
^{:key jira_field}
[forms/select
[multi-select/single
{:label label
:required required
:full-width? true
:selected (get-in @form-data [:jira_fields jira_field])
:on-change #(swap! form-data assoc-in [:jira_fields jira_field] %)
:placeholder "Select one"
:id (str "cmdb-select-" label)
:name (str "cmdb-select-" label)
:clearable? true
:searchble? true
:default-value (or (get-in @form-data [:jira_fields jira_field]) nil)
:on-change #(swap! form-data assoc-in [:jira_fields jira_field] (js->clj %))
:options (create-cmdb-select-options jira_values)}]))])]

[:> Flex {:justify "end" :gap "3" :mt "6"}
Expand Down
55 changes: 29 additions & 26 deletions webapp/src/webapp/webclient/aside/database_schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,34 @@

(defn- sql-databases-tree [_]
(let [dropdown-status (r/atom {})]
(fn [schema indexes has-database?]
(fn [schema indexes has-database? current-schema database-schema-status]
[:div {:class (when has-database?
"pl-small")}
(doall
(for [[db tables] schema]
^{:key db}
[:div
[:div {:class "flex items-center gap-small mb-2"}
[:> Database {:size 12}]
[:span {:class (str "hover:text-blue-500 hover:underline cursor-pointer "
"flex items-center")
:on-click #(swap! dropdown-status
assoc-in [db]
(if (= (get @dropdown-status db) :closed) :open :closed))}
[:> Text {:size "1"} db]
(if (not= (get @dropdown-status db) :closed)
[:> ChevronDown {:size 12}]
[:> ChevronRight {:size 12}])]]
[:div {:class (when (= (get @dropdown-status db) :closed)
"h-0 overflow-hidden")}
[tables-tree (into (sorted-map) tables) (into (sorted-map) (get indexes db))]]]))])))
(cond
;; Caso de erro com mensagem específica
(and (= :error database-schema-status) (:error current-schema))
[:> Text {:as "p" :size "1" :mb "2" :ml "2"}
(:error current-schema)]

:else
(doall
(for [[db tables] schema]
^{:key db}
[:div
[:div {:class "flex items-center gap-small mb-2"}
[:> Database {:size 12}]
[:span {:class (str "hover:text-blue-500 hover:underline cursor-pointer "
"flex items-center")
:on-click #(swap! dropdown-status
assoc-in [db]
(if (= (get @dropdown-status db) :closed) :open :closed))}
[:> Text {:size "1"} db]
(if (not= (get @dropdown-status db) :closed)
[:> ChevronDown {:size 12}]
[:> ChevronRight {:size 12}])]]
[:div {:class (when (= (get @dropdown-status db) :closed)
"h-0 overflow-hidden")}
[tables-tree (into (sorted-map) tables) (into (sorted-map) (get indexes db))]]])))])))

(defn- databases-tree []
(let [open-database (r/atom nil)]
Expand Down Expand Up @@ -209,10 +216,10 @@
current-schema
database-schema-status]}]
(case type
"oracledb" [sql-databases-tree (into (sorted-map) schema) (into (sorted-map) indexes) false]
"mssql" [sql-databases-tree (into (sorted-map) schema) (into (sorted-map) indexes) false]
"oracledb" [sql-databases-tree (into (sorted-map) schema) (into (sorted-map) indexes) false current-schema database-schema-status]
"mssql" [sql-databases-tree (into (sorted-map) schema) (into (sorted-map) indexes) false current-schema database-schema-status]
"postgres" [databases-tree databases (into (sorted-map) schema) (into (sorted-map) indexes) connection-name database-schema-status current-schema]
"mysql" [sql-databases-tree (into (sorted-map) schema) (into (sorted-map) indexes) false]
"mysql" [sql-databases-tree (into (sorted-map) schema) (into (sorted-map) indexes) false current-schema database-schema-status]
"mongodb" [databases-tree databases (into (sorted-map) schema) (into (sorted-map) indexes) connection-name database-schema-status current-schema]
[:> Text {:size "1"}
"Couldn't load the schema"]))
Expand All @@ -225,10 +232,6 @@
current-schema
database-schema-status]}]
(cond
(and (= :error database-schema-status) (:error current-schema))
[:> Text {:as "p" :size "1" :my "4"}
(:error current-schema)]

(= status :loading)
[:div
{:class "flex gap-small items-center py-regular text-xs"}
Expand Down
73 changes: 42 additions & 31 deletions webapp/src/webapp/webclient/panel.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
["@codemirror/state" :as cm-state]
["@codemirror/view" :as cm-view]
["@heroicons/react/20/solid" :as hero-solid-icon]
["@radix-ui/themes" :refer [Button Text]]
["@radix-ui/themes" :refer [Box Button Heading Spinner Text]]
["@uiw/codemirror-theme-dracula" :refer [dracula]]
["@uiw/codemirror-theme-github" :refer [githubDark]]
["@uiw/codemirror-theme-nord" :refer [nord]]
Expand Down Expand Up @@ -88,7 +88,6 @@

connection-type (discover-connection-type connection)
multiple-connections? (> (count selected-connections) 1)
jira-template @(rf/subscribe [:jira-templates->submit-template])
has-jira-template-multiple-connections? (some #(:jira_issue_template_id %) selected-connections)
jira-integration-enabled? @(rf/subscribe [:jira-integration->integration-enabled?])
change-to-tabular? (and (some (partial = connection-type) ["mysql" "postgres" "sql-server" "oracledb" "mssql" "database"])
Expand All @@ -112,19 +111,44 @@
exec-data-with-fields (cond-> exec-data
(:jira_fields form-data) (assoc :jira_fields (:jira_fields form-data))
(:cmdb_fields form-data) (assoc :cmdb_fields (:cmdb_fields form-data)))]
(rf/dispatch [:editor-plugin->exec-script exec-data-with-fields])))]
(rf/dispatch [:editor-plugin->exec-script exec-data-with-fields])))
(check-template-and-show-form []
(let [template @(rf/subscribe [:jira-templates->submit-template])]
(if (or (nil? (:data template))
(= :loading (:status template)))
(js/setTimeout check-template-and-show-form 500)
(if (needs-form? template)
(rf/dispatch [:modal->open
{:content [prompt-form/main
{:prompts (get-in template [:data :prompt_types :items])
:cmdb-items (get-in template [:data :cmdb_types :items])
:on-submit handle-submit}]}])
(handle-submit nil)))))

(handle-jira-template []
(rf/dispatch [:modal->open
{:maxWidth "540px"
:custom-on-click-out (fn [event] (.preventDefault event))
:content [:> Box
[:> Heading {:size "6" :mb "2" :class "text-[--gray-12]"}
"Verifying Jira Templates"]
[:> Text {:as "p" :size "3" :mb "7" :class "text-[--gray-11]"}
(str "This connection has additional verification for Jira Templates "
"and might take a few seconds before proceeding. Please wait until "
"the verification is processed without closing this tab.")]
[:> Spinner {:size "3" :class "justify-self-end"}]]}])
(rf/dispatch [:jira-templates->get-submit-template
(:jira_issue_template_id connection)])

(js/setTimeout check-template-and-show-form) 1000)]

(when (.-preventDefault e) (.preventDefault e))

(cond
(and needs-template? (or (nil? (:data jira-template))
(= :loading (:status jira-template))))
(rf/dispatch [:show-snackbar {:level :info
:text (str "Loading data. "
"Try again in few seconds.")}])

;; Multiple connections check
(and multiple-connections? has-jira-template-multiple-connections? jira-integration-enabled?)
;; Multiple connections check
(and multiple-connections?
has-jira-template-multiple-connections?
jira-integration-enabled?)
(rf/dispatch [:dialog->open
{:title "Running in multiple connections not allowed"
:action-button? false
Expand All @@ -133,21 +157,14 @@
"connections with Jira Templates activated. Please select "
"just one connection before running your command.")]}])

;; Multiple connections without template
;; Multiple connections without template
(and (seq selected-connections) multiple-connections?)
(reset! atom-exec-list-open? true)

;; Single connection
;; Single connection
(= (count selected-connections) 1)
(if (and (needs-form? jira-template) jira-integration-enabled?)
(if (= :loading (:status jira-template))
(rf/dispatch [:show-snackbar {:level :info
:text "Loading template data..."}])
(rf/dispatch [:modal->open
{:content [prompt-form/main
{:prompts (get-in jira-template [:data :prompt_types :items])
:cmdb-items (get-in jira-template [:data :cmdb_types :items])
:on-submit handle-submit}]}]))
(if (and needs-template? jira-integration-enabled?)
(handle-jira-template)

(do
(when change-to-tabular?
Expand All @@ -158,8 +175,9 @@
:metadata (metadata->json-stringify metadata)}])))

:else
(rf/dispatch [:show-snackbar {:level :info
:text "You must choose a connection"}])))))
(rf/dispatch [:show-snackbar
{:level :info
:text "You must choose a connection"}])))))

(defmulti ^:private saved-status-el identity)
(defmethod ^:private saved-status-el :saved [_]
Expand Down Expand Up @@ -209,7 +227,6 @@
plugins (rf/subscribe [:plugins->my-plugins])
selected-template (rf/subscribe [:runbooks-plugin->selected-runbooks])
script-response (rf/subscribe [:editor-plugin->script])
previous-selected-connections (r/atom nil)

vertical-pane-sizes (mapv js/parseInt
(cs/split
Expand Down Expand Up @@ -359,12 +376,6 @@
(= (:type connection) "oracledb")
(= (:type connection) "database")))]

(when (and is-one-connection-selected?
(not= @run-connection-list-selected @previous-selected-connections))
(rf/dispatch [:jira-templates->get-submit-template
(:jira_issue_template_id last-connection-selected)])
(reset! previous-selected-connections @run-connection-list-selected))

(if (and (empty? (:results @db-connections))
(not (:loading @db-connections)))
[quickstart/main]
Expand Down

0 comments on commit 216ab21

Please sign in to comment.