Overview
TheFolderExplorer component manages Google Drive folder integration for entities in the SGD-MCS system. It displays folder status, provides sync/regeneration capabilities, and integrates file upload functionality.
Location: ~/workspace/source/Fronted/src/components/common/FolderExplorer.jsx:10
Features
- Display linked Google Drive folder with status badge
- Sync/regenerate Drive folder for entities
- Direct link to open folder in Google Drive
- Integrated file upload to entity folder
- Visual status indicators (synced/pending)
- Automatic refresh after folder creation
- Error handling with user-friendly messages
Props
The Google Drive folder ID associated with the entity
The full URL to the Google Drive folder
The type of entity (e.g., “student”, “professor”, “thesis”)
The unique identifier for the entity
Entity data object containing entity details
Callback function invoked when a folder is successfully created or synced. Receives
folderId and folderUrlImport
Usage Examples
- Linked Folder
- Unlinked Folder
- With Custom Entity Data
Visual States
Synced Folder (folderId && folderUrl present)
When a folder is linked, the component displays:- Google Drive icon
- “Carpeta en Google Drive” heading
- Green “SINCRONIZADO” status badge
- Folder URL preview (truncated)
- Three action buttons:
- SUBIR ARCHIVO: Opens file uploader modal
- ABRIR: Opens folder in new tab
- Sync icon: Re-synchronizes the folder
Pending/Unlinked Folder (no folderId or folderUrl)
When no folder is linked, the component displays:- Warning icon (AlertCircle)
- “Carpeta No Vinculada” heading
- Amber “PENDIENTE” status badge
- Explanation message
- CREAR CARPETA button to initiate sync
API Integration
The component uses theapi.drive.sync() method to create or sync folders:
File Upload Integration
The component integrates with theFileUploader component when the upload button is clicked:
Event Flow
Folder Creation/Sync Flow
- User clicks “CREAR CARPETA” or sync icon
- Confirmation dialog appears (using SweetAlert2)
- If confirmed, API call to
api.drive.sync()is made - Loading state is shown with animated spinner
- On success:
- Success toast notification
onFolderCreatedcallback invoked- Page reloads after 1.5s
- On error:
- Error toast notification
- Loading state clears
File Upload Flow
- User clicks “SUBIR ARCHIVO” button
- FileUploader modal opens
- User uploads files to the folder
- On completion:
- Success toast notification
- Modal closes
handleUploadCompletecallback invoked
Styling Features
Animations
- Fade-in and slide-in animations on mount
- Spin animation on sync button during loading
- Smooth hover transitions on buttons
- Scale and shadow effects on button hover
Responsive Design
- Flexbox layout that adapts to mobile (flex-col) and desktop (flex-row)
- Truncated URLs with max-width constraints
- Full-width buttons on mobile, auto-width on desktop
Dark Mode Support
- Full dark mode theming using Tailwind’s
dark:variants - Appropriate contrast ratios for all states
- Consistent color scheme across light and dark themes
Error Handling
Missing Entity Information
Missing Entity Information
If
entityType or entityId is not provided when attempting to regenerate a folder, an error toast is displayed:API Failures
API Failures
Network errors or API failures are caught and displayed with user-friendly messages:
Sync Failures
Sync Failures
If the API returns a non-success response, the error message from the API is displayed:
Dependencies
- lucide-react: Icons (Folder, ExternalLink, RefreshCw, etc.)
- api.drive.sync(): Drive API service
- toast: SweetAlert2 utility for notifications
- FileUploader: File upload component
Best Practices
Always Provide Entity Context
Always Provide Entity Context
Ensure
entityType and entityId are always provided to enable proper folder management.Handle Folder Creation Callback
Handle Folder Creation Callback
Implement
onFolderCreated to update parent component state and persist folder information to your backend.Consider Page Reload
Consider Page Reload
The component triggers a page reload after folder creation. Consider if this is necessary for your use case or if state updates are sufficient.
Test Drive API Integration
Test Drive API Integration
Ensure the Google Drive API is properly configured and the
api.drive.sync() endpoint is functional before deploying.Security Considerations
- The component assumes proper authentication is handled at the API level
- Folder URLs are displayed directly - ensure they are properly validated
- Entity data should be sanitized before passing to the component
- Consider implementing role-based access control for sync operations