refactor(events): enforce hierarchy consistency and id standardization

This commit is contained in:
Scott Idem
2026-02-25 17:53:20 -05:00
parent 197adff33b
commit 17620b6fbc
3 changed files with 112 additions and 24 deletions

View File

@@ -23,6 +23,8 @@ export async function load_ae_obj_id__event({
inc_file_li = false,
inc_location_li = false,
inc_session_li = false,
inc_presentation_li = false,
inc_presenter_li = false,
inc_template_li = false,
enabled = 'enabled',
hidden = 'not_hidden',
@@ -36,6 +38,8 @@ export async function load_ae_obj_id__event({
inc_file_li?: boolean;
inc_location_li?: boolean;
inc_session_li?: boolean;
inc_presentation_li?: boolean;
inc_presenter_li?: boolean;
inc_template_li?: boolean;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
@@ -46,6 +50,9 @@ export async function load_ae_obj_id__event({
console.log(`*** load_ae_obj_id__event() *** event_id=${event_id} (SWR Optimization)`);
}
// Hierarchy Enforcement: Pulling presentations/presenters requires pulling sessions first
if (inc_presenter_li || inc_presentation_li) inc_session_li = true;
// 1. FAST PATH: Return cached data immediately
if (try_cache) {
try {
@@ -56,15 +63,15 @@ export async function load_ae_obj_id__event({
// Trigger background refresh
_refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_template_li,
enabled, hidden,
log_lvl: 0
});
// Still handle nested loads for the cached version to ensure UI richness
return await _handle_nested_loads(cached_event, {
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
enabled, hidden, log_lvl
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_template_li,
enabled, hidden, try_cache, log_lvl
});
}
} catch (e) {
@@ -75,7 +82,7 @@ export async function load_ae_obj_id__event({
// 2. SLOW PATH: Wait for API if cache is empty or try_cache is false
return await _refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_template_li,
enabled, hidden,
log_lvl
});
@@ -86,7 +93,7 @@ export async function load_ae_obj_id__event({
*/
async function _refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_template_li,
enabled, hidden,
log_lvl
}: any) {
@@ -123,8 +130,8 @@ async function _refresh_event_v3_background({
}
return await _handle_nested_loads(processed_obj, {
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
enabled, hidden, log_lvl
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_template_li,
enabled, hidden, try_cache: false, log_lvl
});
}
} catch (error: any) {
@@ -136,8 +143,8 @@ async function _refresh_event_v3_background({
/**
* Shared logic for loading nested child collections
*/
async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, enabled, hidden, log_lvl }: any) {
if (log_lvl) console.log(`Loading nested collections for event: ${event_obj.event_id} (Devices: ${inc_device_li}, Files: ${inc_file_li}, Locations: ${inc_location_li}, Sessions: ${inc_session_li}, Templates: ${inc_template_li})`);
async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_template_li, enabled, hidden, try_cache, log_lvl }: any) {
if (log_lvl) console.log(`Loading nested collections for event: ${event_obj.event_id} (Devices: ${inc_device_li}, Files: ${inc_file_li}, Locations: ${inc_location_li}, Sessions: ${inc_session_li}, Presentations: ${inc_presentation_li}, Presenters: ${inc_presenter_li}, Templates: ${inc_template_li})`);
// String-Only ID Vision: the '_id' field IS the string ID
const current_event_id = event_obj.id || event_obj.event_id;
@@ -149,6 +156,7 @@ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, in
api_cfg,
for_obj_type: 'event',
for_obj_id: current_event_id,
try_cache,
log_lvl
}).then(res => event_obj.event_device_obj_li = res));
}
@@ -159,6 +167,7 @@ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, in
for_obj_id: current_event_id,
enabled: 'all',
limit: 100,
try_cache,
log_lvl
}).then(res => event_obj.event_file_li = res));
}
@@ -169,6 +178,7 @@ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, in
for_obj_id: current_event_id,
enabled,
hidden,
try_cache,
log_lvl
}).then(res => event_obj.event_location_obj_li = res));
}
@@ -177,6 +187,11 @@ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, in
api_cfg,
for_obj_type: 'event',
for_obj_id: current_event_id,
inc_presentation_li,
inc_presenter_li,
enabled,
hidden,
try_cache,
log_lvl
}).then(res => event_obj.event_session_obj_li = res));
}
@@ -184,6 +199,7 @@ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, in
tasks.push(load_ae_obj_li__event_badge_template({
api_cfg,
event_id: current_event_id,
try_cache,
log_lvl
}).then(res => event_obj.event_badge_template_obj_li = res));
}
@@ -203,6 +219,8 @@ export async function load_ae_obj_li__event({
hidden = 'not_hidden',
view = 'default',
inc_session_li = false,
inc_presentation_li = false,
inc_presenter_li = false,
limit = 9,
offset = 0,
order_by_li = { start_datetime: 'DESC' } as const,
@@ -217,6 +235,8 @@ export async function load_ae_obj_li__event({
hidden?: 'hidden' | 'all' | 'not_hidden';
view?: string;
inc_session_li?: boolean;
inc_presentation_li?: boolean;
inc_presenter_li?: boolean;
limit?: number;
offset?: number;
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
@@ -225,6 +245,9 @@ export async function load_ae_obj_li__event({
log_lvl?: number;
}): Promise<ae_Event[]> {
// Hierarchy Enforcement: Pulling presentations/presenters requires pulling sessions first
if (inc_presenter_li || inc_presentation_li) inc_session_li = true;
// Check if offline
if (typeof navigator !== 'undefined' && !navigator.onLine) {
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.');
@@ -324,6 +347,9 @@ export async function load_ae_obj_li__event({
api_cfg,
for_obj_type: 'event',
for_obj_id: current_event_id,
inc_presentation_li,
inc_presenter_li,
try_cache,
log_lvl
}).then((res) => (event_obj.event_session_obj_li = res));
});
@@ -860,8 +886,12 @@ async function _process_generic_props<T extends Record<string, any>>({
}
}
const randomIdKey = `${obj_type}_id_random`;
const baseIdKey = `${obj_type}_id`;
if (processed_obj[randomIdKey]) {
(processed_obj as any).id = processed_obj[randomIdKey];
(processed_obj as any)[baseIdKey] = processed_obj[randomIdKey];
} else if (processed_obj[baseIdKey]) {
(processed_obj as any).id = processed_obj[baseIdKey];
}
const group = processed_obj.group ?? '0';
@@ -900,7 +930,9 @@ export async function process_ae_obj__event_props({
obj.code = obj.event_code;
}
// Ensure ID consistency for components relying on specific ID fields
if (obj.id && !obj.event_id) {
if (obj.event_id_random) {
obj.event_id = obj.event_id_random;
} else if (obj.id && !obj.event_id) {
obj.event_id = obj.id;
}
return obj;