m ru # BYOP Preview Feature Frontend Integration
Overview
Successfully integrated the BYOP preview feature into the frontend dashboard with comprehensive UI components and controls.
Components Created
1. Preview Types (/src/types/preview.ts
)
Preview
interface matching API response
PreviewStatus
type with all status values: building, deploying, running, failed, stopped
PreviewLogEntry
interface for log display
2. PreviewStatusBadge (/src/components/PreviewStatusBadge.tsx
)
- Visual status indicator with appropriate colors and icons
- Tooltips explaining each status
- Configurable size (small/default)
- Status-specific styling:
- Building: Processing color with spinning loading icon
- Deploying: Processing color with rocket icon
- Running: Success color with check circle icon
- Failed: Error color with exclamation icon
- Stopped: Default color with stop icon
3. PreviewControl (/src/components/PreviewControl.tsx
)
- Complete preview management interface
- Features:
- Real-time status display with auto-refresh during build/deploy
- Start/Stop preview buttons
- Progress tracking during preview creation
- Error message display for failed previews
- Preview URL display when running
- "Open Preview" button for quick access
- Log viewer modal with refresh capability
- Expiration time display
UI Integration
App Show Page
- Two-column layout with app details on left, preview control on right
- Seamlessly integrated into existing app detail view
- Preview control only shows when app data is available
App List Page
- Added "Preview Status" column showing current status for each app
- Uses PreviewStatusBadge for consistent visual representation
- Helps users quickly identify which apps have active previews
API Integration
Endpoints Used
GET ${API_URL}/apps/{id}/preview
- Get preview status
POST ${API_URL}/apps/{id}/preview
- Start preview
POST ${API_URL}/apps/{id}/preview/stop
- Stop preview
GET ${API_URL}/apps/{id}/preview/logs
- Get preview logs
Configuration
- Uses centralized
API_URL
from /src/config.ts
- Properly handles environment variables via
VITE_API_URL
- Consistent with other API calls in the application
Features
- Automatic status polling during build/deploy phases (every 3 seconds)
- Error handling with user-friendly messages
- Loading states for all operations
- Success/error notifications
- Proper authentication and headers handling
User Experience
Visual Feedback
- Clear status indicators with colors and icons
- Progress bars during preview creation
- Tooltips explaining each status
- Alert messages for errors
- Loading states for all actions
Functionality
- One-click preview start/stop
- Direct access to running previews
- Real-time log viewing
- Automatic URL generation with fallback
- Expiration time awareness
URL Generation
- Primary: Uses API-provided URL when available
- Fallback: Generates URL using pattern
http://{app-name}-preview-{app-id}.byop.local
- Automatic sanitization of app names for URL compatibility
Error Handling
- Graceful 404 handling for apps without previews
- User-friendly error messages
- Retry capabilities
- Non-blocking error states
Next Steps
- Backend API testing and integration
- Real-time WebSocket integration for log streaming
- Preview expiration warnings
- Bulk preview operations
- Preview resource usage metrics
This implementation provides a complete, production-ready preview management system that seamlessly integrates with the existing BYOP dashboard architecture.