Skip to main content

Overview

The FolderExplorer 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

folderId
string
The Google Drive folder ID associated with the entity
folderUrl
string
The full URL to the Google Drive folder
entityType
string
required
The type of entity (e.g., “student”, “professor”, “thesis”)
entityId
string
required
The unique identifier for the entity
entityData
object
Entity data object containing entity details
entityData={{
  Nombre1: "Juan",
  Apellido1: "Pérez"
}}
onFolderCreated
function
Callback function invoked when a folder is successfully created or synced. Receives folderId and folderUrl
onFolderCreated={(id, url) => {
  console.log('Folder created:', id, url);
}}

Import

import FolderExplorer from './components/common/FolderExplorer';

Usage Examples

import FolderExplorer from './components/common/FolderExplorer';

function StudentProfile({ student }) {
  const handleFolderUpdate = (id, url) => {
    console.log('Folder updated:', id, url);
    // Update parent component state
  };

  return (
    <div>
      <h2>{student.name}</h2>
      
      <FolderExplorer
        folderId={student.driveFolderId}
        folderUrl={student.driveFolderUrl}
        entityType="student"
        entityId={student.id}
        entityData={{
          Nombre1: student.firstName,
          Apellido1: student.lastName
        }}
        onFolderCreated={handleFolderUpdate}
      />
    </div>
  );
}

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 the api.drive.sync() method to create or sync folders:
// From FolderExplorer.jsx:29
const result = await api.drive.sync(entityType, entityId);
Expected API response:
{
  "success": true,
  "id": "1abc123def456",
  "url": "https://drive.google.com/drive/folders/1abc123def456"
}

File Upload Integration

The component integrates with the FileUploader component when the upload button is clicked:
// From FolderExplorer.jsx:114-123
{showUploader && (
    <FileUploader
        folderId={folderId}
        entityId={entityId}
        entityType={entityType}
        entityName={entityData ? `${entityData.Nombre1 || ''} ${entityData.Apellido1 || ''}`.trim() : ''}
        onClose={() => setShowUploader(false)}
        onUploadComplete={handleUploadComplete}
    />
)}

Event Flow

Folder Creation/Sync Flow

  1. User clicks “CREAR CARPETA” or sync icon
  2. Confirmation dialog appears (using SweetAlert2)
  3. If confirmed, API call to api.drive.sync() is made
  4. Loading state is shown with animated spinner
  5. On success:
    • Success toast notification
    • onFolderCreated callback invoked
    • Page reloads after 1.5s
  6. On error:
    • Error toast notification
    • Loading state clears

File Upload Flow

  1. User clicks “SUBIR ARCHIVO” button
  2. FileUploader modal opens
  3. User uploads files to the folder
  4. On completion:
    • Success toast notification
    • Modal closes
    • handleUploadComplete callback 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

If entityType or entityId is not provided when attempting to regenerate a folder, an error toast is displayed:
toast.error('Error', 'No se puede regenerar la carpeta sin tipo y ID de entidad');
Network errors or API failures are caught and displayed with user-friendly messages:
toast.error('Error', 'Falló la conexión con Drive');
If the API returns a non-success response, the error message from the API is displayed:
toast.error('Error', result.message || 'No se pudo sincronizar la carpeta');

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

Ensure entityType and entityId are always provided to enable proper folder management.
Implement onFolderCreated to update parent component state and persist folder information to your backend.
The component triggers a page reload after folder creation. Consider if this is necessary for your use case or if state updates are sufficient.
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

Build docs developers (and LLMs) love