Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(database-schema): select database when clicked at one of them #591

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.33.3",
"version": "1.33.4",
"scripts": {
"ancient": "clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version \"RELEASE\"}}}' -m antq.core",
"genversion": "npx genversion src/webapp/version.js",
Expand Down
36 changes: 20 additions & 16 deletions webapp/src/webapp/events/database_schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,31 @@
{}
schemas)))

(rf/reg-event-db
(defn- clear-selected-database [db connection-name]
(let [stored-db (.getItem js/localStorage "selected-database")
current-connection (get-in db [:database-schema :data connection-name])]
(when (and stored-db
(some #(= stored-db %) (:databases current-connection)))
(.removeItem js/localStorage "selected-database"))))

(rf/reg-event-fx
:database-schema->clear-selected-database
(fn [{:keys [db]} [_ connection-name]]
(clear-selected-database db connection-name)
{}))

(rf/reg-event-fx
:database-schema->clear-schema
(fn [db [_ connection-name]]
(-> db
(update-in [:database-schema :data] dissoc connection-name)
(assoc-in [:database-schema :current-connection] nil))))
(fn [{:keys [db]} [_ connection-name]]
(clear-selected-database db connection-name)
{:db (-> db
(update-in [:database-schema :data] dissoc connection-name)
(assoc-in [:database-schema :current-connection] nil))}))

(rf/reg-event-fx
:database-schema->handle-multi-database-schema
(fn [{:keys [db]} [_ connection]]
(let [current-connection-data (get-in db [:database-schema :data (:connection-name connection)])
selected-db (or (.getItem js/localStorage "selected-database")
(first (:databases current-connection-data)))]
(if (and selected-db (:databases current-connection-data))
;; if there is a selected database, fetch its schema
{:fx [[:dispatch [:database-schema->get-multi-database-schema
connection
selected-db
(:databases current-connection-data)]]]}
;; if not, just fetch the databases
{:fx [[:dispatch [:database-schema->get-multi-databases connection]]]}))))
{:fx [[:dispatch [:database-schema->get-multi-databases connection]]]}))

(rf/reg-event-fx
:database-schema->get-multi-databases
Expand Down
75 changes: 34 additions & 41 deletions webapp/src/webapp/webclient/aside/database_schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -157,57 +157,53 @@

(defn- databases-tree []
(let [open-database (r/atom nil)]
(fn [databases schema indexes initial-database connection-name database-schema-status]
(when (and initial-database (nil? @open-database))
(reset! open-database initial-database)
(.setItem js/localStorage "selected-database" initial-database))
(let [selected-db (.getItem js/localStorage "selected-database")]
[:div.text-xs
(doall
(for [db databases]
^{:key db}
[:div
[:div {:class "flex items-center gap-smal mb-2"}
[:span {:class (str "hover:text-blue-500 hover:underline cursor-pointer "
"flex items-center "
(when (= db selected-db) "text-blue-500"))
:on-click (fn []
(.setItem js/localStorage "selected-database" db)
(reset! open-database (when (not= @open-database db) db))
(fn [databases schema indexes connection-name database-schema-status]
[:div.text-xs
(doall
(for [db databases]
^{:key db}
[:div
[:div {:class "flex items-center gap-smal mb-2"}
[:span {:class (str "hover:text-blue-500 hover:underline cursor-pointer "
"flex items-center ")
:on-click (fn []
(reset! open-database (when (not= @open-database db) db))
(if @open-database
(rf/dispatch [:database-schema->change-database
{:connection-name connection-name}
db]))}
[:> Text {:size "1" :weight "bold"} db]
(if (= @open-database db)
[:> ChevronDown {:size 12}]
[:> ChevronRight {:size 12}])]]
[:div {:class (when (not= @open-database db)
"h-0 overflow-hidden")}
(if (= :loading database-schema-status)
[:div
{:class "flex gap-small items-center pb-small ml-small text-xs"}
[:span {:class "italic"}
"Loading tables and indexes"]
[:figure {:class "w-3 flex-shrink-0 animate-spin opacity-60"}
[:img {:src (str config/webapp-url "/icons/icon-loader-circle-white.svg")}]]]
(if (empty? schema)
[:> Text {:as "p" :size "1" :mb "2" :ml "2"}
"Couldn't load tables for this database"]
[sql-databases-tree schema indexes true]))]]))]))))
db])

(rf/dispatch [:database-schema->clear-selected-database connection-name])))}
[:> Text {:size "1" :weight "bold"} db]
(if (= @open-database db)
[:> ChevronDown {:size 12}]
[:> ChevronRight {:size 12}])]]
[:div {:class (when (not= @open-database db)
"h-0 overflow-hidden")}
(if (= :loading database-schema-status)
[:div
{:class "flex gap-small items-center pb-small ml-small text-xs"}
[:span {:class "italic"}
"Loading tables and indexes"]
[:figure {:class "w-3 flex-shrink-0 animate-spin opacity-60"}
[:img {:src (str config/webapp-url "/icons/icon-loader-circle-white.svg")}]]]
(if (empty? schema)
[:> Text {:as "p" :size "1" :mb "2" :ml "2"}
"Couldn't load tables for this database"]
[sql-databases-tree schema indexes true]))]]))])))

