Skip to content

Commit

Permalink
feat: sort license lists by title
Browse files Browse the repository at this point in the history
This gives a consistent result.
  • Loading branch information
Macroz committed Sep 11, 2024
1 parent d22c5d3 commit 45e98a5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changes since v2.37
avoid having many hopeless retries, if there is a typo in an email address.
- Form editor performance has been significantly improved. To give rough numbers, the editor now works smoothly with 200 form fields in test data. (#3105)
- The wording about experimental is removed from GA4GH API. It is already used in production. (#3299)
- Licenses are ordered consistently (alphabetically) wherever they appear. (#3302)

### Fixes
- Empty the license attachment field if the upload fails. (#3292)
Expand Down
3 changes: 2 additions & 1 deletion src/cljs/rems/actions/add_licenses.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
[dropdown/dropdown
{:id dropdown-id
:items (->> potential-licenses
(mapv #(assoc % ::label (get-localized-title %))))
(mapv #(assoc % ::label (get-localized-title %)))
(sort-by ::label))
:item-key :id
:item-label ::label
:item-selected? #(contains? (set selected-licenses) %)
Expand Down
1 change: 1 addition & 0 deletions src/cljs/rems/administration/create_catalogue_item.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
(defn- localize-licenses [resource]
(when-some [licenses (->> (:licenses resource)
(map #(get-localized-title %))
sort
seq)]
(text-format :t.label/default
(text :t.administration/licenses)
Expand Down
6 changes: 4 additions & 2 deletions src/cljs/rems/administration/create_resource.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@
[:label.administration-field-label {:for licenses-dropdown-id} (text :t.create-resource/licenses-selection)]
[dropdown/dropdown
{:id licenses-dropdown-id
:items (vec (for [license licenses
:items (->> (for [license licenses
:let [title (get-localized-title license)
org-short (localize-org-short license)]]
(assoc license
::label (text-format :t.label/default title org-short))))
::label (text-format :t.label/default title org-short)))
(sort-by ::label)
vec)
:item-key :id
:item-label ::label
:item-selected? #(contains? (set selected-licenses) %)
Expand Down
11 changes: 7 additions & 4 deletions src/cljs/rems/administration/create_workflow.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[rems.flash-message :as flash-message]
[rems.focus :as focus]
[rems.spinner :as spinner]
[rems.text :refer [localized localize-command localize-role localize-state text text-format text-format-map]]
[rems.text :refer [get-localized-title localized localize-command localize-role localize-state text text-format text-format-map]]
[rems.util :refer [navigate! post! put! trim-when-string]]))

(rf/reg-event-fx ::enter-page
Expand Down Expand Up @@ -265,9 +265,11 @@
(rf/reg-event-db ::set-licenses (fn [db [_ licenses]] (assoc-in db [::form :licenses] licenses)))

(defn- render-readonly-licenses [id licenses]
(let [licenses (for [license licenses
(let [licenses (for [license (->> licenses
(mapv #(assoc % ::title (get-localized-title %)))
(sort-by ::title))
:let [uri (str "/administration/licenses/" (:license/id license))
title (:title (localized (:localizations license)))]]
title (::title license)]]
[atoms/link {} uri title])]
[fields/readonly-field-raw {:id id
:value (if (seq licenses)
Expand Down Expand Up @@ -298,7 +300,8 @@
:items (->> @(rf/subscribe [::licenses])
(mapv #(assoc % ::label (text-format :t.label/parens
(:title (localized (:localizations %)))
(localize-org-short %)))))
(localize-org-short %))))
(sort-by ::label))
:item-key :id
:item-label ::label
:item-selected? #(contains? selected-ids (:id %))
Expand Down
4 changes: 3 additions & 1 deletion src/cljs/rems/administration/license.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@
:open? (<= (count licenses) 5)
:collapse (if (seq licenses)
(into [:div]
(for [license licenses]
(for [license (->> licenses
(mapv #(assoc % ::title (get-localized-title %)))
(sort-by ::title))]
[license-view-compact license]))
[:p (text :t.administration/no-licenses)])}])

Expand Down
8 changes: 5 additions & 3 deletions src/cljs/rems/administration/workflow.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[rems.common.roles :as roles]
[rems.spinner :as spinner]
[rems.table :as table]
[rems.text :refer [localized localize-command localize-role localize-state text text-format]]
[rems.text :refer [get-localized-title localized localize-command localize-role localize-state text text-format]]
[rems.util :refer [fetch]]))

(rf/reg-event-fx
Expand Down Expand Up @@ -120,9 +120,11 @@
(defn- render-licenses [licenses]
(into [:<>]
(interpose ", ")
(for [license licenses
(for [license (->> licenses
(mapv #(assoc % ::title (get-localized-title %)))
(sort-by ::title))
:let [uri (str "/administration/licenses/" (:license/id license))
title (:title (localized (:localizations license)))]]
title (::title license)]]
[atoms/link {} uri title])))

(defn- localize-workflow [workflow-type]
Expand Down

0 comments on commit 45e98a5

Please sign in to comment.