Social Posts UI Improvements
Overview
Comprehensive UI improvements for the social posts detail page including link tooltips, metadata management, loader implementation, and insights sidebar section.
Changes Implemented
1. Link Tooltips for URLs
Problem: Facebook and Instagram post URLs were overflowing the section.
Solution: Enhanced CommonSection component to support links with tooltips.
Files Modified:
/src/admin/components/common/section-views/index.tsx- Added
Tooltipimport from@medusajs/ui - Extended
CommonFieldtype to supportlinkfield withhrefandlabel - Added rendering logic for links with tooltips
- Links truncate at 300px width and show full URL on hover
- Added
Usage Example:
{
label: "Facebook Post",
link: {
href: "https://www.facebook.com/123456789",
label: "View on Facebook",
},
}
/src/admin/components/social-posts/social-post-general-section.tsx- Updated to use
linkfield for Facebook and Instagram URLs - Added fallback for non-FBINSTA posts to show single post URL
- Links open in new tab with proper security attributes
- Updated to use
2. Metadata Route Implementation
Pattern: Follows the same structure as designs metadata route.
Files Created:
/src/admin/routes/social-posts/[id]/@metadata/edit/page.tsx- Implements metadata editing for social posts
- Uses
MetadataFormcomponent - Includes wrapper function to match expected hook signature
- Handles loading and error states
Key Features:
- Reuses existing
MetadataFormcomponent - Proper TypeScript typing with wrapper function
- Consistent with other metadata routes in the application
3. Loader Implementation
Pattern: Follows the same structure as designs loader.
Files Created:
-
/src/admin/routes/social-posts/[id]/loader.ts- Implements data preloading for social post detail page
- Uses
queryClient.ensureQueryDatafor optimal caching - Fetches related platform data using
fieldsquery parameter
-
/src/admin/routes/social-posts/[id]/constants.ts- Defines
SOCIAL_POST_DETAIL_FIELDSconstant - Currently includes:
"platform.*" - Can be extended to include more related data
- Defines
Integration:
- Exported as
loaderfrom detail page - Enables React Router to prefetch data before rendering
- Improves perceived performance and UX
4. Insights Sidebar Section
Purpose: Display analytics and engagement data from social platform webhooks.
Files Created:
/src/admin/components/social-posts/social-post-insights-section.tsx- Comprehensive insights display component
- Supports Facebook, Instagram, and Twitter metrics
- Shows webhook data (comments, reactions)
Metrics Displayed:
Facebook Insights:
- Post ID
- Impressions
- Reach
- Engagement
- Last updated timestamp
Instagram Insights:
- Media ID
- Permalink (with link tooltip)
- Impressions
- Reach
- Engagement
- Likes
- Comments
- Saves
- Last updated timestamp
Twitter Insights:
- Tweet ID
- (Extensible for future metrics)
Webhook Data:
- Comments count
- Total reactions
- Individual reaction types (like, love, wow, etc.)
Smart Display Logic:
- Only shows available metrics
- Handles missing data gracefully
- Shows appropriate message when no insights available:
- "Insights pending from webhooks" for posted content
- "Post not yet published" for draft content
5. Type System Updates
Files Modified:
/src/admin/hooks/api/social-posts.ts- Added
metadatafield toAdminSocialPosttype - Added
metadatafield toAdminCreateSocialPostPayloadtype - Ensures type consistency across the application
- Added
File Structure
src/admin/
├── components/
│ ├── common/
│ │ └── section-views/
│ │ └── index.tsx (Enhanced with link tooltips)
│ └── social-posts/
│ ├── social-post-general-section.tsx (Updated with link fields)
│ └── social-post-insights-section.tsx (NEW)
├── hooks/
│ └── api/
│ └── social-posts.ts (Added metadata field)
└── routes/
└── social-posts/
└── [id]/
├── @metadata/
│ └── edit/
│ └── page.tsx (NEW)
├── constants.ts (NEW)
├── loader.ts (NEW)
└── page.tsx (Updated with insights and loader)
Benefits
- Better UX: Links no longer overflow, full URLs visible on hover
- Metadata Management: Consistent metadata editing across all entities
- Performance: Loader prefetches data for faster page loads
- Analytics: Comprehensive insights display for tracking post performance
- Extensibility: Easy to add more metrics as platforms add features
- Type Safety: Full TypeScript support with proper types
Testing Checklist
- Verify link tooltips show full URL on hover
- Test metadata editing and saving
- Confirm loader prefetches data correctly
- Check insights display for FBINSTA posts
- Verify insights display for single platform posts
- Test with posts that have no insights data
- Verify webhook data displays correctly
- Test with different insight values (zero, large numbers)
Future Enhancements
- Real-time Updates: Add polling or websocket for live insights updates
- Charts: Add visual charts for metrics over time
- Comparison: Compare performance across multiple posts
- Export: Export insights data to CSV/Excel
- Alerts: Set up alerts for engagement thresholds
- Twitter Metrics: Add comprehensive Twitter analytics when available