Group Document Metrics Date Format Fix
Version: 0.230.048
Fixed in: 0.230.048
Issue Description
Group document metrics in the Control Center were displaying "Last Day: 0" (count format) instead of "Last Day: 09/02/2025" (date format) like user document metrics. The user requested that group metrics follow the same format as user metrics showing actual dates instead of counts.
Root Cause Analysis
The backend was providing two different data structures:
- Users:
last_day_upload(singular) - a date string like "09/02/2025" - Groups:
last_day_uploads(plural) - a count like0or1
The frontend group metrics function was using the count-based field instead of calculating and displaying the actual date of the last upload.
Technical Solution
Backend Changes (route_backend_control_center.py)
Added last_day_upload calculation logic to the enhance_group_with_activity() function:
- Query for Most Recent Upload: Added database query to find the most recent document upload for each group
- Date Format Conversion: Added logic to convert various date formats (ISO, date-only) to MM/DD/YYYY format
- Error Handling: Added proper error handling for invalid dates with fallback to 'Never'
- Debug Logging: Added comprehensive debug logging for troubleshooting
# Calculate last_day_upload date string (matching user format)
last_upload_query = """
SELECT TOP 1 c.upload_date, c.created_at, c.modified_at
FROM c
WHERE c.group_id = @group_id
ORDER BY c.upload_date DESC, c.created_at DESC, c.modified_at DESC
"""
# ... date parsing and formatting logic
enhanced['activity']['document_metrics']['last_day_upload'] = last_day_upload
Frontend Changes (control-center.js)
Updated renderGroupDocumentMetrics() function:
- Field Change: Changed from
docMetrics.last_day_uploads(count) todocMetrics.last_day_upload(date string) - Display Logic: Updated to show date strings like "09/02/2025" or "Never" instead of counts
- Validation Logic: Updated empty state detection to check for 'Never' instead of count === 0
const lastDayUpload = docMetrics.last_day_upload || 'Never';
// Display: <div><strong>Last Day:</strong> ${lastDayUpload}</div>
Expected Display Format
Groups now display document metrics in the same format as users:
Last Day: 09/02/2025
Total Docs: 1
AI Search: 400 KB
Storage: 815.6 KB
(Enhanced)
Testing
Created comprehensive functional test (test_group_document_metrics_display.py) that validates:
- ✅ Backend provides
last_day_uploadfield for groups - ✅ Frontend JavaScript uses correct field name
- ✅ HTML template calls updated function
- ✅ API endpoint structure supports new field
Files Modified
- Backend:
application/single_app/route_backend_control_center.py- Added date calculation logic - Frontend JS:
application/single_app/static/js/control-center.js- Updated display function - Config:
application/single_app/config.py- Version increment to 0.230.048 - Test:
functional_tests/test_group_document_metrics_display.py- Validation test
Validation Results
All functional tests pass ✅:
- Backend Group Metrics Logic: PASSED
- Control Center JavaScript Structure: PASSED
- Control Center HTML Structure: PASSED
- Group Document Metrics API Structure: PASSED
The fix ensures group document metrics now display in the exact same format as user document metrics, showing actual dates instead of counts for the "Last Day" field.