Skip to content

Commit

Permalink
jfx, adds tooltip to sampling button
Browse files Browse the repository at this point in the history
  • Loading branch information
Torkus committed Aug 11, 2023
1 parent 77e5f15 commit dad209e
Showing 4 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@
;; remember to update the LICENCE.txt
;; remember to update pom file (`lein pom`)

[org.clojure/core.cache "1.0.207"] ;; jfx context caching
;;[org.clojure/core.cache "1.0.207"] ;; jfx context caching

]

3 changes: 2 additions & 1 deletion src/strongbox/core.clj
Original file line number Diff line number Diff line change
@@ -864,7 +864,7 @@
(into [] xf db)))

(defn-spec db-search-sampling? boolean?
"returns `true` if a database search should return a random sample.
"returns `true` if a database search should return a random sample of results.
essentially, if nothing has been searched for and no filters have been set, we should take a random
sample of the selected catalogue UNLESS something has explicitly flipped the `:sample?` boolean."
[search-state map?]
@@ -923,6 +923,7 @@
;; no/empty input, do a random sample
(if random-sample?
(let [pct (->> db count (max 1) (/ 100) (* 0.6))]
(println "sampling!!!!!!!!!!!!!!!!!" pct "with cap" cap)
;; decrement cap here so navigation for random search results is disabled
[(take (dec cap) (random-sample pct db))])

21 changes: 12 additions & 9 deletions src/strongbox/jfx.clj
Original file line number Diff line number Diff line change
@@ -547,8 +547,7 @@
".updated-column" {:-fx-alignment "center"}}

"#search-addons-footer "
{;;:-fx-background-color "#ddd"
:-fx-alignment "center-left"
{:-fx-alignment "center-left"

".left-hbox"
{:-fx-alignment "center-left"
@@ -2184,13 +2183,17 @@
(defn search-addons-table-extra
[{:keys [fx/context]}]
(let [search (fx/sub-val context get-in [:app-state, :search])]
{:fx/type :check-box
:text "sample results"
:selected (:sample? search)
;; prevent sample toggle if search in a state where sampling not possible
:disable (not (db-search-sampling? search))
:node-orientation :right-to-left
:on-selected-changed (async-handler cli/toggle-search-sampling!)}))
{:fx/type fx.ext.node/with-tooltip-props
:props {:tooltip {:fx/type :tooltip
:text (format "show a single page of %s random addons" (:results-per-page search))
:show-delay 200}}
:desc {:fx/type :check-box
:text "sample results"
:selected (:sample? search)
;; prevent sample toggle if search in a state where sampling not possible
:disable (not (db-search-sampling? search))
:node-orientation :right-to-left
:on-selected-changed (async-handler cli/toggle-search-sampling!)}}))

(defn search-addons-pane
[_]
47 changes: 47 additions & 0 deletions test/strongbox/cli_test.clj
Original file line number Diff line number Diff line change
@@ -228,6 +228,53 @@

(is (not (cli/search-has-prev?))))))))

(deftest search-db--sampled-results
(testing "search results are sampled by default"
(let [catalogue (slurp (fixture-path "catalogue--v2.json"))
fake-routes {"https://raw.githubusercontent.com/ogri-la/strongbox-catalogue/master/short-catalogue.json"
{:get (fn [req] {:status 200 :body catalogue})}}
cap 2
page-1 first
page-2 second]
(with-global-fake-routes-in-isolation fake-routes
(with-running-app
;; sampling by default
(is (core/db-search-sampling? (core/get-state :search)))

;; we have four items in catalogue so each item has a 15% chance (* 0.25 0.6) of being included.
;; we then take one fewer than the per-page `cap` so the pagination buttons stay disabled.
;; if we set 3 results per page cap we'll always get one page of results with the first two sampled addons back.
(swap! core/state assoc-in [:search :results-per-page] (inc cap))
(cli/bump-search)
(Thread/sleep 100)

;; one page, two results
(is (-> (core/get-state) :search :results count (= 1)))
(is (-> (core/get-state) :search :results page-1 count (= 2)))

;; disable sampling
(cli/toggle-search-sampling!)
(is (not (core/db-search-sampling? (core/get-state :search))))

;; and disable the random result pagination navigation button hack
(swap! core/state assoc-in [:search :results-per-page] cap)
(cli/bump-search)
(Thread/sleep 100)

;; two pages, each with two results
(is (-> (core/get-state) :search :results count (= 2)))
(is (-> (core/get-state) :search :results page-1 count (= 2)))
(is (-> (core/get-state) :search :results page-2 count (= 2)))

)))))

(deftest search-db--sampled-results--toggled-off
(testing "sampled search results can be toggled off."
nil))




(deftest pin-addon
(testing "an addon can be installed, selected and pinned to it's current installed version"
(let [addon {:name "everyaddon-classic" :label "EveryAddon (Classic)" :version "1.2.3" :url "https://group.id/never/fetched"

0 comments on commit dad209e

Please sign in to comment.