(defn db-view [{:keys [type
schema
indexes
databases
initial-database
connection-name
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]
"postgres" [databases-tree databases (into (sorted-map) schema) (into (sorted-map) indexes) initial-database connection-name database-schema-status]
"postgres" [databases-tree databases (into (sorted-map) schema) (into (sorted-map) indexes) connection-name database-schema-status]
"mysql" [sql-databases-tree (into (sorted-map) schema) (into (sorted-map) indexes) false]
"mongodb" [databases-tree databases (into (sorted-map) schema) (into (sorted-map) indexes) initial-database connection-name database-schema-status]
"mongodb" [databases-tree databases (into (sorted-map) schema) (into (sorted-map) indexes) connection-name database-schema-status]
[:> Text {:size "1"}
"Couldn't load the schema"]))

Expand All @@ -216,7 +212,6 @@
schema
indexes
connection
initial-database
database-schema-status]}]
(case status
:loading [:div
Expand All @@ -233,7 +228,6 @@
:schema schema
:indexes indexes
:databases databases
:initial-database initial-database
:connection-name (:connection-name connection)
:database-schema-status database-schema-status}]
[:div
Expand Down Expand Up @@ -264,5 +258,4 @@
:schema (:schema-tree current-schema)
:indexes (:indexes-tree current-schema)
:connection connection
:initial-database (:connection-database-selected connection)
:database-schema-status (:database-schema-status current-schema)}]]))))
25 changes: 9 additions & 16 deletions webapp/src/webapp/webclient/panel.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,15 @@
"" dracula
nil dracula}
show-tree? (fn [connection]
(let [reviewers? (if (:loading @db-connections)
false
(empty?
(:reviewers
(first
(filter #(= (:name connection) (:name %)) (:results @db-connections))))))]
(and (or (= (:type connection) "mysql-csv")
(= (:type connection) "postgres-csv")
(= (:type connection) "mongodb")
(= (:type connection) "postgres")
(= (:type connection) "mysql")
(= (:type connection) "sql-server-csv")
(= (:type connection) "mssql")
(= (:type connection) "oracledb")
(= (:type connection) "database"))
reviewers?)))]
(or (= (:type connection) "mysql-csv")
(= (:type connection) "postgres-csv")
(= (:type connection) "mongodb")
(= (:type connection) "postgres")
(= (:type connection) "mysql")
(= (:type connection) "sql-server-csv")
(= (:type connection) "mssql")
(= (:type connection) "oracledb")
(= (:type connection) "database")))]
(if (and (empty? (:results @db-connections))
(not (:loading @db-connections)))
[quickstart/main]
Expand Down
Loading