From 874c1fceee4e917787eec53ecbb931754ccf5d3b Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 23 Jan 2026 13:09:25 -0600 Subject: [PATCH] Add debugging for proof types not showing in dropdown Backend logging: - Log channel, sub-channel, and proof type counts in get_all_hierarchical() - Log Meta proof types specifically - Log API response for Social.Meta Frontend logging: - Log raw API response in apiService - Log dropdown options in App.tsx when loaded - Log available proof types in UploadProofModal when channel/subchannel selected This will help diagnose why Meta proof types are not appearing on staging. Co-Authored-By: Claude Opus 4.5 --- backend/app/api/routes.py | 10 ++++++++++ backend/app/repositories/dropdown_repository.py | 15 ++++++++++++--- frontend/App.tsx | 5 ++++- frontend/components/Campaigns.tsx | 11 +++++++++++ frontend/services/apiService.ts | 6 +++++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/backend/app/api/routes.py b/backend/app/api/routes.py index ba97a1f..184b3b8 100755 --- a/backend/app/api/routes.py +++ b/backend/app/api/routes.py @@ -519,8 +519,18 @@ async def get_dropdown_options( user: dict = Depends(get_current_user), ): """Get all dropdown options as hierarchical structure.""" + import logging + logger = logging.getLogger(__name__) + repo = DropdownRepository(db) options = await repo.get_all_hierarchical() + + # Debug logging + channels = options.get("channels", {}) + social = channels.get("Social", {}) + meta_proof_types = social.get("Meta", []) + logger.info(f"[DEBUG API] Returning dropdown options - Social.Meta has {len(meta_proof_types)} proof types: {meta_proof_types}") + return DropdownOptionsResponse(**options) diff --git a/backend/app/repositories/dropdown_repository.py b/backend/app/repositories/dropdown_repository.py index 7737786..64c93f3 100644 --- a/backend/app/repositories/dropdown_repository.py +++ b/backend/app/repositories/dropdown_repository.py @@ -1,4 +1,5 @@ """Repository for dropdown options (channels, sub-channels, proof types).""" +import logging import uuid from typing import Optional from sqlalchemy import select, delete @@ -7,6 +8,8 @@ from sqlalchemy.orm import selectinload from app.models.models import DropdownOption +logger = logging.getLogger(__name__) + class DropdownRepository: """Repository for managing dropdown options.""" @@ -30,6 +33,7 @@ class DropdownRepository: ).order_by(DropdownOption.display_order) channels_result = await self.session.execute(channels_stmt) channels = channels_result.scalars().all() + logger.info(f"[DEBUG] Found {len(channels)} channels: {[c.value for c in channels]}") # Query 2: Get all sub-channels sub_channels_stmt = select(DropdownOption).where( @@ -37,6 +41,7 @@ class DropdownRepository: ).order_by(DropdownOption.display_order) sub_channels_result = await self.session.execute(sub_channels_stmt) sub_channels = sub_channels_result.scalars().all() + logger.info(f"[DEBUG] Found {len(sub_channels)} sub-channels: {[sc.value for sc in sub_channels]}") # Query 3: Get all proof types proof_types_stmt = select(DropdownOption).where( @@ -44,6 +49,7 @@ class DropdownRepository: ).order_by(DropdownOption.display_order) proof_types_result = await self.session.execute(proof_types_stmt) proof_types = proof_types_result.scalars().all() + logger.info(f"[DEBUG] Found {len(proof_types)} proof types") # Build lookup dictionaries sub_channels_by_parent: dict[uuid.UUID, list] = {} @@ -58,6 +64,8 @@ class DropdownRepository: proof_types_by_parent[pt.parent_id] = [] proof_types_by_parent[pt.parent_id].append(pt) + logger.info(f"[DEBUG] proof_types_by_parent has {len(proof_types_by_parent)} entries") + # Assemble hierarchy hierarchy: dict[str, dict[str, list[str]]] = {} for channel in channels: @@ -66,9 +74,10 @@ class DropdownRepository: for sub_channel in sub_channels_by_parent.get(channel.id, []): sub_channel_name = sub_channel.value - hierarchy[channel_name][sub_channel_name] = [ - pt.value for pt in proof_types_by_parent.get(sub_channel.id, []) - ] + proof_type_list = [pt.value for pt in proof_types_by_parent.get(sub_channel.id, [])] + hierarchy[channel_name][sub_channel_name] = proof_type_list + if sub_channel_name == "Meta": + logger.info(f"[DEBUG] Meta sub-channel (id={sub_channel.id}) has {len(proof_type_list)} proof types: {proof_type_list}") # Get brand guidelines stmt = select(DropdownOption).where( diff --git a/frontend/App.tsx b/frontend/App.tsx index e36b360..57e960a 100755 --- a/frontend/App.tsx +++ b/frontend/App.tsx @@ -61,13 +61,16 @@ const App: React.FC = () => { try { const options = await apiService.getDropdownOptions(); + console.log('[DEBUG App.tsx] Loaded dropdown options from API'); + console.log('[DEBUG App.tsx] options.channels:', JSON.stringify(options.channels, null, 2)); + console.log('[DEBUG App.tsx] Social.Meta proof types:', options.channels?.Social?.Meta); setDropdownOptions({ campaigns: options.campaigns || [], channels: options.channels || {}, brandGuidelines: options.brand_guidelines || [] }); } catch (error) { - console.error('Failed to load dropdown options:', error); + console.error('[DEBUG App.tsx] Failed to load dropdown options:', error); // Fall back to default options if API fails setDropdownOptions({ campaigns: [], diff --git a/frontend/components/Campaigns.tsx b/frontend/components/Campaigns.tsx index c6c4c55..625c683 100755 --- a/frontend/components/Campaigns.tsx +++ b/frontend/components/Campaigns.tsx @@ -379,6 +379,17 @@ const UploadProofModal: React.FC<{ const availableProofTypes = (channel && subChannel) ? (dropdownOptions.channels[channel][subChannel] || []) : []; const showProofType = availableProofTypes.length > 0; + // Debug logging for proof types + useEffect(() => { + if (channel && subChannel) { + console.log('[DEBUG Frontend] Channel:', channel); + console.log('[DEBUG Frontend] SubChannel:', subChannel); + console.log('[DEBUG Frontend] dropdownOptions.channels[channel]:', dropdownOptions.channels[channel]); + console.log('[DEBUG Frontend] dropdownOptions.channels[channel][subChannel]:', dropdownOptions.channels[channel]?.[subChannel]); + console.log('[DEBUG Frontend] availableProofTypes:', availableProofTypes); + } + }, [channel, subChannel, dropdownOptions, availableProofTypes]); + useEffect(() => { if (isOpen) { setFile(null); diff --git a/frontend/services/apiService.ts b/frontend/services/apiService.ts index b90b2b7..4318924 100755 --- a/frontend/services/apiService.ts +++ b/frontend/services/apiService.ts @@ -314,7 +314,11 @@ class ApiService { // Dropdown options endpoints async getDropdownOptions(): Promise { - return this.fetch('/dropdown-options'); + const response = await this.fetch('/dropdown-options'); + // Debug logging + console.log('[DEBUG API Response] Raw dropdown options:', JSON.stringify(response, null, 2)); + console.log('[DEBUG API Response] Social.Meta proof types:', response.channels?.Social?.Meta); + return response; } async addChannel(name: string): Promise {