Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion frontend/src/components/EmployeeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,57 @@ interface Employee {

interface EmployeeListProps {
employees: Employee[];
isLoading?: boolean;
onEmployeeClick?: (employee: Employee) => void;
onAddEmployee: (employee: Employee) => void;
onEditEmployee?: (employee: Employee) => void;
onRemoveEmployee?: (id: string) => void;
onUpdateEmployeeImage?: (id: string, imageUrl: string) => void;
}

const SKELETON_ROW_COUNT = 5;

const EmployeeSkeletonRow: React.FC = () => (
<tr className="animate-pulse border-b border-gray-200/20">
{/* Name column */}
<td className="p-6">
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-full bg-gray-300/30 shrink-0" />
<div className="flex flex-col gap-1.5 flex-1 min-w-0">
<div className="h-2.5 rounded bg-gray-300/30 w-3/4" />
<div className="h-2 rounded bg-gray-300/20 w-1/2" />
</div>
</div>
</td>
{/* Role */}
<td className="p-6">
<div className="h-2.5 rounded bg-gray-300/30 w-2/3" />
</td>
{/* Wallet */}
<td className="p-6">
<div className="h-2.5 rounded bg-gray-300/20 w-3/4 font-mono" />
</td>
{/* Salary */}
<td className="p-6">
<div className="h-2.5 rounded bg-gray-300/30 w-1/2" />
</td>
{/* Status */}
<td className="p-6">
<div className="h-5 rounded-full bg-gray-300/20 w-16" />
</td>
{/* Actions */}
<td className="p-6">
<div className="flex gap-2">
<div className="w-5 h-5 rounded bg-gray-300/20" />
<div className="w-5 h-5 rounded bg-gray-300/20" />
</div>
</td>
</tr>
);

export const EmployeeList: React.FC<EmployeeListProps> = ({
employees,
isLoading = false,
onAddEmployee,
onEditEmployee,
onRemoveEmployee,
Expand Down Expand Up @@ -212,7 +254,11 @@ export const EmployeeList: React.FC<EmployeeListProps> = ({
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
{sortedEmployees.length === 0 ? (
{isLoading ? (
Array.from({ length: SKELETON_ROW_COUNT }, (_, i) => (
<EmployeeSkeletonRow key={i} />
))
) : sortedEmployees.length === 0 ? (
<tr>
<td colSpan={6} className="p-6 text-center text-gray-500">
{debouncedSearch ? `No employees match "${debouncedSearch}"` : 'No employees found'}
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/components/__tests__/EmployeeList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,24 @@ describe('EmployeeList', () => {
expect(email).toHaveAttribute('title', employee.email);
expect(email.className).toContain('truncate');
});

test('renders skeleton rows and hides employee data while loading', () => {
render(<EmployeeList employees={[employee]} isLoading onAddEmployee={vi.fn()} />);

// Employee data must not be visible during loading
expect(screen.queryByLabelText(`Employee name: ${employee.name}`)).toBeNull();
expect(screen.queryByLabelText(`Employee email: ${employee.email}`)).toBeNull();

// Skeleton rows are rendered with pulse animation
const rows = document.querySelectorAll('tbody tr');
expect(rows.length).toBe(5);
rows.forEach((row) => {
expect(row.className).toContain('animate-pulse');
});
});

test('renders empty state message when not loading and no employees exist', () => {
render(<EmployeeList employees={[]} isLoading={false} onAddEmployee={vi.fn()} />);
expect(screen.getByText('No employees found')).toBeTruthy();
});
});
Loading