2 Commits

Author SHA1 Message Date
Scott Idem
f6051156cf fix(badges): include sort selection in active-filters check
Sort changes without a text query were falling through to the fallback
liveQuery (50 badges sorted by given_name), ignoring the selected sort
entirely. Added params.sort to has_active_filters so any explicit sort
selection triggers the full search path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 19:15:11 -04:00
Scott Idem
d64222ca91 fix(badges): implement missing sort cases for all sort options
All four sort options in the dropdown were falling through to the
default (given_name ASC) because their cases were missing from both
the IDB fast-path sort and the API order_by_li mapping:

- Affiliations ASC: IDB sorts by affiliations_override → affiliations;
  API sorts by affiliations column
- Badge Type ASC: badge_type_code ASC
- First Printed DESC: print_first_datetime DESC
- Last Printed DESC: print_last_datetime DESC

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 18:57:03 -04:00

View File

@@ -218,9 +218,10 @@ async function handle_search_refresh(params: any) {
const min_chars = params.min_chars;
// Defense-in-depth: enforce min_chars even if the search component lets one through.
// Exception: if the user has set a non-default filter (printed status, type, affiliations),
// that is an explicit intent — run the search even without a text query.
const has_active_filters = printed_status !== 'all' || !!type_code || !!aff_str;
// Exception: if the user has set a non-default filter or sort, that is explicit intent —
// run the search even without a text query.
const has_active_filters =
printed_status !== 'all' || !!type_code || !!aff_str || !!params.sort;
if (qry_str.length < min_chars && !has_active_filters) {
untrack(() => {
event_badge_id_li = [];
@@ -317,6 +318,26 @@ async function handle_search_refresh(params: any) {
);
case 'print_count_desc':
return (b.print_count ?? 0) - (a.print_count ?? 0);
case 'print_first_desc':
return (
new Date(b.print_first_datetime || 0).getTime() -
new Date(a.print_first_datetime || 0).getTime()
);
case 'print_last_desc':
return (
new Date(b.print_last_datetime || 0).getTime() -
new Date(a.print_last_datetime || 0).getTime()
);
case 'badge_type_asc':
return (a.badge_type_code ?? '').localeCompare(
b.badge_type_code ?? ''
);
case 'affiliations_asc':
return (
(a.affiliations_override ?? a.affiliations ?? '').localeCompare(
b.affiliations_override ?? b.affiliations ?? ''
)
);
default:
return (a.given_name ?? '').localeCompare(
b.given_name ?? ''
@@ -372,6 +393,18 @@ async function handle_search_refresh(params: any) {
case 'print_count_desc':
order_by_li = { print_count: 'DESC' };
break;
case 'print_first_desc':
order_by_li = { print_first_datetime: 'DESC' };
break;
case 'print_last_desc':
order_by_li = { print_last_datetime: 'DESC' };
break;
case 'badge_type_asc':
order_by_li = { badge_type_code: 'ASC' };
break;
case 'affiliations_asc':
order_by_li = { affiliations: 'ASC' };
break;
default:
order_by_li = { given_name: 'ASC' };
}