fix(badges): fix Printed/Not Printed filter visibility and API query
Two bugs: 1. visible_badge_obj_li gated on trusted+edit_mode, but the filter dropdown is also accessible to manager+ without edit_mode. Changed gate to (trusted+edit) || manager_access to match the filter's own access condition. 2. not_printed API query used print_count eq 0, which does not match NULL in SQL. Unprinted badges have print_count = NULL, so the API was returning 0 results and overwriting the correct IDB fast-path results. Removed the not_printed condition from the API query — IDB fast path (print_count ?? 0) < 1 and visible_badge_obj_li both handle NULL correctly and are the authoritative filter for that case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -501,9 +501,10 @@ export async function search__event_badge({
|
||||
|
||||
if (printed_status === 'printed') {
|
||||
search_query.and.push({ field: 'print_count', op: 'gt', value: 0 });
|
||||
} else if (printed_status === 'not_printed') {
|
||||
search_query.and.push({ field: 'print_count', op: 'eq', value: 0 });
|
||||
}
|
||||
// 'not_printed' intentionally omitted from the API query: unprinted badges have
|
||||
// print_count = NULL (never set), and `eq 0` in SQL does not match NULL.
|
||||
// The IDB fast path (print_count ?? 0) < 1 and visible_badge_obj_li handle this correctly.
|
||||
|
||||
if (enabled === 'enabled')
|
||||
search_query.and.push({ field: 'enable', op: 'eq', value: true });
|
||||
|
||||
@@ -96,12 +96,13 @@ let visible_badge_obj_li = $derived(
|
||||
if (list === undefined || list === null) return null;
|
||||
if (!Array.isArray(list)) return [];
|
||||
|
||||
// The Printed Status filter dropdown is accessible to: trusted+edit OR manager+.
|
||||
// Match that gate here so the filter actually controls what's displayed.
|
||||
const can_use_filter = (is_trusted && is_edit_mode) || $ae_loc.manager_access;
|
||||
const filtered = list.filter((item: any) => {
|
||||
if (!item) return false;
|
||||
if (is_trusted && is_edit_mode) {
|
||||
// Trusted + edit mode: the Printed Status filter dropdown controls visibility.
|
||||
// This is the only context where the filter is accessible, so it is the
|
||||
// authoritative control — no separate edit_mode override needed.
|
||||
if (can_use_filter) {
|
||||
// Filter dropdown controls visibility for users who can access it.
|
||||
const ps = badges_loc.current.qry_printed_status;
|
||||
if (ps === 'printed') return (item.print_count ?? 0) >= 1 && !item.hide;
|
||||
if (ps === 'not_printed') return (item.print_count ?? 0) < 1 && !item.hide;
|
||||
|
||||
Reference in New Issue
Block a user