diff --git a/app/components/multiselect_combobox_component.html.erb b/app/components/multiselect_combobox_component.html.erb index 969cd980e..26762f5d3 100644 --- a/app/components/multiselect_combobox_component.html.erb +++ b/app/components/multiselect_combobox_component.html.erb @@ -14,7 +14,7 @@ <% end %> <% if @field_name == 'advanced_location_s' %> <%= content_tag :li, - 'pul', + 'All Princeton Holdings', class: 'dropdown-item', tabindex: -1, role: 'option' %> @@ -32,7 +32,7 @@ <% end %> <% if @field_name == 'advanced_location_s' %> <%= content_tag :option, - 'pul', + 'All Princeton Holdings', value: 'pul', selected: params.dig('f_inclusive', 'advanced_location_s', 0) == 'pul' %> <% end %> diff --git a/app/javascript/orangelight/multiselect_combobox.es6 b/app/javascript/orangelight/multiselect_combobox.es6 index ba3a6650e..a18839a21 100644 --- a/app/javascript/orangelight/multiselect_combobox.es6 +++ b/app/javascript/orangelight/multiselect_combobox.es6 @@ -17,6 +17,7 @@ export default class MultiselectCombobox { .querySelector('.number-of-results'); this.#addEventListeners(); this.#applySelections(); + this.#orderList(); } toggleItem(item) { @@ -130,15 +131,40 @@ export default class MultiselectCombobox { } #compare(a, b) { + const locations = [ + 'All Princeton Holdings', + 'Architecture Library', + 'East Asian Library', + 'Engineering Library', + 'Firestone Library', + 'Forrestal Annex', + 'Harold P. Furth Plasma Physics Library', + 'Lewis Library', + 'Marquand Library', + 'Mendel Music Library', + 'Mudd Manuscript Library', + 'ReCAP', + 'Special Collections', + 'Stokes Library', + ]; + function toBoolean(value) { return value === 'true' ? true : false; } + function inLocations(value) { + let i = value.indexOf(' ('); + let clean = value.slice(0, i === -1 ? value.length : i); + return locations.includes(clean); + } + if ( toBoolean(a.getAttribute('aria-selected')) !== toBoolean(b.getAttribute('aria-selected')) ) { return toBoolean(a.getAttribute('aria-selected')) ? -1 : 1; + } else if (inLocations(a.textContent) !== inLocations(b.textContent)) { + return inLocations(a.textContent) ? -1 : 1; } else { return a.textContent.localeCompare(b.textContent); } diff --git a/spec/javascript/orangelight/multiselect_combobox.spec.js b/spec/javascript/orangelight/multiselect_combobox.spec.js index 8d6cd868c..9f3d60f2b 100644 --- a/spec/javascript/orangelight/multiselect_combobox.spec.js +++ b/spec/javascript/orangelight/multiselect_combobox.spec.js @@ -111,22 +111,33 @@ describe('MultiselectCombobox', () => { describe('when one of the options is already selected', () => { beforeEach(() => { document.body.innerHTML = ` -