forked from cardosofelipe/pragma-stack
Compare commits
7 Commits
e85788f79f
...
3ea1874638
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ea1874638 | ||
|
|
e1657d5ad8 | ||
|
|
83fa51fd4a | ||
|
|
db868c53c6 | ||
|
|
68f1865a1e | ||
|
|
5b1e2852ea | ||
|
|
d0a88d1fd1 |
202
frontend/e2e/activity-feed.spec.ts
Normal file
202
frontend/e2e/activity-feed.spec.ts
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* E2E Tests for Activity Feed Page
|
||||
*
|
||||
* Tests the real-time activity feed functionality:
|
||||
* - Page navigation and layout
|
||||
* - Event display and filtering
|
||||
* - Search functionality
|
||||
* - Approval handling
|
||||
* - Time-based grouping
|
||||
*/
|
||||
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Activity Feed Page', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Navigate to activity page (authenticated route)
|
||||
// The page uses demo mode when SSE is not connected
|
||||
await page.goto('/en/activity');
|
||||
});
|
||||
|
||||
test('displays page header with title', async ({ page }) => {
|
||||
await expect(page.getByRole('heading', { name: 'Activity Feed', level: 1 })).toBeVisible();
|
||||
await expect(page.getByText('Real-time updates from your projects')).toBeVisible();
|
||||
});
|
||||
|
||||
test('shows demo mode banner when not connected to SSE', async ({ page }) => {
|
||||
// Demo mode banner should be visible
|
||||
await expect(page.getByText(/Demo Mode/)).toBeVisible();
|
||||
await expect(page.getByText(/Showing sample events/)).toBeVisible();
|
||||
});
|
||||
|
||||
test('displays activity feed component', async ({ page }) => {
|
||||
await expect(page.getByTestId('activity-feed')).toBeVisible();
|
||||
});
|
||||
|
||||
test('displays demo events in time groups', async ({ page }) => {
|
||||
// Should have time-based grouping
|
||||
await expect(page.getByTestId('event-group-today')).toBeVisible();
|
||||
});
|
||||
|
||||
test('search functionality filters events', async ({ page }) => {
|
||||
const searchInput = page.getByTestId('search-input');
|
||||
await expect(searchInput).toBeVisible();
|
||||
|
||||
// Search for a specific term
|
||||
await searchInput.fill('JWT');
|
||||
|
||||
// Should find the JWT-related event
|
||||
await expect(page.getByText(/Completed JWT/)).toBeVisible();
|
||||
|
||||
// Clear search
|
||||
await searchInput.clear();
|
||||
});
|
||||
|
||||
test('filter panel toggles visibility', async ({ page }) => {
|
||||
const filterToggle = page.getByTestId('filter-toggle');
|
||||
await expect(filterToggle).toBeVisible();
|
||||
|
||||
// Click to open filter panel
|
||||
await filterToggle.click();
|
||||
await expect(page.getByTestId('filter-panel')).toBeVisible();
|
||||
|
||||
// Click to close filter panel
|
||||
await filterToggle.click();
|
||||
await expect(page.getByTestId('filter-panel')).not.toBeVisible();
|
||||
});
|
||||
|
||||
test('filter by event category', async ({ page }) => {
|
||||
// Open filter panel
|
||||
await page.getByTestId('filter-toggle').click();
|
||||
|
||||
// Select Agent Actions filter
|
||||
await page.getByLabel(/Agent Actions/).click();
|
||||
|
||||
// Should filter events
|
||||
// Agent events should still be visible
|
||||
await expect(page.getByText(/Completed JWT/)).toBeVisible();
|
||||
});
|
||||
|
||||
test('pending approvals filter', async ({ page }) => {
|
||||
// Open filter panel
|
||||
await page.getByTestId('filter-toggle').click();
|
||||
|
||||
// Select pending only filter
|
||||
await page.getByLabel(/Show only pending approvals/).click();
|
||||
|
||||
// Only approval events should be visible
|
||||
await expect(page.getByText(/Approval required/)).toBeVisible();
|
||||
await expect(page.getByText(/Completed JWT/)).not.toBeVisible();
|
||||
});
|
||||
|
||||
test('event item can be expanded', async ({ page }) => {
|
||||
// Find and click an event item
|
||||
const firstEvent = page.getByTestId(/event-item-/).first();
|
||||
await firstEvent.click();
|
||||
|
||||
// Event details should be visible
|
||||
await expect(page.getByTestId('event-details')).toBeVisible();
|
||||
|
||||
// Should show raw payload option
|
||||
await expect(page.getByText('View raw payload')).toBeVisible();
|
||||
});
|
||||
|
||||
test('approval actions are visible for pending approvals', async ({ page }) => {
|
||||
// Find approval event
|
||||
const approvalEvent = page.locator('[data-testid^="event-item-"]', {
|
||||
has: page.getByText('Action Required'),
|
||||
}).first();
|
||||
|
||||
// Approval buttons should be visible
|
||||
await expect(approvalEvent.getByTestId('approve-button')).toBeVisible();
|
||||
await expect(approvalEvent.getByTestId('reject-button')).toBeVisible();
|
||||
});
|
||||
|
||||
test('notification toggle works', async ({ page }) => {
|
||||
const bellButton = page.getByLabel(/notifications/i);
|
||||
await expect(bellButton).toBeVisible();
|
||||
|
||||
// Click to toggle notifications
|
||||
await bellButton.click();
|
||||
|
||||
// Bell icon should change (hard to verify icon change in E2E, but click should work)
|
||||
await expect(bellButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test('refresh button triggers reconnection', async ({ page }) => {
|
||||
const refreshButton = page.getByLabel('Refresh connection');
|
||||
await expect(refreshButton).toBeVisible();
|
||||
|
||||
// Click refresh
|
||||
await refreshButton.click();
|
||||
|
||||
// Button should still be visible and enabled
|
||||
await expect(refreshButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test('pending count badge shows correct count', async ({ page }) => {
|
||||
// Should show pending count
|
||||
await expect(page.getByText(/pending$/)).toBeVisible();
|
||||
});
|
||||
|
||||
test('keyboard navigation works for events', async ({ page }) => {
|
||||
// Tab to first event
|
||||
await page.keyboard.press('Tab');
|
||||
await page.keyboard.press('Tab');
|
||||
await page.keyboard.press('Tab');
|
||||
await page.keyboard.press('Tab');
|
||||
|
||||
// Find focused element and press Enter
|
||||
const focusedElement = page.locator(':focus');
|
||||
|
||||
// If it's an event item, pressing Enter should expand it
|
||||
const testId = await focusedElement.getAttribute('data-testid');
|
||||
if (testId?.startsWith('event-item-')) {
|
||||
await page.keyboard.press('Enter');
|
||||
await expect(page.getByTestId('event-details')).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test('clear filters button works', async ({ page }) => {
|
||||
// Open filter panel and set some filters
|
||||
await page.getByTestId('filter-toggle').click();
|
||||
await page.getByLabel(/Agent Actions/).click();
|
||||
|
||||
// Click clear filters
|
||||
await page.getByText('Clear Filters').click();
|
||||
|
||||
// All events should be visible again
|
||||
await expect(page.getByText(/Completed JWT/)).toBeVisible();
|
||||
await expect(page.getByText(/Approval required/)).toBeVisible();
|
||||
});
|
||||
|
||||
test('responsive layout adapts to viewport', async ({ page }) => {
|
||||
// Test mobile viewport
|
||||
await page.setViewportSize({ width: 375, height: 667 });
|
||||
|
||||
// Page should still be functional
|
||||
await expect(page.getByTestId('activity-feed')).toBeVisible();
|
||||
await expect(page.getByTestId('search-input')).toBeVisible();
|
||||
|
||||
// Reset viewport
|
||||
await page.setViewportSize({ width: 1280, height: 720 });
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Activity Feed - Authenticated Routes', () => {
|
||||
test('redirects to login when not authenticated', async ({ page }) => {
|
||||
// Clear any existing auth state
|
||||
await page.context().clearCookies();
|
||||
|
||||
// Try to access activity page
|
||||
await page.goto('/en/activity');
|
||||
|
||||
// Should redirect to login (AuthGuard behavior)
|
||||
// The exact behavior depends on AuthGuard implementation
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Either on activity page (if demo mode) or redirected to login
|
||||
const url = page.url();
|
||||
expect(url.includes('/activity') || url.includes('/login')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
18
frontend/e2e/global.d.ts
vendored
Normal file
18
frontend/e2e/global.d.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Global type declarations for E2E tests
|
||||
*/
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__TEST_AUTH_STORE__?: {
|
||||
getState: () => {
|
||||
isAuthenticated: boolean;
|
||||
user: { id: string; email: string; is_superuser: boolean } | null;
|
||||
accessToken: string | null;
|
||||
refreshToken: string | null;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
265
frontend/e2e/issues.spec.ts
Normal file
265
frontend/e2e/issues.spec.ts
Normal file
@@ -0,0 +1,265 @@
|
||||
/**
|
||||
* Issue Management E2E Tests
|
||||
*
|
||||
* Tests for the issue list and detail pages.
|
||||
*/
|
||||
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Issue Management', () => {
|
||||
// Use a test project ID
|
||||
const projectId = 'test-project-123';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Mock authentication - inject test auth store
|
||||
await page.addInitScript(() => {
|
||||
window.__TEST_AUTH_STORE__ = {
|
||||
getState: () => ({
|
||||
isAuthenticated: true,
|
||||
user: { id: 'test-user', email: 'test@example.com', is_superuser: false },
|
||||
accessToken: 'test-token',
|
||||
refreshToken: 'test-refresh',
|
||||
}),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Issue List Page', () => {
|
||||
test('displays issues list', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
// Wait for the page to load
|
||||
await expect(page.getByRole('heading', { name: /issues/i })).toBeVisible();
|
||||
|
||||
// Should show issue count
|
||||
await expect(page.getByText(/issues found/i)).toBeVisible();
|
||||
});
|
||||
|
||||
test('has search functionality', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
const searchInput = page.getByPlaceholder('Search issues...');
|
||||
await expect(searchInput).toBeVisible();
|
||||
|
||||
// Type in search
|
||||
await searchInput.fill('authentication');
|
||||
|
||||
// Wait for debounced search (mock data should filter)
|
||||
await page.waitForTimeout(500);
|
||||
});
|
||||
|
||||
test('has status filter', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
// Find status filter
|
||||
const statusFilter = page.getByRole('combobox', { name: /filter by status/i });
|
||||
await expect(statusFilter).toBeVisible();
|
||||
|
||||
// Open and select a status
|
||||
await statusFilter.click();
|
||||
await page.getByRole('option', { name: /in progress/i }).click();
|
||||
});
|
||||
|
||||
test('can toggle extended filters', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
// Extended filters should not be visible initially
|
||||
await expect(page.getByLabel('Priority')).not.toBeVisible();
|
||||
|
||||
// Click filter toggle
|
||||
await page.getByRole('button', { name: /toggle extended filters/i }).click();
|
||||
|
||||
// Extended filters should now be visible
|
||||
await expect(page.getByLabel('Priority')).toBeVisible();
|
||||
await expect(page.getByLabel('Sprint')).toBeVisible();
|
||||
await expect(page.getByLabel('Assignee')).toBeVisible();
|
||||
});
|
||||
|
||||
test('can select issues for bulk actions', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
// Wait for issues to load
|
||||
await page.waitForSelector('[data-testid^="issue-row-"]');
|
||||
|
||||
// Select first issue checkbox
|
||||
const firstCheckbox = page.getByRole('checkbox', { name: /select issue/i }).first();
|
||||
await firstCheckbox.click();
|
||||
|
||||
// Bulk actions bar should appear
|
||||
await expect(page.getByText('1 selected')).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: /change status/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('navigates to issue detail when clicking row', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
// Wait for issues to load
|
||||
await page.waitForSelector('[data-testid^="issue-row-"]');
|
||||
|
||||
// Click on first issue row
|
||||
await page.locator('[data-testid^="issue-row-"]').first().click();
|
||||
|
||||
// Should navigate to detail page
|
||||
await expect(page).toHaveURL(/\/issues\/[^/]+$/);
|
||||
});
|
||||
|
||||
test('has new issue button', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
await expect(page.getByRole('button', { name: /new issue/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('has sync button', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
await expect(page.getByRole('button', { name: /sync/i })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Issue Detail Page', () => {
|
||||
const issueId = 'ISS-001';
|
||||
|
||||
test('displays issue details', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Wait for the page to load
|
||||
await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
|
||||
|
||||
// Should show issue number
|
||||
await expect(page.getByText(/#\d+/)).toBeVisible();
|
||||
});
|
||||
|
||||
test('displays status badge', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Should show status
|
||||
await expect(
|
||||
page.getByText(/open|in progress|in review|blocked|done|closed/i).first()
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
test('displays priority badge', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Should show priority
|
||||
await expect(page.getByText(/high|medium|low/i).first()).toBeVisible();
|
||||
});
|
||||
|
||||
test('has back button', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
const backButton = page.getByRole('link', { name: /back to issues/i });
|
||||
await expect(backButton).toBeVisible();
|
||||
});
|
||||
|
||||
test('displays status workflow panel', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Should show status workflow
|
||||
await expect(page.getByRole('heading', { name: /status workflow/i })).toBeVisible();
|
||||
|
||||
// Should show all status options
|
||||
await expect(page.getByRole('radiogroup', { name: /issue status/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('displays activity timeline', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Should show activity section
|
||||
await expect(page.getByRole('heading', { name: /activity/i })).toBeVisible();
|
||||
|
||||
// Should have add comment button
|
||||
await expect(page.getByRole('button', { name: /add comment/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('displays issue details panel', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Should show details section
|
||||
await expect(page.getByRole('heading', { name: /details/i })).toBeVisible();
|
||||
|
||||
// Should show assignee info
|
||||
await expect(page.getByText(/assignee/i)).toBeVisible();
|
||||
});
|
||||
|
||||
test('can change status via workflow', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Wait for page to load
|
||||
await page.waitForSelector('[role="radiogroup"]');
|
||||
|
||||
// Click on a different status
|
||||
const inProgressOption = page.getByRole('radio', { name: /in progress/i });
|
||||
await inProgressOption.click();
|
||||
|
||||
// The status should update (optimistic update)
|
||||
await expect(inProgressOption).toHaveAttribute('aria-checked', 'true');
|
||||
});
|
||||
|
||||
test('displays description', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// Should show description heading
|
||||
await expect(page.getByRole('heading', { name: /description/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('shows edit button', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
await expect(page.getByRole('button', { name: /edit/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('shows external link when available', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/${issueId}`);
|
||||
|
||||
// The mock data includes an external URL
|
||||
await expect(page.getByRole('link', { name: /view in gitea/i })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Accessibility', () => {
|
||||
test('issue list has proper heading structure', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
// Main heading should be h1
|
||||
const h1 = page.getByRole('heading', { level: 1 });
|
||||
await expect(h1).toBeVisible();
|
||||
});
|
||||
|
||||
test('issue list table has proper ARIA labels', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues`);
|
||||
|
||||
// Wait for table to load
|
||||
await page.waitForSelector('[data-testid^="issue-row-"]');
|
||||
|
||||
// Checkboxes should have labels
|
||||
const checkboxes = page.getByRole('checkbox');
|
||||
const count = await checkboxes.count();
|
||||
expect(count).toBeGreaterThan(0);
|
||||
|
||||
// First checkbox should have accessible label
|
||||
await expect(checkboxes.first()).toHaveAccessibleName(/.+/);
|
||||
});
|
||||
|
||||
test('issue detail has proper radiogroup for status', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/ISS-001`);
|
||||
|
||||
// Status workflow should be a radiogroup
|
||||
const radiogroup = page.getByRole('radiogroup', { name: /issue status/i });
|
||||
await expect(radiogroup).toBeVisible();
|
||||
|
||||
// Each status should be a radio button
|
||||
const radios = page.getByRole('radio');
|
||||
const count = await radios.count();
|
||||
expect(count).toBe(6); // 6 statuses
|
||||
});
|
||||
|
||||
test('activity timeline has proper list structure', async ({ page }) => {
|
||||
await page.goto(`/en/projects/${projectId}/issues/ISS-001`);
|
||||
|
||||
// Activity should be a list
|
||||
const list = page.getByRole('list', { name: /issue activity/i });
|
||||
await expect(list).toBeVisible();
|
||||
});
|
||||
});
|
||||
});
|
||||
297
frontend/e2e/project-dashboard.spec.ts
Normal file
297
frontend/e2e/project-dashboard.spec.ts
Normal file
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
* E2E Tests for Project Dashboard Page
|
||||
*
|
||||
* Tests the single project view showing:
|
||||
* - Project header with status badges
|
||||
* - Agent panel with status indicators
|
||||
* - Sprint progress and burndown chart
|
||||
* - Issue summary sidebar
|
||||
* - Recent activity feed
|
||||
* - Quick actions (start/pause agents, create sprint)
|
||||
*
|
||||
* @module e2e/project-dashboard.spec
|
||||
* @see Issue #40
|
||||
*/
|
||||
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { setupAuthenticatedMocks, loginViaUI } from './helpers/auth';
|
||||
|
||||
test.describe('Project Dashboard Page', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Set up mock API endpoints
|
||||
await setupAuthenticatedMocks(page);
|
||||
});
|
||||
|
||||
test('should display project header with name and status badges', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
|
||||
// Navigate to a project dashboard
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check project header is present
|
||||
await expect(page.getByTestId('project-header')).toBeVisible();
|
||||
|
||||
// Check project name
|
||||
await expect(page.getByRole('heading', { level: 1 })).toContainText('E-Commerce Platform Redesign');
|
||||
|
||||
// Check status badges
|
||||
await expect(page.getByText('In Progress')).toBeVisible();
|
||||
await expect(page.getByText('Milestone')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should display agent panel with active agents', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check agent panel is present
|
||||
await expect(page.getByTestId('agent-panel')).toBeVisible();
|
||||
await expect(page.getByText('Active Agents')).toBeVisible();
|
||||
|
||||
// Check agent count
|
||||
await expect(page.getByText(/\d+ of \d+ agents working/)).toBeVisible();
|
||||
|
||||
// Check at least one agent is visible
|
||||
await expect(page.getByText('Product Owner')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should display sprint progress with stats', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check sprint progress is present
|
||||
await expect(page.getByTestId('sprint-progress')).toBeVisible();
|
||||
await expect(page.getByText('Sprint Overview')).toBeVisible();
|
||||
|
||||
// Check progress bar exists
|
||||
await expect(page.getByRole('progressbar')).toBeVisible();
|
||||
|
||||
// Check issue stats are shown
|
||||
await expect(page.getByText('Completed')).toBeVisible();
|
||||
await expect(page.getByText('In Progress')).toBeVisible();
|
||||
await expect(page.getByText('Blocked')).toBeVisible();
|
||||
|
||||
// Check burndown chart is present
|
||||
await expect(page.getByText('Burndown Chart')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should display issue summary sidebar', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check issue summary is present
|
||||
await expect(page.getByTestId('issue-summary')).toBeVisible();
|
||||
await expect(page.getByText('Issue Summary')).toBeVisible();
|
||||
|
||||
// Check issue counts by status
|
||||
await expect(page.getByText('Open')).toBeVisible();
|
||||
await expect(page.getByText('In Review')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should display recent activity feed', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check activity feed is present
|
||||
await expect(page.getByTestId('recent-activity')).toBeVisible();
|
||||
await expect(page.getByText('Recent Activity')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should have quick action buttons', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check quick actions are present
|
||||
await expect(page.getByRole('button', { name: /run sprint/i })).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: /new sprint/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('should have manage agents button', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check manage agents button
|
||||
await expect(page.getByRole('button', { name: /manage agents/i })).toBeVisible();
|
||||
});
|
||||
|
||||
test('should have view all issues button', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check view all issues button
|
||||
const viewAllButton = page.getByRole('button', { name: /view all issues/i });
|
||||
await expect(viewAllButton).toBeVisible();
|
||||
});
|
||||
|
||||
test('should have accessible heading hierarchy', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check for h1 (project name)
|
||||
await expect(page.locator('h1')).toBeVisible();
|
||||
|
||||
// Check for multiple headings
|
||||
const headings = page.getByRole('heading');
|
||||
const count = await headings.count();
|
||||
expect(count).toBeGreaterThan(3); // Project name + Agent Panel + Sprint + Activity
|
||||
});
|
||||
|
||||
test('should be keyboard navigable', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Tab through the page elements
|
||||
await page.keyboard.press('Tab');
|
||||
|
||||
// Should be able to focus on interactive elements
|
||||
const focusedElement = page.locator(':focus');
|
||||
await expect(focusedElement).toBeVisible();
|
||||
});
|
||||
|
||||
test('should show responsive layout on mobile', async ({ page }) => {
|
||||
// Set mobile viewport
|
||||
await page.setViewportSize({ width: 375, height: 667 });
|
||||
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Page should still be functional on mobile
|
||||
await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
|
||||
await expect(page.getByTestId('agent-panel')).toBeVisible();
|
||||
await expect(page.getByTestId('sprint-progress')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should load within acceptable time', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
|
||||
// Measure navigation timing
|
||||
const start = Date.now();
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
const duration = Date.now() - start;
|
||||
|
||||
// Dashboard should load within 5 seconds (including mock data)
|
||||
expect(duration).toBeLessThan(5000);
|
||||
});
|
||||
|
||||
test('should show SSE connection status when disconnected', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// When SSE is not connected, connection status should be visible
|
||||
// (Connected state hides the status indicator)
|
||||
// Since we don't have SSE mock, it will show as connecting/disconnected
|
||||
const connectionStatus = page.locator('[role="status"]').first();
|
||||
|
||||
// Either connection status is visible (not connected) or hidden (connected)
|
||||
// Both are valid states
|
||||
const count = await connectionStatus.count();
|
||||
expect(count).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Project Dashboard Agent Interactions', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await setupAuthenticatedMocks(page);
|
||||
});
|
||||
|
||||
test('should display agent action menu when clicking agent options', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Find the first agent's action menu button
|
||||
const agentActionButton = page
|
||||
.getByTestId('agent-panel')
|
||||
.getByRole('button', { name: /actions for/i })
|
||||
.first();
|
||||
|
||||
// Check button is visible and clickable
|
||||
await expect(agentActionButton).toBeVisible();
|
||||
await agentActionButton.click();
|
||||
|
||||
// Menu should show options
|
||||
await expect(page.getByText('View Details')).toBeVisible();
|
||||
await expect(page.getByText('Terminate Agent')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should show agent status indicators', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Look for status role elements within agent panel
|
||||
const statusIndicators = page.getByTestId('agent-panel').locator('[role="status"]');
|
||||
const count = await statusIndicators.count();
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Project Dashboard Sprint Interactions', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await setupAuthenticatedMocks(page);
|
||||
});
|
||||
|
||||
test('should display sprint selector when multiple sprints exist', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check for sprint selector combobox
|
||||
const sprintSelector = page.getByRole('combobox', { name: /select sprint/i });
|
||||
await expect(sprintSelector).toBeVisible();
|
||||
});
|
||||
|
||||
test('should show burndown chart legend', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check burndown chart has legend items
|
||||
await expect(page.getByText('Actual')).toBeVisible();
|
||||
await expect(page.getByText('Ideal')).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Project Dashboard Activity Feed', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await setupAuthenticatedMocks(page);
|
||||
});
|
||||
|
||||
test('should display activity items with timestamps', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check activity feed has content
|
||||
const activityFeed = page.getByTestId('recent-activity');
|
||||
await expect(activityFeed).toBeVisible();
|
||||
|
||||
// Check for relative timestamps (e.g., "5 minutes ago", "less than a minute ago")
|
||||
await expect(activityFeed.getByText(/ago|minute|hour|day/i).first()).toBeVisible();
|
||||
});
|
||||
|
||||
test('should highlight action-required activities', async ({ page }) => {
|
||||
await loginViaUI(page);
|
||||
await page.goto('/en/projects/proj-001');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Look for action buttons in activity feed (if any require action)
|
||||
const reviewButton = page.getByTestId('recent-activity').getByRole('button', { name: /review/i });
|
||||
const count = await reviewButton.count();
|
||||
|
||||
// Either there are action items or not - both are valid
|
||||
expect(count).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
238
frontend/src/app/[locale]/(authenticated)/activity/page.tsx
Normal file
238
frontend/src/app/[locale]/(authenticated)/activity/page.tsx
Normal file
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
* Activity Feed Page
|
||||
*
|
||||
* Full-page view of real-time project activity with:
|
||||
* - Real-time SSE connection
|
||||
* - Event filtering and search
|
||||
* - Time-based grouping
|
||||
* - Approval handling
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useProjectEvents } from '@/lib/hooks/useProjectEvents';
|
||||
import { ActivityFeed } from '@/components/activity';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { RefreshCw, Bell, BellOff, AlertTriangle } from 'lucide-react';
|
||||
import { EventType, type ProjectEvent } from '@/lib/types/events';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
// For demo purposes, use a placeholder project ID
|
||||
// In a real app, this would come from route params or user context
|
||||
const DEMO_PROJECT_ID = 'demo-project-001';
|
||||
|
||||
// Demo events for when SSE is not connected
|
||||
const DEMO_EVENTS: ProjectEvent[] = [
|
||||
{
|
||||
id: 'demo-001',
|
||||
type: EventType.APPROVAL_REQUESTED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 5).toISOString(),
|
||||
project_id: DEMO_PROJECT_ID,
|
||||
actor_id: 'agent-001',
|
||||
actor_type: 'agent',
|
||||
payload: {
|
||||
approval_id: 'apr-001',
|
||||
approval_type: 'architecture_decision',
|
||||
description: 'Approval required for API design document for the checkout flow.',
|
||||
requested_by: 'Architect',
|
||||
timeout_minutes: 60,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'demo-002',
|
||||
type: EventType.AGENT_MESSAGE,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 10).toISOString(),
|
||||
project_id: DEMO_PROJECT_ID,
|
||||
actor_id: 'agent-002',
|
||||
actor_type: 'agent',
|
||||
payload: {
|
||||
agent_instance_id: 'agent-002',
|
||||
message: 'Completed JWT token generation and validation. Moving on to session management.',
|
||||
message_type: 'info',
|
||||
metadata: { progress: 65 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'demo-003',
|
||||
type: EventType.AGENT_STATUS_CHANGED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 20).toISOString(),
|
||||
project_id: DEMO_PROJECT_ID,
|
||||
actor_id: 'agent-003',
|
||||
actor_type: 'agent',
|
||||
payload: {
|
||||
agent_instance_id: 'agent-003',
|
||||
previous_status: 'idle',
|
||||
new_status: 'active',
|
||||
reason: 'Started working on product catalog component',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'demo-004',
|
||||
type: EventType.ISSUE_UPDATED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 30).toISOString(),
|
||||
project_id: DEMO_PROJECT_ID,
|
||||
actor_id: 'agent-002',
|
||||
actor_type: 'agent',
|
||||
payload: {
|
||||
issue_id: 'issue-038',
|
||||
changes: { status: { from: 'in_progress', to: 'in_review' } },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'demo-005',
|
||||
type: EventType.SPRINT_STARTED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 2).toISOString(),
|
||||
project_id: DEMO_PROJECT_ID,
|
||||
actor_id: null,
|
||||
actor_type: 'system',
|
||||
payload: {
|
||||
sprint_id: 'sprint-003',
|
||||
sprint_name: 'Sprint 3 - Authentication',
|
||||
goal: 'Complete user authentication module',
|
||||
issue_count: 8,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'demo-006',
|
||||
type: EventType.WORKFLOW_COMPLETED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(),
|
||||
project_id: DEMO_PROJECT_ID,
|
||||
actor_id: null,
|
||||
actor_type: 'system',
|
||||
payload: {
|
||||
workflow_id: 'wf-001',
|
||||
duration_seconds: 3600,
|
||||
result: { issues_completed: 5, code_coverage: 92 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'demo-007',
|
||||
type: EventType.ISSUE_CREATED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 48).toISOString(),
|
||||
project_id: DEMO_PROJECT_ID,
|
||||
actor_id: 'agent-001',
|
||||
actor_type: 'agent',
|
||||
payload: {
|
||||
issue_id: 'issue-050',
|
||||
title: 'Add rate limiting to API endpoints',
|
||||
priority: 'medium',
|
||||
labels: ['security', 'api'],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default function ActivityFeedPage() {
|
||||
const [notificationsEnabled, setNotificationsEnabled] = useState(true);
|
||||
|
||||
// SSE hook for real-time events
|
||||
const {
|
||||
events: sseEvents,
|
||||
connectionState,
|
||||
reconnect,
|
||||
isConnected,
|
||||
} = useProjectEvents(DEMO_PROJECT_ID, {
|
||||
autoConnect: true,
|
||||
onEvent: (event) => {
|
||||
// Show notification for new events if enabled
|
||||
if (notificationsEnabled && event.type === EventType.APPROVAL_REQUESTED) {
|
||||
toast.info('New approval request', {
|
||||
description: 'An agent is requesting your approval.',
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Use demo events when not connected or no events received
|
||||
const events = isConnected && sseEvents.length > 0 ? sseEvents : DEMO_EVENTS;
|
||||
|
||||
// Approval handlers
|
||||
const handleApprove = useCallback((event: ProjectEvent) => {
|
||||
// In a real app, this would call an API to approve the request
|
||||
toast.success('Approval granted', {
|
||||
description: `Approved request ${event.id}`,
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleReject = useCallback((event: ProjectEvent) => {
|
||||
// In a real app, this would call an API to reject the request
|
||||
toast.info('Approval rejected', {
|
||||
description: `Rejected request ${event.id}`,
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleEventClick = useCallback((event: ProjectEvent) => {
|
||||
// In a real app, this might navigate to a detail view
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log('[ActivityFeedPage] Event clicked:', event);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const pendingCount = events.filter((e) => e.type === EventType.APPROVAL_REQUESTED).length;
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<div className="mx-auto max-w-4xl space-y-6">
|
||||
{/* Page Header */}
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Activity Feed</h1>
|
||||
<p className="mt-1 text-muted-foreground">Real-time updates from your projects</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{pendingCount > 0 && (
|
||||
<Badge variant="destructive" className="gap-1">
|
||||
<AlertTriangle className="h-3 w-3" />
|
||||
{pendingCount} pending
|
||||
</Badge>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => setNotificationsEnabled(!notificationsEnabled)}
|
||||
aria-label={notificationsEnabled ? 'Disable notifications' : 'Enable notifications'}
|
||||
>
|
||||
{notificationsEnabled ? (
|
||||
<Bell className="h-4 w-4" />
|
||||
) : (
|
||||
<BellOff className="h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={reconnect}
|
||||
aria-label="Refresh connection"
|
||||
>
|
||||
<RefreshCw className={connectionState === 'connecting' ? 'h-4 w-4 animate-spin' : 'h-4 w-4'} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Demo Mode Banner */}
|
||||
{(!isConnected || sseEvents.length === 0) && (
|
||||
<div className="rounded-lg border border-yellow-200 bg-yellow-50 p-4 dark:border-yellow-800 dark:bg-yellow-950">
|
||||
<p className="text-sm text-yellow-800 dark:text-yellow-200">
|
||||
<strong>Demo Mode:</strong> Showing sample events. Connect to a real project to see live updates.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Activity Feed Component */}
|
||||
<ActivityFeed
|
||||
events={events}
|
||||
connectionState={isConnected ? connectionState : 'disconnected'}
|
||||
onReconnect={reconnect}
|
||||
onApprove={handleApprove}
|
||||
onReject={handleReject}
|
||||
onEventClick={handleEventClick}
|
||||
maxHeight={600}
|
||||
showHeader={false}
|
||||
enableFiltering
|
||||
enableSearch
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
194
frontend/src/app/[locale]/(authenticated)/agents/[id]/page.tsx
Normal file
194
frontend/src/app/[locale]/(authenticated)/agents/[id]/page.tsx
Normal file
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* Agent Type Detail/Edit Page
|
||||
*
|
||||
* Displays agent type details with options to edit, duplicate, or deactivate.
|
||||
* Handles 'new' as a special ID to show the create form.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useRouter, useParams } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
import { AgentTypeDetail, AgentTypeForm } from '@/components/agents';
|
||||
import {
|
||||
useAgentType,
|
||||
useCreateAgentType,
|
||||
useUpdateAgentType,
|
||||
useDeactivateAgentType,
|
||||
useDuplicateAgentType,
|
||||
} from '@/lib/api/hooks/useAgentTypes';
|
||||
import type { AgentTypeCreateFormValues } from '@/lib/validations/agentType';
|
||||
|
||||
type ViewMode = 'detail' | 'edit' | 'create';
|
||||
|
||||
export default function AgentTypeDetailPage() {
|
||||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const id = params.id as string;
|
||||
|
||||
// Determine initial view mode
|
||||
const isNew = id === 'new';
|
||||
const [viewMode, setViewMode] = useState<ViewMode>(isNew ? 'create' : 'detail');
|
||||
|
||||
// Fetch agent type data (skip if creating new)
|
||||
const {
|
||||
data: agentType,
|
||||
isLoading,
|
||||
error,
|
||||
} = useAgentType(isNew ? null : id);
|
||||
|
||||
// Mutations
|
||||
const createMutation = useCreateAgentType();
|
||||
const updateMutation = useUpdateAgentType();
|
||||
const deactivateMutation = useDeactivateAgentType();
|
||||
const duplicateMutation = useDuplicateAgentType();
|
||||
|
||||
// Handle navigation back to list
|
||||
const handleBack = useCallback(() => {
|
||||
if (viewMode === 'edit') {
|
||||
setViewMode('detail');
|
||||
} else {
|
||||
router.push('/agents');
|
||||
}
|
||||
}, [router, viewMode]);
|
||||
|
||||
// Handle edit button click
|
||||
const handleEdit = useCallback(() => {
|
||||
setViewMode('edit');
|
||||
}, []);
|
||||
|
||||
// Handle form submission for create/update
|
||||
const handleSubmit = useCallback(
|
||||
async (data: AgentTypeCreateFormValues) => {
|
||||
try {
|
||||
if (isNew || viewMode === 'create') {
|
||||
// Create new agent type
|
||||
const result = await createMutation.mutateAsync({
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
expertise: data.expertise,
|
||||
personality_prompt: data.personality_prompt,
|
||||
primary_model: data.primary_model,
|
||||
fallback_models: data.fallback_models,
|
||||
model_params: data.model_params,
|
||||
mcp_servers: data.mcp_servers,
|
||||
tool_permissions: data.tool_permissions,
|
||||
is_active: data.is_active,
|
||||
});
|
||||
toast.success('Agent type created', {
|
||||
description: `${result.name} has been created successfully`,
|
||||
});
|
||||
router.push(`/agents/${result.id}`);
|
||||
} else {
|
||||
// Update existing agent type
|
||||
const result = await updateMutation.mutateAsync({
|
||||
id,
|
||||
data: {
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
expertise: data.expertise,
|
||||
personality_prompt: data.personality_prompt,
|
||||
primary_model: data.primary_model,
|
||||
fallback_models: data.fallback_models,
|
||||
model_params: data.model_params,
|
||||
mcp_servers: data.mcp_servers,
|
||||
tool_permissions: data.tool_permissions,
|
||||
is_active: data.is_active,
|
||||
},
|
||||
});
|
||||
toast.success('Agent type updated', {
|
||||
description: `${result.name} has been updated successfully`,
|
||||
});
|
||||
setViewMode('detail');
|
||||
}
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'An error occurred';
|
||||
toast.error('Failed to save agent type', { description: message });
|
||||
}
|
||||
},
|
||||
[id, isNew, viewMode, createMutation, updateMutation, router]
|
||||
);
|
||||
|
||||
// Handle duplicate
|
||||
const handleDuplicate = useCallback(async () => {
|
||||
if (!agentType) return;
|
||||
|
||||
try {
|
||||
const result = await duplicateMutation.mutateAsync(agentType);
|
||||
toast.success('Agent type duplicated', {
|
||||
description: `${result.name} has been created`,
|
||||
});
|
||||
router.push(`/agents/${result.id}`);
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'An error occurred';
|
||||
toast.error('Failed to duplicate agent type', { description: message });
|
||||
}
|
||||
}, [agentType, duplicateMutation, router]);
|
||||
|
||||
// Handle deactivate
|
||||
const handleDeactivate = useCallback(async () => {
|
||||
try {
|
||||
await deactivateMutation.mutateAsync(id);
|
||||
toast.success('Agent type deactivated', {
|
||||
description: 'The agent type has been deactivated',
|
||||
});
|
||||
router.push('/agents');
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'An error occurred';
|
||||
toast.error('Failed to deactivate agent type', { description: message });
|
||||
}
|
||||
}, [id, deactivateMutation, router]);
|
||||
|
||||
// Handle cancel from form
|
||||
const handleCancel = useCallback(() => {
|
||||
if (isNew) {
|
||||
router.push('/agents');
|
||||
} else {
|
||||
setViewMode('detail');
|
||||
}
|
||||
}, [isNew, router]);
|
||||
|
||||
// Show error state
|
||||
if (error && !isNew) {
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
<AgentTypeDetail
|
||||
agentType={null}
|
||||
onBack={handleBack}
|
||||
onEdit={handleEdit}
|
||||
onDuplicate={handleDuplicate}
|
||||
onDeactivate={handleDeactivate}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Render based on view mode
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
{(viewMode === 'create' || viewMode === 'edit') && (
|
||||
<AgentTypeForm
|
||||
agentType={viewMode === 'edit' ? agentType ?? undefined : undefined}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
isSubmitting={createMutation.isPending || updateMutation.isPending}
|
||||
/>
|
||||
)}
|
||||
|
||||
{viewMode === 'detail' && (
|
||||
<AgentTypeDetail
|
||||
agentType={agentType ?? null}
|
||||
isLoading={isLoading}
|
||||
onBack={handleBack}
|
||||
onEdit={handleEdit}
|
||||
onDuplicate={handleDuplicate}
|
||||
onDeactivate={handleDeactivate}
|
||||
isDeactivating={deactivateMutation.isPending}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
95
frontend/src/app/[locale]/(authenticated)/agents/page.tsx
Normal file
95
frontend/src/app/[locale]/(authenticated)/agents/page.tsx
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Agent Types List Page
|
||||
*
|
||||
* Displays a list of agent types with search and filter functionality.
|
||||
* Allows navigation to agent type detail and creation pages.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback, useMemo } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
import { AgentTypeList } from '@/components/agents';
|
||||
import { useAgentTypes } from '@/lib/api/hooks/useAgentTypes';
|
||||
import { useDebounce } from '@/lib/hooks/useDebounce';
|
||||
|
||||
export default function AgentTypesPage() {
|
||||
const router = useRouter();
|
||||
|
||||
// Filter state
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [statusFilter, setStatusFilter] = useState('all');
|
||||
|
||||
// Debounce search for API calls
|
||||
const debouncedSearch = useDebounce(searchQuery, 300);
|
||||
|
||||
// Determine is_active filter value
|
||||
const isActiveFilter = useMemo(() => {
|
||||
if (statusFilter === 'active') return true;
|
||||
if (statusFilter === 'inactive') return false;
|
||||
return undefined; // 'all' returns undefined to not filter
|
||||
}, [statusFilter]);
|
||||
|
||||
// Fetch agent types
|
||||
const { data, isLoading, error } = useAgentTypes({
|
||||
search: debouncedSearch || undefined,
|
||||
is_active: isActiveFilter,
|
||||
page: 1,
|
||||
limit: 50,
|
||||
});
|
||||
|
||||
// Filter results client-side for 'all' status
|
||||
const filteredAgentTypes = useMemo(() => {
|
||||
if (!data?.data) return [];
|
||||
|
||||
// When status is 'all', we need to fetch both and combine
|
||||
// For now, the API returns based on is_active filter
|
||||
return data.data;
|
||||
}, [data?.data]);
|
||||
|
||||
// Handle navigation to agent type detail
|
||||
const handleSelect = useCallback(
|
||||
(id: string) => {
|
||||
router.push(`/agents/${id}`);
|
||||
},
|
||||
[router]
|
||||
);
|
||||
|
||||
// Handle navigation to create page
|
||||
const handleCreate = useCallback(() => {
|
||||
router.push('/agents/new');
|
||||
}, [router]);
|
||||
|
||||
// Handle search change
|
||||
const handleSearchChange = useCallback((query: string) => {
|
||||
setSearchQuery(query);
|
||||
}, []);
|
||||
|
||||
// Handle status filter change
|
||||
const handleStatusFilterChange = useCallback((status: string) => {
|
||||
setStatusFilter(status);
|
||||
}, []);
|
||||
|
||||
// Show error toast if fetch fails
|
||||
if (error) {
|
||||
toast.error('Failed to load agent types', {
|
||||
description: 'Please try again later',
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
<AgentTypeList
|
||||
agentTypes={filteredAgentTypes}
|
||||
isLoading={isLoading}
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={handleSearchChange}
|
||||
statusFilter={statusFilter}
|
||||
onStatusFilterChange={handleStatusFilterChange}
|
||||
onSelect={handleSelect}
|
||||
onCreate={handleCreate}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Issue Detail Page
|
||||
*
|
||||
* Displays full issue details with status workflow and activity timeline.
|
||||
*
|
||||
* @module app/[locale]/(authenticated)/projects/[id]/issues/[issueId]/page
|
||||
*/
|
||||
|
||||
import { use } from 'react';
|
||||
import Link from 'next/link';
|
||||
import {
|
||||
ArrowLeft,
|
||||
Calendar,
|
||||
Clock,
|
||||
ExternalLink,
|
||||
Edit,
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import {
|
||||
StatusBadge,
|
||||
PriorityBadge,
|
||||
SyncStatusIndicator,
|
||||
StatusWorkflow,
|
||||
ActivityTimeline,
|
||||
IssueDetailPanel,
|
||||
useIssue,
|
||||
useUpdateIssueStatus,
|
||||
getPrimaryTransition,
|
||||
} from '@/features/issues';
|
||||
import type { IssueStatus } from '@/features/issues';
|
||||
|
||||
interface IssueDetailPageProps {
|
||||
params: Promise<{
|
||||
locale: string;
|
||||
id: string;
|
||||
issueId: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export default function IssueDetailPage({ params }: IssueDetailPageProps) {
|
||||
const { locale, id: projectId, issueId } = use(params);
|
||||
|
||||
const { data: issue, isLoading, error } = useIssue(issueId);
|
||||
const updateStatus = useUpdateIssueStatus();
|
||||
|
||||
const handleStatusChange = (status: IssueStatus) => {
|
||||
updateStatus.mutate({ issueId, status });
|
||||
};
|
||||
|
||||
const primaryTransition = issue ? getPrimaryTransition(issue.status) : undefined;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<div className="rounded-lg border border-destructive bg-destructive/10 p-6 text-center">
|
||||
<h2 className="text-lg font-semibold text-destructive">Error Loading Issue</h2>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
Failed to load issue details. Please try again later.
|
||||
</p>
|
||||
<div className="mt-4 flex justify-center gap-2">
|
||||
<Link href={`/${locale}/projects/${projectId}/issues`}>
|
||||
<Button variant="outline">Back to Issues</Button>
|
||||
</Link>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => window.location.reload()}
|
||||
>
|
||||
Retry
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading || !issue) {
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-start gap-4">
|
||||
<Skeleton className="h-10 w-10" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-6 w-48" />
|
||||
<Skeleton className="h-8 w-96" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
<Skeleton className="h-64 w-full" />
|
||||
<Skeleton className="h-96 w-full" />
|
||||
</div>
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-64 w-full" />
|
||||
<Skeleton className="h-48 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-start gap-4">
|
||||
<Link href={`/${locale}/projects/${projectId}/issues`}>
|
||||
<Button variant="ghost" size="icon" aria-label="Back to issues">
|
||||
<ArrowLeft className="h-4 w-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="flex-1 space-y-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="font-mono text-muted-foreground">#{issue.number}</span>
|
||||
<StatusBadge status={issue.status} />
|
||||
<PriorityBadge priority={issue.priority} />
|
||||
<SyncStatusIndicator status={issue.sync_status} showLabel />
|
||||
</div>
|
||||
<h1 className="text-2xl font-bold">{issue.title}</h1>
|
||||
<div className="flex flex-wrap items-center gap-4 text-sm text-muted-foreground">
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="h-4 w-4" aria-hidden="true" />
|
||||
Created {new Date(issue.created_at).toLocaleDateString()}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Clock className="h-4 w-4" aria-hidden="true" />
|
||||
Updated {new Date(issue.updated_at).toLocaleDateString()}
|
||||
</div>
|
||||
{issue.external_url && (
|
||||
<a
|
||||
href={issue.external_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center gap-1 text-primary hover:underline"
|
||||
>
|
||||
<ExternalLink className="h-4 w-4" aria-hidden="true" />
|
||||
View in Gitea
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" size="sm">
|
||||
<Edit className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
Edit
|
||||
</Button>
|
||||
{primaryTransition && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => handleStatusChange(primaryTransition.to)}
|
||||
disabled={updateStatus.isPending}
|
||||
>
|
||||
{updateStatus.isPending ? 'Updating...' : primaryTransition.label}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
{/* Main Content */}
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
{/* Description Card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Description</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="prose prose-sm max-w-none dark:prose-invert">
|
||||
<pre className="whitespace-pre-wrap font-sans text-sm">
|
||||
{issue.description}
|
||||
</pre>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Activity Timeline */}
|
||||
<ActivityTimeline
|
||||
activities={issue.activity}
|
||||
onAddComment={() => console.log('Add comment')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Sidebar */}
|
||||
<div className="space-y-6">
|
||||
{/* Status Workflow */}
|
||||
<StatusWorkflow
|
||||
currentStatus={issue.status}
|
||||
onStatusChange={handleStatusChange}
|
||||
disabled={updateStatus.isPending}
|
||||
/>
|
||||
|
||||
{/* Issue Details */}
|
||||
<IssueDetailPanel issue={issue} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Project Issues List Page
|
||||
*
|
||||
* Displays filterable, sortable list of issues for a project.
|
||||
* Supports bulk actions and sync with external trackers.
|
||||
*
|
||||
* @module app/[locale]/(authenticated)/projects/[id]/issues/page
|
||||
*/
|
||||
|
||||
import { useState, use } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Plus, Upload } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import {
|
||||
IssueFilters,
|
||||
IssueTable,
|
||||
BulkActions,
|
||||
useIssues,
|
||||
} from '@/features/issues';
|
||||
import type { IssueFiltersType, IssueSort } from '@/features/issues';
|
||||
|
||||
interface ProjectIssuesPageProps {
|
||||
params: Promise<{
|
||||
locale: string;
|
||||
id: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export default function ProjectIssuesPage({ params }: ProjectIssuesPageProps) {
|
||||
const { locale, id: projectId } = use(params);
|
||||
const router = useRouter();
|
||||
|
||||
// Filter state
|
||||
const [filters, setFilters] = useState<IssueFiltersType>({
|
||||
status: 'all',
|
||||
priority: 'all',
|
||||
sprint: 'all',
|
||||
assignee: 'all',
|
||||
});
|
||||
|
||||
// Sort state
|
||||
const [sort, setSort] = useState<IssueSort>({
|
||||
field: 'updated_at',
|
||||
direction: 'desc',
|
||||
});
|
||||
|
||||
// Selection state
|
||||
const [selectedIssues, setSelectedIssues] = useState<string[]>([]);
|
||||
|
||||
// Fetch issues
|
||||
const { data, isLoading, error } = useIssues(projectId, filters, sort);
|
||||
|
||||
const handleIssueClick = (issueId: string) => {
|
||||
router.push(`/${locale}/projects/${projectId}/issues/${issueId}`);
|
||||
};
|
||||
|
||||
const handleBulkChangeStatus = () => {
|
||||
// TODO: Open status change dialog
|
||||
console.log('Change status for:', selectedIssues);
|
||||
};
|
||||
|
||||
const handleBulkAssign = () => {
|
||||
// TODO: Open assign dialog
|
||||
console.log('Assign:', selectedIssues);
|
||||
};
|
||||
|
||||
const handleBulkAddLabels = () => {
|
||||
// TODO: Open labels dialog
|
||||
console.log('Add labels to:', selectedIssues);
|
||||
};
|
||||
|
||||
const handleBulkDelete = () => {
|
||||
// TODO: Confirm and delete
|
||||
console.log('Delete:', selectedIssues);
|
||||
};
|
||||
|
||||
const handleSync = () => {
|
||||
// TODO: Sync all issues
|
||||
console.log('Sync issues');
|
||||
};
|
||||
|
||||
const handleNewIssue = () => {
|
||||
// TODO: Navigate to new issue page or open dialog
|
||||
console.log('Create new issue');
|
||||
};
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<div className="rounded-lg border border-destructive bg-destructive/10 p-6 text-center">
|
||||
<h2 className="text-lg font-semibold text-destructive">Error Loading Issues</h2>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
Failed to load issues. Please try again later.
|
||||
</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mt-4"
|
||||
onClick={() => window.location.reload()}
|
||||
>
|
||||
Retry
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold">Issues</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{isLoading ? (
|
||||
<Skeleton className="h-4 w-24" />
|
||||
) : (
|
||||
`${data?.pagination.total || 0} issues found`
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" size="sm" onClick={handleSync}>
|
||||
<Upload className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
Sync
|
||||
</Button>
|
||||
<Button size="sm" onClick={handleNewIssue}>
|
||||
<Plus className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
New Issue
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filters */}
|
||||
<IssueFilters filters={filters} onFiltersChange={setFilters} />
|
||||
|
||||
{/* Bulk Actions */}
|
||||
<BulkActions
|
||||
selectedCount={selectedIssues.length}
|
||||
onChangeStatus={handleBulkChangeStatus}
|
||||
onAssign={handleBulkAssign}
|
||||
onAddLabels={handleBulkAddLabels}
|
||||
onDelete={handleBulkDelete}
|
||||
/>
|
||||
|
||||
{/* Issue Table */}
|
||||
{isLoading ? (
|
||||
<div className="space-y-2">
|
||||
{[...Array(5)].map((_, i) => (
|
||||
<Skeleton key={i} className="h-16 w-full" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<IssueTable
|
||||
issues={data?.data || []}
|
||||
selectedIssues={selectedIssues}
|
||||
onSelectionChange={setSelectedIssues}
|
||||
onIssueClick={handleIssueClick}
|
||||
sort={sort}
|
||||
onSortChange={setSort}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Pagination info */}
|
||||
{data && data.pagination.total > 0 && (
|
||||
<div className="flex items-center justify-between text-sm text-muted-foreground">
|
||||
<span>
|
||||
Showing {(data.pagination.page - 1) * data.pagination.page_size + 1} to{' '}
|
||||
{Math.min(
|
||||
data.pagination.page * data.pagination.page_size,
|
||||
data.pagination.total
|
||||
)}{' '}
|
||||
of {data.pagination.total} issues
|
||||
</span>
|
||||
{data.pagination.total_pages > 1 && (
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={!data.pagination.has_prev}
|
||||
>
|
||||
Previous
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={!data.pagination.has_next}
|
||||
>
|
||||
Next
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Project Dashboard Page
|
||||
*
|
||||
* Main dashboard for viewing project status, agents, sprints, and activity.
|
||||
* Provides real-time updates via SSE and quick actions for project management.
|
||||
*
|
||||
* @see Issue #40
|
||||
*/
|
||||
|
||||
import { Metadata } from 'next';
|
||||
import { ProjectDashboard } from '@/components/projects/ProjectDashboard';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Project Dashboard',
|
||||
description: 'View project status, agents, sprints, and activity',
|
||||
};
|
||||
|
||||
interface ProjectDashboardPageProps {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
locale: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export default async function ProjectDashboardPage({ params }: ProjectDashboardPageProps) {
|
||||
const { id } = await params;
|
||||
|
||||
return <ProjectDashboard projectId={id} />;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* New Project Page
|
||||
*
|
||||
* Multi-step wizard for creating new Syndarix projects.
|
||||
*/
|
||||
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { ProjectWizard } from '@/components/projects';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'New Project',
|
||||
description: 'Create a new Syndarix project with AI-powered agents',
|
||||
};
|
||||
|
||||
interface NewProjectPageProps {
|
||||
params: Promise<{ locale: string }>;
|
||||
}
|
||||
|
||||
export default async function NewProjectPage({ params }: NewProjectPageProps) {
|
||||
const { locale } = await params;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background">
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<ProjectWizard locale={locale} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
928
frontend/src/components/activity/ActivityFeed.tsx
Normal file
928
frontend/src/components/activity/ActivityFeed.tsx
Normal file
@@ -0,0 +1,928 @@
|
||||
/**
|
||||
* ActivityFeed Component
|
||||
*
|
||||
* A shared real-time activity feed component used across:
|
||||
* - Main Dashboard
|
||||
* - Project Dashboard
|
||||
* - Activity Feed page
|
||||
*
|
||||
* Features:
|
||||
* - Real-time connection indicator
|
||||
* - Time-based event grouping (Today, Yesterday, This Week, etc.)
|
||||
* - Event type filtering
|
||||
* - Expandable event details
|
||||
* - Approval request handling
|
||||
* - Search functionality
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useState, useMemo, useCallback } from 'react';
|
||||
import { formatDistanceToNow, isToday, isYesterday, isThisWeek } from 'date-fns';
|
||||
import {
|
||||
Activity,
|
||||
Bot,
|
||||
FileText,
|
||||
Users,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
PlayCircle,
|
||||
AlertTriangle,
|
||||
Folder,
|
||||
Workflow,
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
Search,
|
||||
Filter,
|
||||
RefreshCw,
|
||||
CircleDot,
|
||||
GitPullRequest,
|
||||
ExternalLink,
|
||||
} from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import {
|
||||
EventType,
|
||||
type ProjectEvent,
|
||||
isAgentEvent,
|
||||
isIssueEvent,
|
||||
isSprintEvent,
|
||||
isApprovalEvent,
|
||||
isWorkflowEvent,
|
||||
isProjectEvent,
|
||||
} from '@/lib/types/events';
|
||||
import type { ConnectionState } from '@/lib/types/events';
|
||||
|
||||
// ============================================================================
|
||||
// Types
|
||||
// ============================================================================
|
||||
|
||||
export interface ActivityFeedProps {
|
||||
/** Events to display */
|
||||
events: ProjectEvent[];
|
||||
/** SSE connection state */
|
||||
connectionState: ConnectionState;
|
||||
/** Whether data is loading */
|
||||
isLoading?: boolean;
|
||||
/** Callback to trigger reconnection */
|
||||
onReconnect?: () => void;
|
||||
/** Callback when an approval is approved */
|
||||
onApprove?: (event: ProjectEvent) => void;
|
||||
/** Callback when an approval is rejected */
|
||||
onReject?: (event: ProjectEvent) => void;
|
||||
/** Callback when event is clicked */
|
||||
onEventClick?: (event: ProjectEvent) => void;
|
||||
/** Maximum height for scrolling (default: 'auto') */
|
||||
maxHeight?: number | string;
|
||||
/** Whether to show the header (default: true) */
|
||||
showHeader?: boolean;
|
||||
/** Title for the header (default: 'Activity Feed') */
|
||||
title?: string;
|
||||
/** Whether to enable filtering (default: true) */
|
||||
enableFiltering?: boolean;
|
||||
/** Whether to enable search (default: true) */
|
||||
enableSearch?: boolean;
|
||||
/** Show compact view (default: false) */
|
||||
compact?: boolean;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export interface EventTypeFilter {
|
||||
type: EventType | 'all';
|
||||
label: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface EventGroup {
|
||||
label: string;
|
||||
events: ProjectEvent[];
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Event Configuration
|
||||
// ============================================================================
|
||||
|
||||
const EVENT_TYPE_CONFIG: Record<
|
||||
string,
|
||||
{
|
||||
label: string;
|
||||
icon: typeof Activity;
|
||||
color: string;
|
||||
bgColor: string;
|
||||
}
|
||||
> = {
|
||||
// Agent Events
|
||||
[EventType.AGENT_SPAWNED]: {
|
||||
label: 'Agent Spawned',
|
||||
icon: Bot,
|
||||
color: 'text-blue-500',
|
||||
bgColor: 'bg-blue-100 dark:bg-blue-900',
|
||||
},
|
||||
[EventType.AGENT_MESSAGE]: {
|
||||
label: 'Agent Message',
|
||||
icon: Bot,
|
||||
color: 'text-blue-500',
|
||||
bgColor: 'bg-blue-100 dark:bg-blue-900',
|
||||
},
|
||||
[EventType.AGENT_STATUS_CHANGED]: {
|
||||
label: 'Status Changed',
|
||||
icon: Bot,
|
||||
color: 'text-yellow-500',
|
||||
bgColor: 'bg-yellow-100 dark:bg-yellow-900',
|
||||
},
|
||||
[EventType.AGENT_TERMINATED]: {
|
||||
label: 'Agent Terminated',
|
||||
icon: Bot,
|
||||
color: 'text-gray-500',
|
||||
bgColor: 'bg-gray-100 dark:bg-gray-800',
|
||||
},
|
||||
// Issue Events
|
||||
[EventType.ISSUE_CREATED]: {
|
||||
label: 'Issue Created',
|
||||
icon: CircleDot,
|
||||
color: 'text-green-500',
|
||||
bgColor: 'bg-green-100 dark:bg-green-900',
|
||||
},
|
||||
[EventType.ISSUE_UPDATED]: {
|
||||
label: 'Issue Updated',
|
||||
icon: FileText,
|
||||
color: 'text-blue-500',
|
||||
bgColor: 'bg-blue-100 dark:bg-blue-900',
|
||||
},
|
||||
[EventType.ISSUE_ASSIGNED]: {
|
||||
label: 'Issue Assigned',
|
||||
icon: Users,
|
||||
color: 'text-purple-500',
|
||||
bgColor: 'bg-purple-100 dark:bg-purple-900',
|
||||
},
|
||||
[EventType.ISSUE_CLOSED]: {
|
||||
label: 'Issue Closed',
|
||||
icon: CheckCircle2,
|
||||
color: 'text-green-600',
|
||||
bgColor: 'bg-green-100 dark:bg-green-900',
|
||||
},
|
||||
// Sprint Events
|
||||
[EventType.SPRINT_STARTED]: {
|
||||
label: 'Sprint Started',
|
||||
icon: PlayCircle,
|
||||
color: 'text-indigo-500',
|
||||
bgColor: 'bg-indigo-100 dark:bg-indigo-900',
|
||||
},
|
||||
[EventType.SPRINT_COMPLETED]: {
|
||||
label: 'Sprint Completed',
|
||||
icon: CheckCircle2,
|
||||
color: 'text-indigo-500',
|
||||
bgColor: 'bg-indigo-100 dark:bg-indigo-900',
|
||||
},
|
||||
// Approval Events
|
||||
[EventType.APPROVAL_REQUESTED]: {
|
||||
label: 'Approval Requested',
|
||||
icon: AlertTriangle,
|
||||
color: 'text-orange-500',
|
||||
bgColor: 'bg-orange-100 dark:bg-orange-900',
|
||||
},
|
||||
[EventType.APPROVAL_GRANTED]: {
|
||||
label: 'Approval Granted',
|
||||
icon: CheckCircle2,
|
||||
color: 'text-green-500',
|
||||
bgColor: 'bg-green-100 dark:bg-green-900',
|
||||
},
|
||||
[EventType.APPROVAL_DENIED]: {
|
||||
label: 'Approval Denied',
|
||||
icon: XCircle,
|
||||
color: 'text-red-500',
|
||||
bgColor: 'bg-red-100 dark:bg-red-900',
|
||||
},
|
||||
// Project Events
|
||||
[EventType.PROJECT_CREATED]: {
|
||||
label: 'Project Created',
|
||||
icon: Folder,
|
||||
color: 'text-teal-500',
|
||||
bgColor: 'bg-teal-100 dark:bg-teal-900',
|
||||
},
|
||||
[EventType.PROJECT_UPDATED]: {
|
||||
label: 'Project Updated',
|
||||
icon: Folder,
|
||||
color: 'text-teal-500',
|
||||
bgColor: 'bg-teal-100 dark:bg-teal-900',
|
||||
},
|
||||
[EventType.PROJECT_ARCHIVED]: {
|
||||
label: 'Project Archived',
|
||||
icon: Folder,
|
||||
color: 'text-gray-500',
|
||||
bgColor: 'bg-gray-100 dark:bg-gray-800',
|
||||
},
|
||||
// Workflow Events
|
||||
[EventType.WORKFLOW_STARTED]: {
|
||||
label: 'Workflow Started',
|
||||
icon: Workflow,
|
||||
color: 'text-cyan-500',
|
||||
bgColor: 'bg-cyan-100 dark:bg-cyan-900',
|
||||
},
|
||||
[EventType.WORKFLOW_STEP_COMPLETED]: {
|
||||
label: 'Step Completed',
|
||||
icon: Workflow,
|
||||
color: 'text-cyan-500',
|
||||
bgColor: 'bg-cyan-100 dark:bg-cyan-900',
|
||||
},
|
||||
[EventType.WORKFLOW_COMPLETED]: {
|
||||
label: 'Workflow Completed',
|
||||
icon: CheckCircle2,
|
||||
color: 'text-green-500',
|
||||
bgColor: 'bg-green-100 dark:bg-green-900',
|
||||
},
|
||||
[EventType.WORKFLOW_FAILED]: {
|
||||
label: 'Workflow Failed',
|
||||
icon: XCircle,
|
||||
color: 'text-red-500',
|
||||
bgColor: 'bg-red-100 dark:bg-red-900',
|
||||
},
|
||||
};
|
||||
|
||||
const FILTER_CATEGORIES = [
|
||||
{ id: 'agent', label: 'Agent Actions', types: [EventType.AGENT_SPAWNED, EventType.AGENT_MESSAGE, EventType.AGENT_STATUS_CHANGED, EventType.AGENT_TERMINATED] },
|
||||
{ id: 'issue', label: 'Issues', types: [EventType.ISSUE_CREATED, EventType.ISSUE_UPDATED, EventType.ISSUE_ASSIGNED, EventType.ISSUE_CLOSED] },
|
||||
{ id: 'sprint', label: 'Sprints', types: [EventType.SPRINT_STARTED, EventType.SPRINT_COMPLETED] },
|
||||
{ id: 'approval', label: 'Approvals', types: [EventType.APPROVAL_REQUESTED, EventType.APPROVAL_GRANTED, EventType.APPROVAL_DENIED] },
|
||||
{ id: 'workflow', label: 'Workflows', types: [EventType.WORKFLOW_STARTED, EventType.WORKFLOW_STEP_COMPLETED, EventType.WORKFLOW_COMPLETED, EventType.WORKFLOW_FAILED] },
|
||||
{ id: 'project', label: 'Projects', types: [EventType.PROJECT_CREATED, EventType.PROJECT_UPDATED, EventType.PROJECT_ARCHIVED] },
|
||||
];
|
||||
|
||||
// ============================================================================
|
||||
// Helper Functions
|
||||
// ============================================================================
|
||||
|
||||
function getEventConfig(event: ProjectEvent) {
|
||||
const config = EVENT_TYPE_CONFIG[event.type];
|
||||
if (config) return config;
|
||||
|
||||
// Fallback based on event category
|
||||
if (isAgentEvent(event)) {
|
||||
return { icon: Bot, label: event.type, color: 'text-blue-500', bgColor: 'bg-blue-100 dark:bg-blue-900' };
|
||||
}
|
||||
if (isIssueEvent(event)) {
|
||||
return { icon: FileText, label: event.type, color: 'text-green-500', bgColor: 'bg-green-100 dark:bg-green-900' };
|
||||
}
|
||||
if (isSprintEvent(event)) {
|
||||
return { icon: PlayCircle, label: event.type, color: 'text-indigo-500', bgColor: 'bg-indigo-100 dark:bg-indigo-900' };
|
||||
}
|
||||
if (isApprovalEvent(event)) {
|
||||
return { icon: AlertTriangle, label: event.type, color: 'text-orange-500', bgColor: 'bg-orange-100 dark:bg-orange-900' };
|
||||
}
|
||||
if (isWorkflowEvent(event)) {
|
||||
return { icon: Workflow, label: event.type, color: 'text-cyan-500', bgColor: 'bg-cyan-100 dark:bg-cyan-900' };
|
||||
}
|
||||
if (isProjectEvent(event)) {
|
||||
return { icon: Folder, label: event.type, color: 'text-teal-500', bgColor: 'bg-teal-100 dark:bg-teal-900' };
|
||||
}
|
||||
|
||||
return { icon: Activity, label: event.type, color: 'text-gray-500', bgColor: 'bg-gray-100 dark:bg-gray-800' };
|
||||
}
|
||||
|
||||
function getEventSummary(event: ProjectEvent): string {
|
||||
const payload = event.payload as Record<string, unknown>;
|
||||
|
||||
switch (event.type) {
|
||||
case EventType.AGENT_SPAWNED:
|
||||
return `${payload.agent_name || 'Agent'} spawned as ${payload.role || 'unknown role'}`;
|
||||
case EventType.AGENT_MESSAGE:
|
||||
return String(payload.message || 'No message');
|
||||
case EventType.AGENT_STATUS_CHANGED:
|
||||
return `Status: ${payload.previous_status} -> ${payload.new_status}`;
|
||||
case EventType.AGENT_TERMINATED:
|
||||
return payload.termination_reason ? String(payload.termination_reason) : 'Agent terminated';
|
||||
case EventType.ISSUE_CREATED:
|
||||
return String(payload.title || 'New issue created');
|
||||
case EventType.ISSUE_UPDATED:
|
||||
return `Issue ${payload.issue_id || ''} updated`;
|
||||
case EventType.ISSUE_ASSIGNED:
|
||||
return payload.assignee_name ? `Assigned to ${payload.assignee_name}` : 'Issue assignment changed';
|
||||
case EventType.ISSUE_CLOSED:
|
||||
return payload.resolution ? `Closed: ${payload.resolution}` : 'Issue closed';
|
||||
case EventType.SPRINT_STARTED:
|
||||
return payload.sprint_name ? `Sprint "${payload.sprint_name}" started` : 'Sprint started';
|
||||
case EventType.SPRINT_COMPLETED:
|
||||
return payload.sprint_name ? `Sprint "${payload.sprint_name}" completed` : 'Sprint completed';
|
||||
case EventType.APPROVAL_REQUESTED:
|
||||
return String(payload.description || 'Approval requested');
|
||||
case EventType.APPROVAL_GRANTED:
|
||||
return 'Approval granted';
|
||||
case EventType.APPROVAL_DENIED:
|
||||
return payload.reason ? `Denied: ${payload.reason}` : 'Approval denied';
|
||||
case EventType.WORKFLOW_STARTED:
|
||||
return payload.workflow_type ? `${payload.workflow_type} workflow started` : 'Workflow started';
|
||||
case EventType.WORKFLOW_STEP_COMPLETED:
|
||||
return `Step ${payload.step_number}/${payload.total_steps}: ${payload.step_name || 'completed'}`;
|
||||
case EventType.WORKFLOW_COMPLETED:
|
||||
return payload.duration_seconds ? `Completed in ${payload.duration_seconds}s` : 'Workflow completed';
|
||||
case EventType.WORKFLOW_FAILED:
|
||||
return payload.error_message ? String(payload.error_message) : 'Workflow failed';
|
||||
default:
|
||||
return event.type;
|
||||
}
|
||||
}
|
||||
|
||||
function groupEventsByTimePeriod(events: ProjectEvent[]): EventGroup[] {
|
||||
const groups: EventGroup[] = [
|
||||
{ label: 'Today', events: [] },
|
||||
{ label: 'Yesterday', events: [] },
|
||||
{ label: 'This Week', events: [] },
|
||||
{ label: 'Older', events: [] },
|
||||
];
|
||||
|
||||
events.forEach((event) => {
|
||||
const eventDate = new Date(event.timestamp);
|
||||
|
||||
if (isToday(eventDate)) {
|
||||
groups[0].events.push(event);
|
||||
} else if (isYesterday(eventDate)) {
|
||||
groups[1].events.push(event);
|
||||
} else if (isThisWeek(eventDate, { weekStartsOn: 1 })) {
|
||||
groups[2].events.push(event);
|
||||
} else {
|
||||
groups[3].events.push(event);
|
||||
}
|
||||
});
|
||||
|
||||
// Sort events within each group by timestamp (newest first)
|
||||
groups.forEach((group) => {
|
||||
group.events.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
||||
});
|
||||
|
||||
return groups.filter((g) => g.events.length > 0);
|
||||
}
|
||||
|
||||
function formatActorDisplay(event: ProjectEvent): string {
|
||||
if (event.actor_type === 'system') return 'System';
|
||||
if (event.actor_type === 'agent') return 'Agent';
|
||||
if (event.actor_type === 'user') return 'User';
|
||||
return event.actor_type;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Sub-Components
|
||||
// ============================================================================
|
||||
|
||||
interface ConnectionIndicatorProps {
|
||||
state: ConnectionState;
|
||||
onReconnect?: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function ConnectionIndicator({ state, onReconnect, className }: ConnectionIndicatorProps) {
|
||||
const statusConfig = {
|
||||
connected: { color: 'bg-green-500', label: 'Live', pulse: true },
|
||||
connecting: { color: 'bg-yellow-500', label: 'Connecting...', pulse: true },
|
||||
disconnected: { color: 'bg-gray-400', label: 'Disconnected', pulse: false },
|
||||
error: { color: 'bg-red-500', label: 'Error', pulse: false },
|
||||
};
|
||||
|
||||
const config = statusConfig[state];
|
||||
const canReconnect = state === 'disconnected' || state === 'error';
|
||||
|
||||
return (
|
||||
<div className={cn('flex items-center gap-2', className)} data-testid="connection-indicator">
|
||||
<span
|
||||
className={cn(
|
||||
'h-2 w-2 rounded-full',
|
||||
config.color,
|
||||
config.pulse && 'animate-pulse'
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground">{config.label}</span>
|
||||
{canReconnect && onReconnect && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onReconnect}
|
||||
className="h-6 w-6 p-0"
|
||||
aria-label="Reconnect"
|
||||
>
|
||||
<RefreshCw className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface FilterPanelProps {
|
||||
selectedCategories: string[];
|
||||
onCategoryChange: (categoryId: string) => void;
|
||||
showPendingOnly: boolean;
|
||||
onShowPendingOnlyChange: (value: boolean) => void;
|
||||
onClearFilters: () => void;
|
||||
events: ProjectEvent[];
|
||||
}
|
||||
|
||||
function FilterPanel({
|
||||
selectedCategories,
|
||||
onCategoryChange,
|
||||
showPendingOnly,
|
||||
onShowPendingOnlyChange,
|
||||
onClearFilters,
|
||||
events,
|
||||
}: FilterPanelProps) {
|
||||
const getCategoryCount = (types: EventType[]) => {
|
||||
return events.filter((e) => types.includes(e.type)).length;
|
||||
};
|
||||
|
||||
const pendingCount = events.filter((e) => e.type === EventType.APPROVAL_REQUESTED).length;
|
||||
|
||||
return (
|
||||
<Card className="p-4" data-testid="filter-panel">
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label className="text-sm font-medium">Event Types</Label>
|
||||
<div className="mt-2 grid grid-cols-2 gap-2">
|
||||
{FILTER_CATEGORIES.map((category) => {
|
||||
const count = getCategoryCount(category.types);
|
||||
return (
|
||||
<div key={category.id} className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={`filter-${category.id}`}
|
||||
checked={selectedCategories.includes(category.id)}
|
||||
onCheckedChange={() => onCategoryChange(category.id)}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`filter-${category.id}`}
|
||||
className="flex items-center gap-1 text-sm font-normal cursor-pointer"
|
||||
>
|
||||
{category.label}
|
||||
<Badge variant="secondary" className="text-xs">
|
||||
{count}
|
||||
</Badge>
|
||||
</Label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="filter-pending"
|
||||
checked={showPendingOnly}
|
||||
onCheckedChange={(checked) => onShowPendingOnlyChange(checked as boolean)}
|
||||
/>
|
||||
<Label htmlFor="filter-pending" className="flex items-center gap-1 text-sm font-normal cursor-pointer">
|
||||
Show only pending approvals
|
||||
{pendingCount > 0 && (
|
||||
<Badge variant="destructive" className="text-xs">
|
||||
{pendingCount}
|
||||
</Badge>
|
||||
)}
|
||||
</Label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="ghost" size="sm" onClick={onClearFilters}>
|
||||
Clear Filters
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
interface EventItemProps {
|
||||
event: ProjectEvent;
|
||||
expanded: boolean;
|
||||
onToggle: () => void;
|
||||
onApprove?: (event: ProjectEvent) => void;
|
||||
onReject?: (event: ProjectEvent) => void;
|
||||
onClick?: (event: ProjectEvent) => void;
|
||||
compact?: boolean;
|
||||
}
|
||||
|
||||
function EventItem({
|
||||
event,
|
||||
expanded,
|
||||
onToggle,
|
||||
onApprove,
|
||||
onReject,
|
||||
onClick,
|
||||
compact = false,
|
||||
}: EventItemProps) {
|
||||
const config = getEventConfig(event);
|
||||
const Icon = config.icon;
|
||||
const summary = getEventSummary(event);
|
||||
const actor = formatActorDisplay(event);
|
||||
const timestamp = formatDistanceToNow(new Date(event.timestamp), { addSuffix: true });
|
||||
const isPendingApproval = event.type === EventType.APPROVAL_REQUESTED;
|
||||
const payload = event.payload as Record<string, unknown>;
|
||||
|
||||
const handleClick = () => {
|
||||
onClick?.(event);
|
||||
onToggle();
|
||||
};
|
||||
|
||||
const handleApprove = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
onApprove?.(event);
|
||||
};
|
||||
|
||||
const handleReject = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
onReject?.(event);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'border-b border-border/50 last:border-b-0 transition-colors',
|
||||
'cursor-pointer hover:bg-muted/50',
|
||||
isPendingApproval && 'border-l-4 border-l-orange-500',
|
||||
compact ? 'p-2' : 'p-4'
|
||||
)}
|
||||
onClick={handleClick}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
handleClick();
|
||||
}
|
||||
}}
|
||||
data-testid={`event-item-${event.id}`}
|
||||
>
|
||||
<div className="flex gap-3">
|
||||
{/* Icon */}
|
||||
<div
|
||||
className={cn(
|
||||
'flex shrink-0 items-center justify-center rounded-full',
|
||||
config.bgColor,
|
||||
compact ? 'h-8 w-8' : 'h-10 w-10'
|
||||
)}
|
||||
>
|
||||
<Icon className={cn(config.color, compact ? 'h-4 w-4' : 'h-5 w-5')} aria-hidden="true" />
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{config.label}
|
||||
</Badge>
|
||||
<span className="text-xs text-muted-foreground">{actor}</span>
|
||||
{isPendingApproval && (
|
||||
<Badge variant="destructive" className="text-xs">
|
||||
Action Required
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className={cn('mt-1 text-sm', compact && 'truncate')}>{summary}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">{timestamp}</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 w-6 p-0"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onToggle();
|
||||
}}
|
||||
aria-label={expanded ? 'Collapse details' : 'Expand details'}
|
||||
>
|
||||
{expanded ? <ChevronDown className="h-4 w-4" /> : <ChevronRight className="h-4 w-4" />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Expanded Details */}
|
||||
{expanded && (() => {
|
||||
const issueId = payload.issue_id as string | undefined;
|
||||
const pullRequest = payload.pullRequest as string | number | undefined;
|
||||
const documentUrl = payload.documentUrl as string | undefined;
|
||||
const progress = payload.progress as number | undefined;
|
||||
|
||||
return (
|
||||
<div className="mt-3 rounded-md bg-muted/50 p-3 space-y-3" data-testid="event-details">
|
||||
{/* Issue/PR Links */}
|
||||
{issueId && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<CircleDot className="h-4 w-4" aria-hidden="true" />
|
||||
<span>Issue #{issueId}</span>
|
||||
</div>
|
||||
)}
|
||||
{pullRequest && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<GitPullRequest className="h-4 w-4" aria-hidden="true" />
|
||||
<span>PR #{String(pullRequest)}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Document Links */}
|
||||
{documentUrl && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<ExternalLink className="h-4 w-4" aria-hidden="true" />
|
||||
<a href={documentUrl} className="text-primary hover:underline">
|
||||
{documentUrl}
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Progress */}
|
||||
{progress !== undefined && (
|
||||
<div className="space-y-1">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span>Progress</span>
|
||||
<span>{progress}%</span>
|
||||
</div>
|
||||
<div className="h-2 rounded-full bg-muted">
|
||||
<div
|
||||
className="h-full rounded-full bg-primary"
|
||||
style={{ width: `${progress}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Timestamp */}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{new Date(event.timestamp).toLocaleString()}
|
||||
</p>
|
||||
|
||||
{/* Raw Payload (for debugging) */}
|
||||
<details className="text-xs">
|
||||
<summary className="cursor-pointer text-muted-foreground hover:text-foreground">
|
||||
View raw payload
|
||||
</summary>
|
||||
<pre className="mt-2 overflow-x-auto whitespace-pre-wrap break-words rounded bg-muted p-2">
|
||||
{JSON.stringify(event.payload, null, 2)}
|
||||
</pre>
|
||||
</details>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
|
||||
{/* Approval Actions */}
|
||||
{isPendingApproval && (onApprove || onReject) && (
|
||||
<div className="mt-3 flex gap-2">
|
||||
{onApprove && (
|
||||
<Button size="sm" onClick={handleApprove} data-testid="approve-button">
|
||||
<CheckCircle2 className="mr-2 h-4 w-4" />
|
||||
Approve
|
||||
</Button>
|
||||
)}
|
||||
{onReject && (
|
||||
<Button variant="outline" size="sm" onClick={handleReject} data-testid="reject-button">
|
||||
<XCircle className="mr-2 h-4 w-4" />
|
||||
Reject
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LoadingSkeleton() {
|
||||
return (
|
||||
<div className="space-y-4" data-testid="loading-skeleton">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<div key={i} className="flex gap-3 p-4">
|
||||
<Skeleton className="h-10 w-10 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EmptyState({ hasFilters }: { hasFilters: boolean }) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-12 text-muted-foreground" data-testid="empty-state">
|
||||
<Activity className="h-12 w-12 mb-4" aria-hidden="true" />
|
||||
<h3 className="font-semibold">No activity found</h3>
|
||||
<p className="text-sm">
|
||||
{hasFilters
|
||||
? 'Try adjusting your search or filters'
|
||||
: 'Activity will appear here as agents work on your projects'}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main Component
|
||||
// ============================================================================
|
||||
|
||||
export function ActivityFeed({
|
||||
events,
|
||||
connectionState,
|
||||
isLoading = false,
|
||||
onReconnect,
|
||||
onApprove,
|
||||
onReject,
|
||||
onEventClick,
|
||||
maxHeight = 'auto',
|
||||
showHeader = true,
|
||||
title = 'Activity Feed',
|
||||
enableFiltering = true,
|
||||
enableSearch = true,
|
||||
compact = false,
|
||||
className,
|
||||
}: ActivityFeedProps) {
|
||||
// State
|
||||
const [expandedEvents, setExpandedEvents] = useState<Set<string>>(new Set());
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [showFilters, setShowFilters] = useState(false);
|
||||
const [selectedCategories, setSelectedCategories] = useState<string[]>([]);
|
||||
const [showPendingOnly, setShowPendingOnly] = useState(false);
|
||||
|
||||
// Filter logic
|
||||
const filteredEvents = useMemo(() => {
|
||||
let result = events;
|
||||
|
||||
// Search filter
|
||||
if (searchQuery) {
|
||||
const query = searchQuery.toLowerCase();
|
||||
result = result.filter((event) => {
|
||||
const summary = getEventSummary(event).toLowerCase();
|
||||
return summary.includes(query) || event.type.toLowerCase().includes(query);
|
||||
});
|
||||
}
|
||||
|
||||
// Category filter
|
||||
if (selectedCategories.length > 0) {
|
||||
const allowedTypes = new Set<EventType>();
|
||||
selectedCategories.forEach((categoryId) => {
|
||||
const category = FILTER_CATEGORIES.find((c) => c.id === categoryId);
|
||||
if (category) {
|
||||
category.types.forEach((type) => allowedTypes.add(type));
|
||||
}
|
||||
});
|
||||
result = result.filter((event) => allowedTypes.has(event.type));
|
||||
}
|
||||
|
||||
// Pending only filter
|
||||
if (showPendingOnly) {
|
||||
result = result.filter((event) => event.type === EventType.APPROVAL_REQUESTED);
|
||||
}
|
||||
|
||||
return result;
|
||||
}, [events, searchQuery, selectedCategories, showPendingOnly]);
|
||||
|
||||
// Group events by time
|
||||
const groupedEvents = useMemo(() => groupEventsByTimePeriod(filteredEvents), [filteredEvents]);
|
||||
|
||||
// Event handlers
|
||||
const toggleExpanded = useCallback((eventId: string) => {
|
||||
setExpandedEvents((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(eventId)) {
|
||||
next.delete(eventId);
|
||||
} else {
|
||||
next.add(eventId);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleCategoryChange = useCallback((categoryId: string) => {
|
||||
setSelectedCategories((prev) =>
|
||||
prev.includes(categoryId) ? prev.filter((c) => c !== categoryId) : [...prev, categoryId]
|
||||
);
|
||||
}, []);
|
||||
|
||||
const handleClearFilters = useCallback(() => {
|
||||
setSelectedCategories([]);
|
||||
setShowPendingOnly(false);
|
||||
setSearchQuery('');
|
||||
}, []);
|
||||
|
||||
const hasFilters = searchQuery !== '' || selectedCategories.length > 0 || showPendingOnly;
|
||||
const pendingCount = events.filter((e) => e.type === EventType.APPROVAL_REQUESTED).length;
|
||||
|
||||
return (
|
||||
<Card className={className} data-testid="activity-feed">
|
||||
{showHeader && (
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="text-lg">{title}</CardTitle>
|
||||
<div className="flex items-center gap-3">
|
||||
<ConnectionIndicator state={connectionState} onReconnect={onReconnect} />
|
||||
{pendingCount > 0 && (
|
||||
<Badge variant="destructive" className="gap-1">
|
||||
<AlertTriangle className="h-3 w-3" />
|
||||
{pendingCount} pending
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
)}
|
||||
|
||||
<CardContent className={showHeader ? 'pt-0' : ''}>
|
||||
<div className="space-y-4">
|
||||
{/* Search and Filter Controls */}
|
||||
{(enableSearch || enableFiltering) && (
|
||||
<div className="flex flex-col gap-4 sm:flex-row">
|
||||
{enableSearch && (
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search activity..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-9"
|
||||
data-testid="search-input"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{enableFiltering && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setShowFilters(!showFilters)}
|
||||
className={showFilters ? 'bg-muted' : ''}
|
||||
data-testid="filter-toggle"
|
||||
>
|
||||
<Filter className="mr-2 h-4 w-4" />
|
||||
Filters
|
||||
{hasFilters && (
|
||||
<Badge variant="secondary" className="ml-2">
|
||||
Active
|
||||
</Badge>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Filter Panel */}
|
||||
{showFilters && enableFiltering && (
|
||||
<FilterPanel
|
||||
selectedCategories={selectedCategories}
|
||||
onCategoryChange={handleCategoryChange}
|
||||
showPendingOnly={showPendingOnly}
|
||||
onShowPendingOnlyChange={setShowPendingOnly}
|
||||
onClearFilters={handleClearFilters}
|
||||
events={events}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Event List */}
|
||||
<div
|
||||
className="overflow-y-auto"
|
||||
style={{ maxHeight: typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight }}
|
||||
>
|
||||
{isLoading ? (
|
||||
<LoadingSkeleton />
|
||||
) : filteredEvents.length === 0 ? (
|
||||
<EmptyState hasFilters={hasFilters} />
|
||||
) : (
|
||||
<div className="space-y-6">
|
||||
{groupedEvents.map((group) => (
|
||||
<div key={group.label} data-testid={`event-group-${group.label.toLowerCase().replace(' ', '-')}`}>
|
||||
<div className="mb-3 flex items-center gap-2">
|
||||
<h3 className="text-sm font-medium text-muted-foreground">{group.label}</h3>
|
||||
<Badge variant="secondary" className="text-xs">
|
||||
{group.events.length}
|
||||
</Badge>
|
||||
<Separator className="flex-1" />
|
||||
</div>
|
||||
<div className="rounded-lg border divide-y divide-border/50">
|
||||
{group.events.map((event) => (
|
||||
<EventItem
|
||||
key={event.id}
|
||||
event={event}
|
||||
expanded={expandedEvents.has(event.id)}
|
||||
onToggle={() => toggleExpanded(event.id)}
|
||||
onApprove={onApprove}
|
||||
onReject={onReject}
|
||||
onClick={onEventClick}
|
||||
compact={compact}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
9
frontend/src/components/activity/index.ts
Normal file
9
frontend/src/components/activity/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Activity Components
|
||||
*
|
||||
* Shared components for displaying real-time activity feeds across
|
||||
* dashboards and dedicated activity pages.
|
||||
*/
|
||||
|
||||
export { ActivityFeed } from './ActivityFeed';
|
||||
export type { ActivityFeedProps, EventTypeFilter } from './ActivityFeed';
|
||||
416
frontend/src/components/agents/AgentTypeDetail.tsx
Normal file
416
frontend/src/components/agents/AgentTypeDetail.tsx
Normal file
@@ -0,0 +1,416 @@
|
||||
/**
|
||||
* AgentTypeDetail Component
|
||||
*
|
||||
* Displays detailed information about a single agent type.
|
||||
* Shows model configuration, permissions, personality, and instance stats.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import {
|
||||
Bot,
|
||||
ArrowLeft,
|
||||
Copy,
|
||||
Edit,
|
||||
Trash2,
|
||||
FileText,
|
||||
Zap,
|
||||
MessageSquare,
|
||||
Shield,
|
||||
Cpu,
|
||||
CheckCircle2,
|
||||
AlertTriangle,
|
||||
} from 'lucide-react';
|
||||
import type { AgentTypeResponse } from '@/lib/api/types/agentTypes';
|
||||
import { AVAILABLE_MCP_SERVERS } from '@/lib/validations/agentType';
|
||||
|
||||
interface AgentTypeDetailProps {
|
||||
agentType: AgentTypeResponse | null;
|
||||
isLoading?: boolean;
|
||||
onBack: () => void;
|
||||
onEdit: () => void;
|
||||
onDuplicate: () => void;
|
||||
onDeactivate: () => void;
|
||||
isDeactivating?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status badge component for agent types
|
||||
*/
|
||||
function AgentTypeStatusBadge({ isActive }: { isActive: boolean }) {
|
||||
if (isActive) {
|
||||
return (
|
||||
<Badge className="bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200" variant="outline">
|
||||
Active
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Badge className="bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200" variant="outline">
|
||||
Inactive
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loading skeleton for agent type detail
|
||||
*/
|
||||
function AgentTypeDetailSkeleton() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center gap-4">
|
||||
<Skeleton className="h-10 w-10" />
|
||||
<div className="flex-1">
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<Skeleton className="mt-2 h-4 w-48" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-6 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Skeleton className="h-20 w-full" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-6 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Skeleton className="h-40 w-full" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get model display name
|
||||
*/
|
||||
function getModelDisplayName(modelId: string): string {
|
||||
const modelNames: Record<string, string> = {
|
||||
'claude-opus-4-5-20251101': 'Claude Opus 4.5',
|
||||
'claude-sonnet-4-20250514': 'Claude Sonnet 4',
|
||||
'claude-3-5-sonnet-20241022': 'Claude 3.5 Sonnet',
|
||||
};
|
||||
return modelNames[modelId] || modelId;
|
||||
}
|
||||
|
||||
export function AgentTypeDetail({
|
||||
agentType,
|
||||
isLoading = false,
|
||||
onBack,
|
||||
onEdit,
|
||||
onDuplicate,
|
||||
onDeactivate,
|
||||
isDeactivating = false,
|
||||
className,
|
||||
}: AgentTypeDetailProps) {
|
||||
if (isLoading) {
|
||||
return <AgentTypeDetailSkeleton />;
|
||||
}
|
||||
|
||||
if (!agentType) {
|
||||
return (
|
||||
<div className="py-12 text-center">
|
||||
<AlertTriangle className="mx-auto h-12 w-12 text-muted-foreground" />
|
||||
<h3 className="mt-4 font-semibold">Agent type not found</h3>
|
||||
<p className="text-muted-foreground">
|
||||
The requested agent type could not be found
|
||||
</p>
|
||||
<Button onClick={onBack} variant="outline" className="mt-4">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Go Back
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const modelParams = agentType.model_params as {
|
||||
temperature?: number;
|
||||
max_tokens?: number;
|
||||
top_p?: number;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{/* Header */}
|
||||
<div className="mb-6 flex items-center gap-4">
|
||||
<Button variant="ghost" size="icon" onClick={onBack}>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
<span className="sr-only">Go back</span>
|
||||
</Button>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-3">
|
||||
<h1 className="text-3xl font-bold">{agentType.name}</h1>
|
||||
<AgentTypeStatusBadge isActive={agentType.is_active} />
|
||||
</div>
|
||||
<p className="text-muted-foreground">
|
||||
Last modified:{' '}
|
||||
{new Date(agentType.updated_at).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" size="sm" onClick={onDuplicate}>
|
||||
<Copy className="mr-2 h-4 w-4" />
|
||||
Duplicate
|
||||
</Button>
|
||||
<Button size="sm" onClick={onEdit}>
|
||||
<Edit className="mr-2 h-4 w-4" />
|
||||
Edit
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
{/* Main Content */}
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
{/* Description Card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<FileText className="h-5 w-5" />
|
||||
Description
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-muted-foreground">
|
||||
{agentType.description || 'No description provided'}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Expertise Card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Zap className="h-5 w-5" />
|
||||
Expertise Areas
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{agentType.expertise.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{agentType.expertise.map((skill) => (
|
||||
<Badge key={skill} variant="secondary">
|
||||
{skill}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-muted-foreground">No expertise areas defined</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Personality Prompt Card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<MessageSquare className="h-5 w-5" />
|
||||
Personality Prompt
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<pre className="whitespace-pre-wrap rounded-lg bg-muted p-4 text-sm">
|
||||
{agentType.personality_prompt}
|
||||
</pre>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* MCP Permissions Card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Shield className="h-5 w-5" />
|
||||
MCP Permissions
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Model Context Protocol servers this agent can access
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{AVAILABLE_MCP_SERVERS.map((server) => {
|
||||
const isEnabled = agentType.mcp_servers.includes(server.id);
|
||||
return (
|
||||
<div
|
||||
key={server.id}
|
||||
className={`flex items-center justify-between rounded-lg border p-3 ${
|
||||
isEnabled
|
||||
? 'border-primary/20 bg-primary/5'
|
||||
: 'border-muted bg-muted/50'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
className={`flex h-8 w-8 items-center justify-center rounded-full ${
|
||||
isEnabled ? 'bg-primary/10' : 'bg-muted'
|
||||
}`}
|
||||
>
|
||||
{isEnabled ? (
|
||||
<CheckCircle2 className="h-4 w-4 text-primary" />
|
||||
) : (
|
||||
<AlertTriangle className="h-4 w-4 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium">{server.name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{server.description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Badge variant={isEnabled ? 'default' : 'secondary'}>
|
||||
{isEnabled ? 'Enabled' : 'Disabled'}
|
||||
</Badge>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Sidebar */}
|
||||
<div className="space-y-6">
|
||||
{/* Model Configuration */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-lg">
|
||||
<Cpu className="h-5 w-5" />
|
||||
Model Configuration
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Primary Model</p>
|
||||
<p className="font-medium">
|
||||
{getModelDisplayName(agentType.primary_model)}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Failover Model</p>
|
||||
<p className="font-medium">
|
||||
{agentType.fallback_models.length > 0
|
||||
? getModelDisplayName(agentType.fallback_models[0])
|
||||
: 'None configured'}
|
||||
</p>
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">Temperature</span>
|
||||
<span className="font-medium">{modelParams.temperature ?? 0.7}</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">Max Tokens</span>
|
||||
<span className="font-medium">
|
||||
{(modelParams.max_tokens ?? 8192).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">Top P</span>
|
||||
<span className="font-medium">{modelParams.top_p ?? 0.95}</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Instance Stats */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-lg">
|
||||
<Bot className="h-5 w-5" />
|
||||
Instances
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-center">
|
||||
<p className="text-4xl font-bold text-primary">
|
||||
{agentType.instance_count}
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">Active instances</p>
|
||||
</div>
|
||||
<Button variant="outline" className="mt-4 w-full" size="sm" disabled>
|
||||
View Instances
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Danger Zone */}
|
||||
<Card className="border-destructive/50">
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-lg text-destructive">
|
||||
<AlertTriangle className="h-5 w-5" />
|
||||
Danger Zone
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button
|
||||
variant="destructive"
|
||||
className="w-full"
|
||||
size="sm"
|
||||
disabled={isDeactivating}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
{agentType.is_active ? 'Deactivate Type' : 'Delete Type'}
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{agentType.is_active
|
||||
? `This will deactivate the "${agentType.name}" agent type. Existing instances will continue to work, but no new instances can be created from this type.`
|
||||
: `This will permanently delete the "${agentType.name}" agent type. This action cannot be undone.`}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={onDeactivate}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{agentType.is_active ? 'Deactivate' : 'Delete'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
554
frontend/src/components/agents/AgentTypeForm.tsx
Normal file
554
frontend/src/components/agents/AgentTypeForm.tsx
Normal file
@@ -0,0 +1,554 @@
|
||||
/**
|
||||
* AgentTypeForm Component
|
||||
*
|
||||
* React Hook Form-based form for creating and editing agent types.
|
||||
* Features tabbed interface for organizing form sections.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useForm, Controller } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import {
|
||||
FileText,
|
||||
Cpu,
|
||||
Shield,
|
||||
MessageSquare,
|
||||
Sliders,
|
||||
Save,
|
||||
ArrowLeft,
|
||||
X,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
agentTypeCreateSchema,
|
||||
type AgentTypeCreateFormValues,
|
||||
AVAILABLE_MODELS,
|
||||
AVAILABLE_MCP_SERVERS,
|
||||
defaultAgentTypeValues,
|
||||
generateSlug,
|
||||
} from '@/lib/validations/agentType';
|
||||
import type { AgentTypeResponse } from '@/lib/api/types/agentTypes';
|
||||
|
||||
interface AgentTypeFormProps {
|
||||
agentType?: AgentTypeResponse;
|
||||
onSubmit: (data: AgentTypeCreateFormValues) => void;
|
||||
onCancel: () => void;
|
||||
isSubmitting?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function AgentTypeForm({
|
||||
agentType,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
isSubmitting = false,
|
||||
className,
|
||||
}: AgentTypeFormProps) {
|
||||
const isEditing = !!agentType;
|
||||
const [activeTab, setActiveTab] = useState('basic');
|
||||
const [expertiseInput, setExpertiseInput] = useState('');
|
||||
|
||||
// Always use create schema for validation - editing requires all fields too
|
||||
const form = useForm<AgentTypeCreateFormValues>({
|
||||
resolver: zodResolver(agentTypeCreateSchema),
|
||||
defaultValues: agentType
|
||||
? {
|
||||
name: agentType.name,
|
||||
slug: agentType.slug,
|
||||
description: agentType.description,
|
||||
expertise: agentType.expertise,
|
||||
personality_prompt: agentType.personality_prompt,
|
||||
primary_model: agentType.primary_model,
|
||||
fallback_models: agentType.fallback_models,
|
||||
model_params: (agentType.model_params ?? {
|
||||
temperature: 0.7,
|
||||
max_tokens: 8192,
|
||||
top_p: 0.95,
|
||||
}) as AgentTypeCreateFormValues['model_params'],
|
||||
mcp_servers: agentType.mcp_servers,
|
||||
tool_permissions: agentType.tool_permissions,
|
||||
is_active: agentType.is_active,
|
||||
}
|
||||
: defaultAgentTypeValues,
|
||||
});
|
||||
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
handleSubmit,
|
||||
watch,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = form;
|
||||
|
||||
const watchName = watch('name');
|
||||
const watchExpertise = watch('expertise') || [];
|
||||
const watchMcpServers = watch('mcp_servers') || [];
|
||||
|
||||
// Auto-generate slug from name for new agent types
|
||||
useEffect(() => {
|
||||
if (!isEditing && watchName) {
|
||||
const slug = generateSlug(watchName);
|
||||
setValue('slug', slug, { shouldValidate: true });
|
||||
}
|
||||
}, [watchName, isEditing, setValue]);
|
||||
|
||||
const handleAddExpertise = () => {
|
||||
if (expertiseInput.trim()) {
|
||||
const newExpertise = expertiseInput.trim().toLowerCase();
|
||||
if (!watchExpertise.includes(newExpertise)) {
|
||||
setValue('expertise', [...watchExpertise, newExpertise]);
|
||||
}
|
||||
setExpertiseInput('');
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveExpertise = (skill: string) => {
|
||||
setValue(
|
||||
'expertise',
|
||||
watchExpertise.filter((e) => e !== skill)
|
||||
);
|
||||
};
|
||||
|
||||
const handleMcpServerToggle = (serverId: string, checked: boolean) => {
|
||||
if (checked) {
|
||||
setValue('mcp_servers', [...watchMcpServers, serverId]);
|
||||
} else {
|
||||
setValue(
|
||||
'mcp_servers',
|
||||
watchMcpServers.filter((s) => s !== serverId)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)} className={className}>
|
||||
{/* Header */}
|
||||
<div className="mb-6 flex items-center gap-4">
|
||||
<Button type="button" variant="ghost" size="icon" onClick={onCancel}>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
<span className="sr-only">Go back</span>
|
||||
</Button>
|
||||
<div className="flex-1">
|
||||
<h1 className="text-3xl font-bold">
|
||||
{isEditing ? 'Edit Agent Type' : 'Create Agent Type'}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{isEditing
|
||||
? 'Modify agent type configuration'
|
||||
: 'Define a new agent type template'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" variant="outline" onClick={onCancel} disabled={isSubmitting}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isSubmitting}>
|
||||
<Save className="mr-2 h-4 w-4" />
|
||||
{isSubmitting ? 'Saving...' : isEditing ? 'Save Changes' : 'Create'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tabbed Form */}
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
||||
<TabsList className="grid w-full grid-cols-4">
|
||||
<TabsTrigger value="basic">
|
||||
<FileText className="mr-2 h-4 w-4" />
|
||||
Basic Info
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="model">
|
||||
<Cpu className="mr-2 h-4 w-4" />
|
||||
Model
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="permissions">
|
||||
<Shield className="mr-2 h-4 w-4" />
|
||||
Permissions
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="personality">
|
||||
<MessageSquare className="mr-2 h-4 w-4" />
|
||||
Personality
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
{/* Basic Info Tab */}
|
||||
<TabsContent value="basic" className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Basic Information</CardTitle>
|
||||
<CardDescription>
|
||||
Define the agent type name, description, and expertise areas
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">
|
||||
Name <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="name"
|
||||
placeholder="e.g., Software Architect"
|
||||
{...register('name')}
|
||||
aria-invalid={!!errors.name}
|
||||
aria-describedby={errors.name ? 'name-error' : undefined}
|
||||
/>
|
||||
{errors.name && (
|
||||
<p id="name-error" className="text-sm text-destructive" role="alert">
|
||||
{errors.name.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="slug">
|
||||
Slug <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="slug"
|
||||
placeholder="e.g., software-architect"
|
||||
{...register('slug')}
|
||||
aria-invalid={!!errors.slug}
|
||||
aria-describedby={errors.slug ? 'slug-error' : undefined}
|
||||
/>
|
||||
{errors.slug && (
|
||||
<p id="slug-error" className="text-sm text-destructive" role="alert">
|
||||
{errors.slug.message}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
URL-friendly identifier (auto-generated from name)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="status">Status</Label>
|
||||
<Controller
|
||||
name="is_active"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Select
|
||||
value={field.value ? 'active' : 'inactive'}
|
||||
onValueChange={(val) => field.onChange(val === 'active')}
|
||||
>
|
||||
<SelectTrigger id="status">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="active">Active</SelectItem>
|
||||
<SelectItem value="inactive">Inactive / Draft</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="description">Description</Label>
|
||||
<Textarea
|
||||
id="description"
|
||||
placeholder="Describe what this agent type does..."
|
||||
rows={3}
|
||||
{...register('description')}
|
||||
aria-invalid={!!errors.description}
|
||||
aria-describedby={errors.description ? 'description-error' : undefined}
|
||||
/>
|
||||
{errors.description && (
|
||||
<p id="description-error" className="text-sm text-destructive" role="alert">
|
||||
{errors.description.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Expertise Areas</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Add skills and areas of expertise
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
placeholder="e.g., System Design"
|
||||
value={expertiseInput}
|
||||
onChange={(e) => setExpertiseInput(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
handleAddExpertise();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button type="button" variant="outline" onClick={handleAddExpertise}>
|
||||
Add
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 pt-2">
|
||||
{watchExpertise.map((skill) => (
|
||||
<Badge key={skill} variant="secondary" className="gap-1">
|
||||
{skill}
|
||||
<button
|
||||
type="button"
|
||||
className="ml-1 rounded-full hover:bg-muted"
|
||||
onClick={() => handleRemoveExpertise(skill)}
|
||||
aria-label={`Remove ${skill}`}
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
|
||||
{/* Model Configuration Tab */}
|
||||
<TabsContent value="model" className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Model Selection</CardTitle>
|
||||
<CardDescription>
|
||||
Choose the AI models that power this agent type
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="primary_model">
|
||||
Primary Model <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Controller
|
||||
name="primary_model"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Select value={field.value} onValueChange={field.onChange}>
|
||||
<SelectTrigger id="primary_model">
|
||||
<SelectValue placeholder="Select model" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{AVAILABLE_MODELS.map((model) => (
|
||||
<SelectItem key={model.value} value={model.value}>
|
||||
{model.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
{errors.primary_model && (
|
||||
<p className="text-sm text-destructive" role="alert">
|
||||
{errors.primary_model.message}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Main model used for this agent
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="fallback_model">Fallover Model</Label>
|
||||
<Controller
|
||||
name="fallback_models"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Select
|
||||
value={field.value?.[0] || ''}
|
||||
onValueChange={(val) => field.onChange([val])}
|
||||
>
|
||||
<SelectTrigger id="fallback_model">
|
||||
<SelectValue placeholder="Select model" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{AVAILABLE_MODELS.map((model) => (
|
||||
<SelectItem key={model.value} value={model.value}>
|
||||
{model.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Backup model if primary is unavailable
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Sliders className="h-5 w-5" />
|
||||
Model Parameters
|
||||
</CardTitle>
|
||||
<CardDescription>Fine-tune the model behavior</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid gap-6 md:grid-cols-3">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="temperature">Temperature</Label>
|
||||
<Controller
|
||||
name="model_params.temperature"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Input
|
||||
id="temperature"
|
||||
type="number"
|
||||
step="0.1"
|
||||
min="0"
|
||||
max="2"
|
||||
value={field.value ?? 0.7}
|
||||
onChange={(e) => field.onChange(parseFloat(e.target.value))}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
0 = deterministic, 2 = creative
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="max_tokens">Max Tokens</Label>
|
||||
<Controller
|
||||
name="model_params.max_tokens"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Input
|
||||
id="max_tokens"
|
||||
type="number"
|
||||
step="1024"
|
||||
min="1024"
|
||||
max="128000"
|
||||
value={field.value ?? 8192}
|
||||
onChange={(e) => field.onChange(parseInt(e.target.value, 10))}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">Maximum response length</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="top_p">Top P</Label>
|
||||
<Controller
|
||||
name="model_params.top_p"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Input
|
||||
id="top_p"
|
||||
type="number"
|
||||
step="0.05"
|
||||
min="0"
|
||||
max="1"
|
||||
value={field.value ?? 0.95}
|
||||
onChange={(e) => field.onChange(parseFloat(e.target.value))}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">Nucleus sampling threshold</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
|
||||
{/* MCP Permissions Tab */}
|
||||
<TabsContent value="permissions" className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>MCP Server Permissions</CardTitle>
|
||||
<CardDescription>
|
||||
Configure which MCP servers this agent can access
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{AVAILABLE_MCP_SERVERS.map((server) => (
|
||||
<div key={server.id} className="rounded-lg border p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<Checkbox
|
||||
id={`mcp-${server.id}`}
|
||||
checked={watchMcpServers.includes(server.id)}
|
||||
onCheckedChange={(checked) =>
|
||||
handleMcpServerToggle(server.id, checked === true)
|
||||
}
|
||||
/>
|
||||
<div>
|
||||
<Label htmlFor={`mcp-${server.id}`} className="font-medium">
|
||||
{server.name}
|
||||
</Label>
|
||||
<p className="text-sm text-muted-foreground">{server.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
|
||||
{/* Personality Prompt Tab */}
|
||||
<TabsContent value="personality" className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Personality Prompt</CardTitle>
|
||||
<CardDescription>
|
||||
Define the agent's personality, behavior, and communication style. This
|
||||
prompt shapes how the agent approaches tasks and interacts.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<Textarea
|
||||
id="personality_prompt"
|
||||
placeholder="You are a..."
|
||||
rows={15}
|
||||
className="font-mono text-sm"
|
||||
{...register('personality_prompt')}
|
||||
aria-invalid={!!errors.personality_prompt}
|
||||
aria-describedby={
|
||||
errors.personality_prompt ? 'personality_prompt-error' : undefined
|
||||
}
|
||||
/>
|
||||
{errors.personality_prompt && (
|
||||
<p
|
||||
id="personality_prompt-error"
|
||||
className="text-sm text-destructive"
|
||||
role="alert"
|
||||
>
|
||||
{errors.personality_prompt.message}
|
||||
</p>
|
||||
)}
|
||||
<div className="flex items-center gap-4 text-sm text-muted-foreground">
|
||||
<span>
|
||||
Character count: {watch('personality_prompt')?.length || 0}
|
||||
</span>
|
||||
<Separator orientation="vertical" className="h-4" />
|
||||
<span className="text-xs">
|
||||
Tip: Be specific about expertise, communication style, and decision-making
|
||||
approach
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
248
frontend/src/components/agents/AgentTypeList.tsx
Normal file
248
frontend/src/components/agents/AgentTypeList.tsx
Normal file
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* AgentTypeList Component
|
||||
*
|
||||
* Displays a grid of agent type cards with search and filter functionality.
|
||||
* Used on the main agent types page for browsing and selecting agent types.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Bot, Plus, Search, Cpu } from 'lucide-react';
|
||||
import type { AgentTypeResponse } from '@/lib/api/types/agentTypes';
|
||||
|
||||
interface AgentTypeListProps {
|
||||
agentTypes: AgentTypeResponse[];
|
||||
isLoading?: boolean;
|
||||
searchQuery: string;
|
||||
onSearchChange: (query: string) => void;
|
||||
statusFilter: string;
|
||||
onStatusFilterChange: (status: string) => void;
|
||||
onSelect: (id: string) => void;
|
||||
onCreate: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status badge component for agent types
|
||||
*/
|
||||
function AgentTypeStatusBadge({ isActive }: { isActive: boolean }) {
|
||||
if (isActive) {
|
||||
return (
|
||||
<Badge className="bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200" variant="outline">
|
||||
Active
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Badge className="bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200" variant="outline">
|
||||
Inactive
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loading skeleton for agent type cards
|
||||
*/
|
||||
function AgentTypeCardSkeleton() {
|
||||
return (
|
||||
<Card className="h-[200px]">
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<Skeleton className="h-10 w-10 rounded-lg" />
|
||||
<Skeleton className="h-5 w-16" />
|
||||
</div>
|
||||
<Skeleton className="mt-3 h-6 w-3/4" />
|
||||
<Skeleton className="mt-2 h-4 w-full" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<Skeleton className="h-5 w-16" />
|
||||
<Skeleton className="h-5 w-20" />
|
||||
<Skeleton className="h-5 w-14" />
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="flex items-center justify-between">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-4 w-20" />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract model display name from model ID
|
||||
*/
|
||||
function getModelDisplayName(modelId: string): string {
|
||||
const parts = modelId.split('-');
|
||||
if (parts.length >= 2) {
|
||||
return parts.slice(0, 2).join(' ').replace('claude', 'Claude');
|
||||
}
|
||||
return modelId;
|
||||
}
|
||||
|
||||
export function AgentTypeList({
|
||||
agentTypes,
|
||||
isLoading = false,
|
||||
searchQuery,
|
||||
onSearchChange,
|
||||
statusFilter,
|
||||
onStatusFilterChange,
|
||||
onSelect,
|
||||
onCreate,
|
||||
className,
|
||||
}: AgentTypeListProps) {
|
||||
return (
|
||||
<div className={className}>
|
||||
{/* Header */}
|
||||
<div className="mb-6 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold">Agent Types</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Configure templates for spawning AI agent instances
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={onCreate}>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Agent Type
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Filters */}
|
||||
<div className="mb-6 flex flex-col gap-4 sm:flex-row">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search agent types..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
className="pl-9"
|
||||
aria-label="Search agent types"
|
||||
/>
|
||||
</div>
|
||||
<Select value={statusFilter} onValueChange={onStatusFilterChange}>
|
||||
<SelectTrigger className="w-full sm:w-40" aria-label="Filter by status">
|
||||
<SelectValue placeholder="Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Status</SelectItem>
|
||||
<SelectItem value="active">Active</SelectItem>
|
||||
<SelectItem value="inactive">Inactive</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Loading State */}
|
||||
{isLoading && (
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{[1, 2, 3, 4, 5, 6].map((i) => (
|
||||
<AgentTypeCardSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Agent Type Grid */}
|
||||
{!isLoading && agentTypes.length > 0 && (
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{agentTypes.map((type) => (
|
||||
<Card
|
||||
key={type.id}
|
||||
className="cursor-pointer transition-all hover:border-primary hover:shadow-md"
|
||||
onClick={() => onSelect(type.id)}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
onSelect(type.id);
|
||||
}
|
||||
}}
|
||||
aria-label={`View ${type.name} agent type`}
|
||||
>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10">
|
||||
<Bot className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
<AgentTypeStatusBadge isActive={type.is_active} />
|
||||
</div>
|
||||
<CardTitle className="mt-3">{type.name}</CardTitle>
|
||||
<CardDescription className="line-clamp-2">
|
||||
{type.description || 'No description provided'}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{/* Expertise tags */}
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{type.expertise.slice(0, 3).map((skill) => (
|
||||
<Badge key={skill} variant="secondary" className="text-xs">
|
||||
{skill}
|
||||
</Badge>
|
||||
))}
|
||||
{type.expertise.length > 3 && (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
+{type.expertise.length - 3}
|
||||
</Badge>
|
||||
)}
|
||||
{type.expertise.length === 0 && (
|
||||
<span className="text-xs text-muted-foreground">No expertise defined</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* Metadata */}
|
||||
<div className="flex items-center justify-between text-sm text-muted-foreground">
|
||||
<div className="flex items-center gap-1">
|
||||
<Cpu className="h-3.5 w-3.5" />
|
||||
<span className="text-xs">{getModelDisplayName(type.primary_model)}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Bot className="h-3.5 w-3.5" />
|
||||
<span className="text-xs">{type.instance_count} instances</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Empty State */}
|
||||
{!isLoading && agentTypes.length === 0 && (
|
||||
<div className="py-12 text-center">
|
||||
<Bot className="mx-auto h-12 w-12 text-muted-foreground" />
|
||||
<h3 className="mt-4 font-semibold">No agent types found</h3>
|
||||
<p className="text-muted-foreground">
|
||||
{searchQuery || statusFilter !== 'all'
|
||||
? 'Try adjusting your search or filters'
|
||||
: 'Create your first agent type to get started'}
|
||||
</p>
|
||||
{!searchQuery && statusFilter === 'all' && (
|
||||
<Button onClick={onCreate} className="mt-4">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Agent Type
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
9
frontend/src/components/agents/index.ts
Normal file
9
frontend/src/components/agents/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Agent Components
|
||||
*
|
||||
* Components for managing agent types and agent instances.
|
||||
*/
|
||||
|
||||
export { AgentTypeForm } from './AgentTypeForm';
|
||||
export { AgentTypeList } from './AgentTypeList';
|
||||
export { AgentTypeDetail } from './AgentTypeDetail';
|
||||
242
frontend/src/components/projects/AgentPanel.tsx
Normal file
242
frontend/src/components/projects/AgentPanel.tsx
Normal file
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* Agent Panel Component
|
||||
*
|
||||
* Displays a list of active agents on the project with their status and current task.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { Bot, MoreVertical } from 'lucide-react';
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { AgentStatusIndicator } from './AgentStatusIndicator';
|
||||
import type { AgentInstance } from './types';
|
||||
|
||||
// ============================================================================
|
||||
// Types
|
||||
// ============================================================================
|
||||
|
||||
interface AgentPanelProps {
|
||||
/** List of agent instances */
|
||||
agents: AgentInstance[];
|
||||
/** Whether data is loading */
|
||||
isLoading?: boolean;
|
||||
/** Callback when "Manage Agents" is clicked */
|
||||
onManageAgents?: () => void;
|
||||
/** Callback when an agent action is triggered */
|
||||
onAgentAction?: (agentId: string, action: 'view' | 'pause' | 'restart' | 'terminate') => void;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Helper Functions
|
||||
// ============================================================================
|
||||
|
||||
function getAgentAvatarText(agent: AgentInstance): string {
|
||||
if (agent.avatar) return agent.avatar;
|
||||
// Generate initials from role
|
||||
const words = agent.role.split(/[\s_-]+/);
|
||||
if (words.length >= 2) {
|
||||
return (words[0][0] + words[1][0]).toUpperCase();
|
||||
}
|
||||
return agent.role.substring(0, 2).toUpperCase();
|
||||
}
|
||||
|
||||
function formatLastActivity(lastActivity?: string): string {
|
||||
if (!lastActivity) return 'No activity';
|
||||
try {
|
||||
return formatDistanceToNow(new Date(lastActivity), { addSuffix: true });
|
||||
} catch {
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Subcomponents
|
||||
// ============================================================================
|
||||
|
||||
function AgentListItem({
|
||||
agent,
|
||||
onAction,
|
||||
}: {
|
||||
agent: AgentInstance;
|
||||
onAction?: (agentId: string, action: 'view' | 'pause' | 'restart' | 'terminate') => void;
|
||||
}) {
|
||||
const avatarText = getAgentAvatarText(agent);
|
||||
const lastActivity = formatLastActivity(agent.last_activity_at);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex items-center justify-between rounded-lg border p-3 transition-colors hover:bg-muted/50"
|
||||
data-testid={`agent-item-${agent.id}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Avatar */}
|
||||
<div
|
||||
className="flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-sm font-medium text-primary"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{avatarText}
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium">{agent.name}</span>
|
||||
<AgentStatusIndicator status={agent.status} />
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground line-clamp-1">
|
||||
{agent.current_task || 'No active task'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground">{lastActivity}</span>
|
||||
|
||||
{onAction && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
aria-label={`Actions for ${agent.name}`}
|
||||
>
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => onAction(agent.id, 'view')}>
|
||||
View Details
|
||||
</DropdownMenuItem>
|
||||
{agent.status === 'active' || agent.status === 'working' ? (
|
||||
<DropdownMenuItem onClick={() => onAction(agent.id, 'pause')}>
|
||||
Pause Agent
|
||||
</DropdownMenuItem>
|
||||
) : (
|
||||
<DropdownMenuItem onClick={() => onAction(agent.id, 'restart')}>
|
||||
Restart Agent
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={() => onAction(agent.id, 'terminate')}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
Terminate Agent
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AgentPanelSkeleton() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-5 w-32" />
|
||||
<Skeleton className="h-4 w-48" />
|
||||
</div>
|
||||
<Skeleton className="h-9 w-28" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<div key={i} className="flex items-center gap-3 rounded-lg border p-3">
|
||||
<Skeleton className="h-10 w-10 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-3 w-48" />
|
||||
</div>
|
||||
<Skeleton className="h-8 w-8" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main Component
|
||||
// ============================================================================
|
||||
|
||||
export function AgentPanel({
|
||||
agents,
|
||||
isLoading = false,
|
||||
onManageAgents,
|
||||
onAgentAction,
|
||||
className,
|
||||
}: AgentPanelProps) {
|
||||
if (isLoading) {
|
||||
return <AgentPanelSkeleton />;
|
||||
}
|
||||
|
||||
const activeAgentCount = agents.filter(
|
||||
(a) => a.status === 'active' || a.status === 'working'
|
||||
).length;
|
||||
|
||||
return (
|
||||
<Card className={className} data-testid="agent-panel">
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Bot className="h-5 w-5" aria-hidden="true" />
|
||||
Active Agents
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{activeAgentCount} of {agents.length} agents working
|
||||
</CardDescription>
|
||||
</div>
|
||||
{onManageAgents && (
|
||||
<Button variant="outline" size="sm" onClick={onManageAgents}>
|
||||
Manage Agents
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{agents.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-8 text-center text-muted-foreground">
|
||||
<Bot className="mb-2 h-8 w-8" aria-hidden="true" />
|
||||
<p className="text-sm">No agents assigned to this project</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{agents.map((agent) => (
|
||||
<AgentListItem
|
||||
key={agent.id}
|
||||
agent={agent}
|
||||
onAction={onAgentAction}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
79
frontend/src/components/projects/AgentStatusIndicator.tsx
Normal file
79
frontend/src/components/projects/AgentStatusIndicator.tsx
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Agent Status Indicator
|
||||
*
|
||||
* Visual indicator for agent status (idle, working, error, etc.)
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { AgentStatus } from './types';
|
||||
|
||||
const statusConfig: Record<AgentStatus, { color: string; label: string }> = {
|
||||
idle: {
|
||||
color: 'bg-yellow-500',
|
||||
label: 'Idle',
|
||||
},
|
||||
active: {
|
||||
color: 'bg-green-500',
|
||||
label: 'Active',
|
||||
},
|
||||
working: {
|
||||
color: 'bg-green-500 animate-pulse',
|
||||
label: 'Working',
|
||||
},
|
||||
pending: {
|
||||
color: 'bg-gray-400',
|
||||
label: 'Pending',
|
||||
},
|
||||
error: {
|
||||
color: 'bg-red-500',
|
||||
label: 'Error',
|
||||
},
|
||||
terminated: {
|
||||
color: 'bg-gray-600',
|
||||
label: 'Terminated',
|
||||
},
|
||||
};
|
||||
|
||||
interface AgentStatusIndicatorProps {
|
||||
status: AgentStatus;
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
showLabel?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function AgentStatusIndicator({
|
||||
status,
|
||||
size = 'sm',
|
||||
showLabel = false,
|
||||
className,
|
||||
}: AgentStatusIndicatorProps) {
|
||||
const config = statusConfig[status] || statusConfig.pending;
|
||||
|
||||
const sizeClasses = {
|
||||
sm: 'h-2 w-2',
|
||||
md: 'h-3 w-3',
|
||||
lg: 'h-4 w-4',
|
||||
};
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn('inline-flex items-center gap-1.5', className)}
|
||||
role="status"
|
||||
aria-label={`Status: ${config.label}`}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'inline-block rounded-full',
|
||||
sizeClasses[size],
|
||||
config.color
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{showLabel && (
|
||||
<span className="text-xs text-muted-foreground">{config.label}</span>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
146
frontend/src/components/projects/BurndownChart.tsx
Normal file
146
frontend/src/components/projects/BurndownChart.tsx
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Burndown Chart Component
|
||||
*
|
||||
* Simple SVG-based burndown chart showing actual vs ideal progress.
|
||||
* This is a placeholder that will be enhanced when a charting library is integrated.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { BurndownDataPoint } from './types';
|
||||
|
||||
interface BurndownChartProps {
|
||||
/** Burndown data points */
|
||||
data: BurndownDataPoint[];
|
||||
/** Chart height */
|
||||
height?: number;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
/** Show legend */
|
||||
showLegend?: boolean;
|
||||
}
|
||||
|
||||
export function BurndownChart({
|
||||
data,
|
||||
height = 120,
|
||||
className,
|
||||
showLegend = true,
|
||||
}: BurndownChartProps) {
|
||||
if (data.length === 0) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center justify-center rounded-md border border-dashed p-4 text-sm text-muted-foreground',
|
||||
className
|
||||
)}
|
||||
style={{ height }}
|
||||
>
|
||||
No burndown data available
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const chartWidth = 100;
|
||||
const chartHeight = height;
|
||||
const padding = { top: 10, right: 10, bottom: 20, left: 10 };
|
||||
const innerWidth = chartWidth - padding.left - padding.right;
|
||||
const innerHeight = chartHeight - padding.top - padding.bottom;
|
||||
|
||||
const maxPoints = Math.max(...data.map((d) => Math.max(d.remaining, d.ideal)));
|
||||
|
||||
// Generate points for polylines
|
||||
const getPoints = (key: 'remaining' | 'ideal') => {
|
||||
return data
|
||||
.map((d, i) => {
|
||||
const x = padding.left + (i / (data.length - 1)) * innerWidth;
|
||||
const y = padding.top + innerHeight - (d[key] / maxPoints) * innerHeight;
|
||||
return `${x},${y}`;
|
||||
})
|
||||
.join(' ');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn('w-full', className)}>
|
||||
<div className="relative" style={{ height }}>
|
||||
<svg
|
||||
viewBox={`0 0 ${chartWidth} ${chartHeight}`}
|
||||
className="h-full w-full"
|
||||
preserveAspectRatio="none"
|
||||
role="img"
|
||||
aria-label="Sprint burndown chart showing actual progress versus ideal progress"
|
||||
>
|
||||
{/* Grid lines */}
|
||||
<g className="text-muted stroke-current opacity-20">
|
||||
{[0, 0.25, 0.5, 0.75, 1].map((ratio) => (
|
||||
<line
|
||||
key={ratio}
|
||||
x1={padding.left}
|
||||
y1={padding.top + innerHeight * ratio}
|
||||
x2={padding.left + innerWidth}
|
||||
y2={padding.top + innerHeight * ratio}
|
||||
strokeWidth="0.5"
|
||||
/>
|
||||
))}
|
||||
</g>
|
||||
|
||||
{/* Ideal line (dashed) */}
|
||||
<polyline
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeOpacity="0.3"
|
||||
strokeWidth="1"
|
||||
strokeDasharray="4,2"
|
||||
points={getPoints('ideal')}
|
||||
/>
|
||||
|
||||
{/* Actual line */}
|
||||
<polyline
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
className="text-primary"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
points={getPoints('remaining')}
|
||||
/>
|
||||
|
||||
{/* Data points on actual line */}
|
||||
{data.map((d, i) => {
|
||||
const x = padding.left + (i / (data.length - 1)) * innerWidth;
|
||||
const y = padding.top + innerHeight - (d.remaining / maxPoints) * innerHeight;
|
||||
return (
|
||||
<circle
|
||||
key={i}
|
||||
cx={x}
|
||||
cy={y}
|
||||
r="2"
|
||||
className="fill-primary"
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</svg>
|
||||
|
||||
{/* X-axis labels */}
|
||||
<div className="absolute bottom-0 left-0 right-0 flex justify-between text-xs text-muted-foreground">
|
||||
<span>Day 1</span>
|
||||
<span>Day {data.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Legend */}
|
||||
{showLegend && (
|
||||
<div className="mt-2 flex items-center justify-center gap-6 text-xs text-muted-foreground">
|
||||
<span className="flex items-center gap-1">
|
||||
<span className="h-0.5 w-4 bg-primary" />
|
||||
Actual
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<span className="h-0.5 w-4 border-t border-dashed border-muted-foreground" />
|
||||
Ideal
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
194
frontend/src/components/projects/IssueSummary.tsx
Normal file
194
frontend/src/components/projects/IssueSummary.tsx
Normal file
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* Issue Summary Component
|
||||
*
|
||||
* Sidebar component showing issue counts by status.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import {
|
||||
GitBranch,
|
||||
CircleDot,
|
||||
PlayCircle,
|
||||
Clock,
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
} from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import type { IssueSummary as IssueSummaryType } from './types';
|
||||
|
||||
// ============================================================================
|
||||
// Types
|
||||
// ============================================================================
|
||||
|
||||
interface IssueSummaryProps {
|
||||
/** Issue summary data */
|
||||
summary: IssueSummaryType | null;
|
||||
/** Whether data is loading */
|
||||
isLoading?: boolean;
|
||||
/** Callback when "View All Issues" is clicked */
|
||||
onViewAllIssues?: () => void;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
interface StatusRowProps {
|
||||
icon: React.ElementType;
|
||||
iconColor: string;
|
||||
label: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Subcomponents
|
||||
// ============================================================================
|
||||
|
||||
function StatusRow({ icon: Icon, iconColor, label, count }: StatusRowProps) {
|
||||
return (
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Icon className={cn('h-4 w-4', iconColor)} aria-hidden="true" />
|
||||
<span className="text-sm">{label}</span>
|
||||
</div>
|
||||
<span className="font-medium">{count}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function IssueSummarySkeleton() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{[1, 2, 3, 4].map((i) => (
|
||||
<div key={i} className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Skeleton className="h-4 w-4" />
|
||||
<Skeleton className="h-4 w-20" />
|
||||
</div>
|
||||
<Skeleton className="h-4 w-8" />
|
||||
</div>
|
||||
))}
|
||||
<Skeleton className="h-px w-full" />
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Skeleton className="h-4 w-4" />
|
||||
<Skeleton className="h-4 w-20" />
|
||||
</div>
|
||||
<Skeleton className="h-4 w-8" />
|
||||
</div>
|
||||
<div className="pt-2">
|
||||
<Skeleton className="h-9 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main Component
|
||||
// ============================================================================
|
||||
|
||||
export function IssueSummary({
|
||||
summary,
|
||||
isLoading = false,
|
||||
onViewAllIssues,
|
||||
className,
|
||||
}: IssueSummaryProps) {
|
||||
if (isLoading) {
|
||||
return <IssueSummarySkeleton />;
|
||||
}
|
||||
|
||||
if (!summary) {
|
||||
return (
|
||||
<Card className={className} data-testid="issue-summary">
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="flex items-center gap-2 text-lg">
|
||||
<GitBranch className="h-5 w-5" aria-hidden="true" />
|
||||
Issue Summary
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-col items-center justify-center py-4 text-center text-muted-foreground">
|
||||
<CircleDot className="mb-2 h-6 w-6" aria-hidden="true" />
|
||||
<p className="text-sm">No issues found</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className={className} data-testid="issue-summary">
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="flex items-center gap-2 text-lg">
|
||||
<GitBranch className="h-5 w-5" aria-hidden="true" />
|
||||
Issue Summary
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3" role="list" aria-label="Issue counts by status">
|
||||
<StatusRow
|
||||
icon={CircleDot}
|
||||
iconColor="text-blue-500"
|
||||
label="Open"
|
||||
count={summary.open}
|
||||
/>
|
||||
<StatusRow
|
||||
icon={PlayCircle}
|
||||
iconColor="text-yellow-500"
|
||||
label="In Progress"
|
||||
count={summary.in_progress}
|
||||
/>
|
||||
<StatusRow
|
||||
icon={Clock}
|
||||
iconColor="text-purple-500"
|
||||
label="In Review"
|
||||
count={summary.in_review}
|
||||
/>
|
||||
<StatusRow
|
||||
icon={AlertCircle}
|
||||
iconColor="text-red-500"
|
||||
label="Blocked"
|
||||
count={summary.blocked}
|
||||
/>
|
||||
|
||||
<Separator />
|
||||
|
||||
<StatusRow
|
||||
icon={CheckCircle2}
|
||||
iconColor="text-green-500"
|
||||
label="Completed"
|
||||
count={summary.done}
|
||||
/>
|
||||
|
||||
{onViewAllIssues && (
|
||||
<div className="pt-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
size="sm"
|
||||
onClick={onViewAllIssues}
|
||||
>
|
||||
View All Issues ({summary.total})
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
75
frontend/src/components/projects/ProgressBar.tsx
Normal file
75
frontend/src/components/projects/ProgressBar.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Progress Bar Component
|
||||
*
|
||||
* Simple progress bar with customizable appearance.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface ProgressBarProps {
|
||||
/** Progress value (0-100) */
|
||||
value: number;
|
||||
/** Color variant */
|
||||
variant?: 'default' | 'success' | 'warning' | 'error';
|
||||
/** Height size */
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
/** Show percentage label */
|
||||
showLabel?: boolean;
|
||||
/** Additional CSS classes for the container */
|
||||
className?: string;
|
||||
/** Aria label for accessibility */
|
||||
'aria-label'?: string;
|
||||
}
|
||||
|
||||
const variantClasses = {
|
||||
default: 'bg-primary',
|
||||
success: 'bg-green-500',
|
||||
warning: 'bg-yellow-500',
|
||||
error: 'bg-red-500',
|
||||
};
|
||||
|
||||
const sizeClasses = {
|
||||
sm: 'h-1',
|
||||
md: 'h-2',
|
||||
lg: 'h-3',
|
||||
};
|
||||
|
||||
export function ProgressBar({
|
||||
value,
|
||||
variant = 'default',
|
||||
size = 'md',
|
||||
showLabel = false,
|
||||
className,
|
||||
'aria-label': ariaLabel,
|
||||
}: ProgressBarProps) {
|
||||
const clampedValue = Math.min(100, Math.max(0, value));
|
||||
|
||||
return (
|
||||
<div className={cn('w-full', className)}>
|
||||
{showLabel && (
|
||||
<div className="mb-1 flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">Progress</span>
|
||||
<span className="font-medium">{Math.round(clampedValue)}%</span>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className={cn('w-full rounded-full bg-muted', sizeClasses[size])}
|
||||
role="progressbar"
|
||||
aria-valuenow={clampedValue}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-label={ariaLabel || `Progress: ${Math.round(clampedValue)}%`}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'h-full rounded-full transition-all duration-300 ease-in-out',
|
||||
variantClasses[variant]
|
||||
)}
|
||||
style={{ width: `${clampedValue}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
451
frontend/src/components/projects/ProjectDashboard.tsx
Normal file
451
frontend/src/components/projects/ProjectDashboard.tsx
Normal file
@@ -0,0 +1,451 @@
|
||||
/**
|
||||
* Project Dashboard Component
|
||||
*
|
||||
* Main dashboard view for a project showing agents, sprints, issues, and activity.
|
||||
* Integrates real-time updates via SSE.
|
||||
*
|
||||
* @see Issue #40
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { AlertCircle, RefreshCw } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ConnectionStatus } from '@/components/events/ConnectionStatus';
|
||||
import { useProjectEvents } from '@/lib/hooks/useProjectEvents';
|
||||
import { EventType, type ProjectEvent } from '@/lib/types/events';
|
||||
import { ProjectHeader } from './ProjectHeader';
|
||||
import { AgentPanel } from './AgentPanel';
|
||||
import { SprintProgress } from './SprintProgress';
|
||||
import { IssueSummary } from './IssueSummary';
|
||||
import { RecentActivity } from './RecentActivity';
|
||||
import type {
|
||||
Project,
|
||||
AgentInstance,
|
||||
Sprint,
|
||||
BurndownDataPoint,
|
||||
IssueSummary as IssueSummaryType,
|
||||
ActivityItem,
|
||||
} from './types';
|
||||
|
||||
// ============================================================================
|
||||
// Types
|
||||
// ============================================================================
|
||||
|
||||
interface ProjectDashboardProps {
|
||||
/** Project ID */
|
||||
projectId: string;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Mock Data (to be replaced with API calls)
|
||||
// ============================================================================
|
||||
|
||||
// Mock data for development - will be replaced with TanStack Query hooks
|
||||
const mockProject: Project = {
|
||||
id: 'proj-001',
|
||||
name: 'E-Commerce Platform Redesign',
|
||||
description: 'Complete redesign of the e-commerce platform with modern UI/UX',
|
||||
status: 'in_progress',
|
||||
autonomy_level: 'milestone',
|
||||
current_sprint_id: 'sprint-003',
|
||||
created_at: '2025-01-15T00:00:00Z',
|
||||
owner_id: 'user-001',
|
||||
};
|
||||
|
||||
const mockAgents: AgentInstance[] = [
|
||||
{
|
||||
id: 'agent-001',
|
||||
agent_type_id: 'type-po',
|
||||
project_id: 'proj-001',
|
||||
name: 'Product Owner',
|
||||
role: 'product_owner',
|
||||
status: 'active',
|
||||
current_task: 'Reviewing user story acceptance criteria',
|
||||
last_activity_at: new Date(Date.now() - 2 * 60 * 1000).toISOString(),
|
||||
spawned_at: '2025-01-15T00:00:00Z',
|
||||
avatar: 'PO',
|
||||
},
|
||||
{
|
||||
id: 'agent-002',
|
||||
agent_type_id: 'type-arch',
|
||||
project_id: 'proj-001',
|
||||
name: 'Architect',
|
||||
role: 'architect',
|
||||
status: 'working',
|
||||
current_task: 'Designing API contract for checkout flow',
|
||||
last_activity_at: new Date(Date.now() - 5 * 60 * 1000).toISOString(),
|
||||
spawned_at: '2025-01-15T00:00:00Z',
|
||||
avatar: 'AR',
|
||||
},
|
||||
{
|
||||
id: 'agent-003',
|
||||
agent_type_id: 'type-be',
|
||||
project_id: 'proj-001',
|
||||
name: 'Backend Engineer',
|
||||
role: 'backend_engineer',
|
||||
status: 'idle',
|
||||
current_task: 'Waiting for architecture review',
|
||||
last_activity_at: new Date(Date.now() - 15 * 60 * 1000).toISOString(),
|
||||
spawned_at: '2025-01-15T00:00:00Z',
|
||||
avatar: 'BE',
|
||||
},
|
||||
{
|
||||
id: 'agent-004',
|
||||
agent_type_id: 'type-fe',
|
||||
project_id: 'proj-001',
|
||||
name: 'Frontend Engineer',
|
||||
role: 'frontend_engineer',
|
||||
status: 'active',
|
||||
current_task: 'Implementing product catalog component',
|
||||
last_activity_at: new Date(Date.now() - 1 * 60 * 1000).toISOString(),
|
||||
spawned_at: '2025-01-15T00:00:00Z',
|
||||
avatar: 'FE',
|
||||
},
|
||||
{
|
||||
id: 'agent-005',
|
||||
agent_type_id: 'type-qa',
|
||||
project_id: 'proj-001',
|
||||
name: 'QA Engineer',
|
||||
role: 'qa_engineer',
|
||||
status: 'pending',
|
||||
current_task: 'Preparing test cases for Sprint 3',
|
||||
last_activity_at: new Date(Date.now() - 30 * 60 * 1000).toISOString(),
|
||||
spawned_at: '2025-01-15T00:00:00Z',
|
||||
avatar: 'QA',
|
||||
},
|
||||
];
|
||||
|
||||
const mockSprint: Sprint = {
|
||||
id: 'sprint-003',
|
||||
project_id: 'proj-001',
|
||||
name: 'Sprint 3',
|
||||
goal: 'Complete checkout flow',
|
||||
status: 'active',
|
||||
start_date: '2025-01-27',
|
||||
end_date: '2025-02-10',
|
||||
total_issues: 15,
|
||||
completed_issues: 8,
|
||||
in_progress_issues: 4,
|
||||
blocked_issues: 1,
|
||||
todo_issues: 2,
|
||||
};
|
||||
|
||||
const mockBurndownData: BurndownDataPoint[] = [
|
||||
{ day: 1, remaining: 45, ideal: 45 },
|
||||
{ day: 2, remaining: 42, ideal: 42 },
|
||||
{ day: 3, remaining: 38, ideal: 39 },
|
||||
{ day: 4, remaining: 35, ideal: 36 },
|
||||
{ day: 5, remaining: 30, ideal: 33 },
|
||||
{ day: 6, remaining: 28, ideal: 30 },
|
||||
{ day: 7, remaining: 25, ideal: 27 },
|
||||
{ day: 8, remaining: 20, ideal: 24 },
|
||||
];
|
||||
|
||||
const mockIssueSummary: IssueSummaryType = {
|
||||
open: 12,
|
||||
in_progress: 8,
|
||||
in_review: 3,
|
||||
blocked: 2,
|
||||
done: 45,
|
||||
total: 70,
|
||||
};
|
||||
|
||||
const mockActivity: ActivityItem[] = [
|
||||
{
|
||||
id: 'act-001',
|
||||
type: 'agent_message',
|
||||
agent: 'Product Owner',
|
||||
message: 'Approved user story #42: Cart checkout flow',
|
||||
timestamp: new Date(Date.now() - 2 * 60 * 1000).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 'act-002',
|
||||
type: 'issue_update',
|
||||
agent: 'Backend Engineer',
|
||||
message: 'Moved issue #38 to "In Review"',
|
||||
timestamp: new Date(Date.now() - 8 * 60 * 1000).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 'act-003',
|
||||
type: 'agent_status',
|
||||
agent: 'Frontend Engineer',
|
||||
message: 'Started working on issue #45',
|
||||
timestamp: new Date(Date.now() - 15 * 60 * 1000).toISOString(),
|
||||
},
|
||||
{
|
||||
id: 'act-004',
|
||||
type: 'approval_request',
|
||||
agent: 'Architect',
|
||||
message: 'Requesting approval for API design document',
|
||||
timestamp: new Date(Date.now() - 25 * 60 * 1000).toISOString(),
|
||||
requires_action: true,
|
||||
},
|
||||
{
|
||||
id: 'act-005',
|
||||
type: 'sprint_event',
|
||||
agent: 'System',
|
||||
message: 'Sprint 3 daily standup completed',
|
||||
timestamp: new Date(Date.now() - 60 * 60 * 1000).toISOString(),
|
||||
},
|
||||
];
|
||||
|
||||
// ============================================================================
|
||||
// Helper Functions
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Convert SSE events to activity items
|
||||
*/
|
||||
function eventToActivity(event: ProjectEvent): ActivityItem {
|
||||
const getAgentName = (event: ProjectEvent): string | undefined => {
|
||||
if (event.actor_type === 'agent') {
|
||||
const payload = event.payload as Record<string, unknown>;
|
||||
return (payload.agent_name as string) || 'Agent';
|
||||
}
|
||||
if (event.actor_type === 'system') {
|
||||
return 'System';
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const getMessage = (event: ProjectEvent): string => {
|
||||
const payload = event.payload as Record<string, unknown>;
|
||||
switch (event.type) {
|
||||
case EventType.AGENT_SPAWNED:
|
||||
return `spawned as ${payload.role || 'agent'}`;
|
||||
case EventType.AGENT_MESSAGE:
|
||||
return String(payload.message || 'sent a message');
|
||||
case EventType.AGENT_STATUS_CHANGED:
|
||||
return `status changed to ${payload.new_status}`;
|
||||
case EventType.ISSUE_CREATED:
|
||||
return `created issue: ${payload.title}`;
|
||||
case EventType.ISSUE_UPDATED:
|
||||
return `updated issue #${payload.issue_id}`;
|
||||
case EventType.APPROVAL_REQUESTED:
|
||||
return String(payload.description || 'requested approval');
|
||||
case EventType.SPRINT_STARTED:
|
||||
return `started sprint: ${payload.sprint_name}`;
|
||||
default:
|
||||
return event.type.replace(/_/g, ' ');
|
||||
}
|
||||
};
|
||||
|
||||
const getType = (event: ProjectEvent): ActivityItem['type'] => {
|
||||
if (event.type.startsWith('agent.message')) return 'agent_message';
|
||||
if (event.type.startsWith('agent.')) return 'agent_status';
|
||||
if (event.type.startsWith('issue.')) return 'issue_update';
|
||||
if (event.type.startsWith('approval.')) return 'approval_request';
|
||||
if (event.type.startsWith('sprint.')) return 'sprint_event';
|
||||
return 'system';
|
||||
};
|
||||
|
||||
return {
|
||||
id: event.id,
|
||||
type: getType(event),
|
||||
agent: getAgentName(event),
|
||||
message: getMessage(event),
|
||||
timestamp: event.timestamp,
|
||||
requires_action: event.type === EventType.APPROVAL_REQUESTED,
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main Component
|
||||
// ============================================================================
|
||||
|
||||
export function ProjectDashboard({ projectId, className }: ProjectDashboardProps) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// SSE connection for real-time updates
|
||||
const {
|
||||
events: sseEvents,
|
||||
connectionState,
|
||||
error: sseError,
|
||||
retryCount,
|
||||
reconnect,
|
||||
} = useProjectEvents(projectId, {
|
||||
autoConnect: true,
|
||||
onEvent: (event) => {
|
||||
// Handle specific event types for state updates
|
||||
console.log('[Dashboard] Received event:', event.type);
|
||||
},
|
||||
});
|
||||
|
||||
// Convert SSE events to activity items
|
||||
const sseActivities = useMemo(() => {
|
||||
return sseEvents.slice(-10).map(eventToActivity);
|
||||
}, [sseEvents]);
|
||||
|
||||
// Merge mock activities with SSE activities (SSE takes priority)
|
||||
const allActivities = useMemo(() => {
|
||||
const merged = [...sseActivities, ...mockActivity];
|
||||
// Sort by timestamp, newest first
|
||||
merged.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
||||
return merged.slice(0, 10);
|
||||
}, [sseActivities]);
|
||||
|
||||
// Use mock data for now (will be replaced with TanStack Query)
|
||||
const project = mockProject;
|
||||
const agents = mockAgents;
|
||||
const sprint = mockSprint;
|
||||
const burndownData = mockBurndownData;
|
||||
const issueSummary = mockIssueSummary;
|
||||
|
||||
// Event handlers
|
||||
const handleStartSprint = useCallback(() => {
|
||||
console.log('Start sprint clicked');
|
||||
// TODO: Implement start sprint action
|
||||
}, []);
|
||||
|
||||
const handlePauseProject = useCallback(() => {
|
||||
console.log('Pause project clicked');
|
||||
// TODO: Implement pause project action
|
||||
}, []);
|
||||
|
||||
const handleCreateSprint = useCallback(() => {
|
||||
console.log('Create sprint clicked');
|
||||
// TODO: Navigate to create sprint page
|
||||
}, []);
|
||||
|
||||
const handleSettings = useCallback(() => {
|
||||
router.push(`/projects/${projectId}/settings`);
|
||||
}, [router, projectId]);
|
||||
|
||||
const handleManageAgents = useCallback(() => {
|
||||
router.push(`/projects/${projectId}/agents`);
|
||||
}, [router, projectId]);
|
||||
|
||||
const handleAgentAction = useCallback(
|
||||
(agentId: string, action: 'view' | 'pause' | 'restart' | 'terminate') => {
|
||||
console.log(`Agent action: ${action} on ${agentId}`);
|
||||
// TODO: Implement agent actions
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const handleViewAllIssues = useCallback(() => {
|
||||
router.push(`/projects/${projectId}/issues`);
|
||||
}, [router, projectId]);
|
||||
|
||||
const handleViewAllActivity = useCallback(() => {
|
||||
router.push(`/projects/${projectId}/activity`);
|
||||
}, [router, projectId]);
|
||||
|
||||
const handleActionClick = useCallback((activityId: string) => {
|
||||
console.log(`Action clicked for activity: ${activityId}`);
|
||||
// TODO: Navigate to approval page
|
||||
}, []);
|
||||
|
||||
// Error state
|
||||
if (error) {
|
||||
return (
|
||||
<div className={cn('container mx-auto px-4 py-6', className)}>
|
||||
<Alert variant="destructive">
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertTitle>Error loading project</AlertTitle>
|
||||
<AlertDescription className="flex items-center gap-2">
|
||||
{error}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setError(null);
|
||||
setIsLoading(true);
|
||||
// TODO: Refetch data
|
||||
}}
|
||||
>
|
||||
<RefreshCw className="mr-2 h-4 w-4" />
|
||||
Retry
|
||||
</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('min-h-screen bg-background', className)} data-testid="project-dashboard">
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
<div className="space-y-6">
|
||||
{/* SSE Connection Status - only show if not connected */}
|
||||
{connectionState !== 'connected' && (
|
||||
<ConnectionStatus
|
||||
state={connectionState}
|
||||
error={sseError}
|
||||
retryCount={retryCount}
|
||||
onReconnect={reconnect}
|
||||
compact
|
||||
className="mb-4"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Header Section */}
|
||||
<ProjectHeader
|
||||
project={project}
|
||||
isLoading={isLoading}
|
||||
canPause={project.status === 'in_progress'}
|
||||
canStart={true}
|
||||
onStartSprint={handleStartSprint}
|
||||
onPauseProject={handlePauseProject}
|
||||
onCreateSprint={handleCreateSprint}
|
||||
onSettings={handleSettings}
|
||||
/>
|
||||
|
||||
{/* Main Content Grid */}
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
{/* Left Column - Agent Panel & Sprint Overview */}
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
{/* Agent Panel */}
|
||||
<AgentPanel
|
||||
agents={agents}
|
||||
isLoading={isLoading}
|
||||
onManageAgents={handleManageAgents}
|
||||
onAgentAction={handleAgentAction}
|
||||
/>
|
||||
|
||||
{/* Sprint Overview */}
|
||||
<SprintProgress
|
||||
sprint={sprint}
|
||||
burndownData={burndownData}
|
||||
availableSprints={[
|
||||
{ id: 'sprint-003', name: 'Sprint 3' },
|
||||
{ id: 'sprint-002', name: 'Sprint 2' },
|
||||
{ id: 'sprint-001', name: 'Sprint 1' },
|
||||
]}
|
||||
selectedSprintId={sprint.id}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Right Column - Activity & Issue Summary */}
|
||||
<div className="space-y-6">
|
||||
{/* Issue Summary */}
|
||||
<IssueSummary
|
||||
summary={issueSummary}
|
||||
isLoading={isLoading}
|
||||
onViewAllIssues={handleViewAllIssues}
|
||||
/>
|
||||
|
||||
{/* Recent Activity */}
|
||||
<RecentActivity
|
||||
activities={allActivities}
|
||||
isLoading={isLoading}
|
||||
onViewAll={handleViewAllActivity}
|
||||
onActionClick={handleActionClick}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
146
frontend/src/components/projects/ProjectHeader.tsx
Normal file
146
frontend/src/components/projects/ProjectHeader.tsx
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Project Header Component
|
||||
*
|
||||
* Header section for the project dashboard with title, status, and quick actions.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { PlayCircle, PauseCircle, Plus, Settings } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { ProjectStatusBadge, AutonomyBadge } from './StatusBadge';
|
||||
import type { Project } from './types';
|
||||
|
||||
// ============================================================================
|
||||
// Types
|
||||
// ============================================================================
|
||||
|
||||
interface ProjectHeaderProps {
|
||||
/** Project data */
|
||||
project: Project | null;
|
||||
/** Whether data is loading */
|
||||
isLoading?: boolean;
|
||||
/** Whether the project can be paused */
|
||||
canPause?: boolean;
|
||||
/** Whether the project can be started */
|
||||
canStart?: boolean;
|
||||
/** Callback when "Start/Run Sprint" is clicked */
|
||||
onStartSprint?: () => void;
|
||||
/** Callback when "Pause" is clicked */
|
||||
onPauseProject?: () => void;
|
||||
/** Callback when "Create Sprint" is clicked */
|
||||
onCreateSprint?: () => void;
|
||||
/** Callback when "Settings" is clicked */
|
||||
onSettings?: () => void;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Subcomponents
|
||||
// ============================================================================
|
||||
|
||||
function ProjectHeaderSkeleton() {
|
||||
return (
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-start md:justify-between">
|
||||
<div className="space-y-3">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Skeleton className="h-9 w-64" />
|
||||
<Skeleton className="h-6 w-24" />
|
||||
<Skeleton className="h-6 w-28" />
|
||||
</div>
|
||||
<Skeleton className="h-5 w-96" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Skeleton className="h-9 w-32" />
|
||||
<Skeleton className="h-9 w-28" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main Component
|
||||
// ============================================================================
|
||||
|
||||
export function ProjectHeader({
|
||||
project,
|
||||
isLoading = false,
|
||||
canPause = false,
|
||||
canStart = true,
|
||||
onStartSprint,
|
||||
onPauseProject,
|
||||
onCreateSprint,
|
||||
onSettings,
|
||||
className,
|
||||
}: ProjectHeaderProps) {
|
||||
if (isLoading) {
|
||||
return <ProjectHeaderSkeleton />;
|
||||
}
|
||||
|
||||
if (!project) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const showPauseButton = canPause && project.status === 'in_progress';
|
||||
const showStartButton = canStart && project.status !== 'completed' && project.status !== 'archived';
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col gap-4 md:flex-row md:items-start md:justify-between',
|
||||
className
|
||||
)}
|
||||
data-testid="project-header"
|
||||
>
|
||||
{/* Project Info */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<h1 className="text-3xl font-bold">{project.name}</h1>
|
||||
<ProjectStatusBadge status={project.status} />
|
||||
<AutonomyBadge level={project.autonomy_level} />
|
||||
</div>
|
||||
{project.description && (
|
||||
<p className="text-muted-foreground">{project.description}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Quick Actions */}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{onSettings && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onSettings}
|
||||
aria-label="Project settings"
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{showPauseButton && onPauseProject && (
|
||||
<Button variant="outline" size="sm" onClick={onPauseProject}>
|
||||
<PauseCircle className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
Pause Project
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{onCreateSprint && (
|
||||
<Button variant="outline" size="sm" onClick={onCreateSprint}>
|
||||
<Plus className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
New Sprint
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{showStartButton && onStartSprint && (
|
||||
<Button size="sm" onClick={onStartSprint}>
|
||||
<PlayCircle className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
Run Sprint
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
207
frontend/src/components/projects/RecentActivity.tsx
Normal file
207
frontend/src/components/projects/RecentActivity.tsx
Normal file
@@ -0,0 +1,207 @@
|
||||
/**
|
||||
* Recent Activity Component
|
||||
*
|
||||
* Displays recent project activity feed with action items.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import {
|
||||
Activity,
|
||||
MessageSquare,
|
||||
GitPullRequest,
|
||||
PlayCircle,
|
||||
AlertCircle,
|
||||
Users,
|
||||
Cog,
|
||||
type LucideIcon,
|
||||
} from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import type { ActivityItem } from './types';
|
||||
|
||||
// ============================================================================
|
||||
// Types
|
||||
// ============================================================================
|
||||
|
||||
interface RecentActivityProps {
|
||||
/** Activity items to display */
|
||||
activities: ActivityItem[];
|
||||
/** Whether data is loading */
|
||||
isLoading?: boolean;
|
||||
/** Maximum items to show */
|
||||
maxItems?: number;
|
||||
/** Callback when "View All" is clicked */
|
||||
onViewAll?: () => void;
|
||||
/** Callback when an action item is clicked */
|
||||
onActionClick?: (activityId: string) => void;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Helper Functions
|
||||
// ============================================================================
|
||||
|
||||
function getActivityIcon(type: ActivityItem['type']): LucideIcon {
|
||||
switch (type) {
|
||||
case 'agent_message':
|
||||
return MessageSquare;
|
||||
case 'issue_update':
|
||||
return GitPullRequest;
|
||||
case 'agent_status':
|
||||
return PlayCircle;
|
||||
case 'approval_request':
|
||||
return AlertCircle;
|
||||
case 'sprint_event':
|
||||
return Users;
|
||||
case 'system':
|
||||
default:
|
||||
return Cog;
|
||||
}
|
||||
}
|
||||
|
||||
function formatTimestamp(timestamp: string): string {
|
||||
try {
|
||||
return formatDistanceToNow(new Date(timestamp), { addSuffix: true });
|
||||
} catch {
|
||||
return 'Unknown time';
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Subcomponents
|
||||
// ============================================================================
|
||||
|
||||
interface ActivityItemRowProps {
|
||||
activity: ActivityItem;
|
||||
onActionClick?: (activityId: string) => void;
|
||||
}
|
||||
|
||||
function ActivityItemRow({ activity, onActionClick }: ActivityItemRowProps) {
|
||||
const Icon = getActivityIcon(activity.type);
|
||||
const timestamp = formatTimestamp(activity.timestamp);
|
||||
|
||||
return (
|
||||
<div className="flex gap-3" data-testid={`activity-item-${activity.id}`}>
|
||||
<div
|
||||
className={cn(
|
||||
'flex h-8 w-8 shrink-0 items-center justify-center rounded-full',
|
||||
activity.requires_action
|
||||
? 'bg-yellow-100 text-yellow-600 dark:bg-yellow-900 dark:text-yellow-400'
|
||||
: 'bg-muted text-muted-foreground'
|
||||
)}
|
||||
>
|
||||
<Icon className="h-4 w-4" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm">
|
||||
{activity.agent && (
|
||||
<span className="font-medium">{activity.agent}</span>
|
||||
)}{' '}
|
||||
<span className="text-muted-foreground">{activity.message}</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">{timestamp}</p>
|
||||
{activity.requires_action && onActionClick && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="mt-2 h-7 text-xs"
|
||||
onClick={() => onActionClick(activity.id)}
|
||||
>
|
||||
Review Request
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RecentActivitySkeleton({ count = 5 }: { count?: number }) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Skeleton className="h-5 w-32" />
|
||||
<Skeleton className="h-8 w-16" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
{Array.from({ length: count }).map((_, i) => (
|
||||
<div key={i} className="flex gap-3">
|
||||
<Skeleton className="h-8 w-8 shrink-0 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
<Skeleton className="h-3 w-20" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main Component
|
||||
// ============================================================================
|
||||
|
||||
export function RecentActivity({
|
||||
activities,
|
||||
isLoading = false,
|
||||
maxItems = 5,
|
||||
onViewAll,
|
||||
onActionClick,
|
||||
className,
|
||||
}: RecentActivityProps) {
|
||||
if (isLoading) {
|
||||
return <RecentActivitySkeleton count={maxItems} />;
|
||||
}
|
||||
|
||||
const displayedActivities = activities.slice(0, maxItems);
|
||||
|
||||
return (
|
||||
<Card className={className} data-testid="recent-activity">
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="flex items-center gap-2 text-lg">
|
||||
<Activity className="h-5 w-5" aria-hidden="true" />
|
||||
Recent Activity
|
||||
</CardTitle>
|
||||
{onViewAll && activities.length > maxItems && (
|
||||
<Button variant="ghost" size="sm" className="text-xs" onClick={onViewAll}>
|
||||
View All
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{displayedActivities.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-8 text-center text-muted-foreground">
|
||||
<Activity className="mb-2 h-8 w-8" aria-hidden="true" />
|
||||
<p className="text-sm">No recent activity</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4" role="list" aria-label="Recent project activity">
|
||||
{displayedActivities.map((activity) => (
|
||||
<ActivityItemRow
|
||||
key={activity.id}
|
||||
activity={activity}
|
||||
onActionClick={onActionClick}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
255
frontend/src/components/projects/SprintProgress.tsx
Normal file
255
frontend/src/components/projects/SprintProgress.tsx
Normal file
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
* Sprint Progress Component
|
||||
*
|
||||
* Displays sprint overview with progress bar, issue stats, and burndown chart.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { TrendingUp, Calendar } from 'lucide-react';
|
||||
import { format } from 'date-fns';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { ProgressBar } from './ProgressBar';
|
||||
import { BurndownChart } from './BurndownChart';
|
||||
import type { Sprint, BurndownDataPoint } from './types';
|
||||
|
||||
// ============================================================================
|
||||
// Types
|
||||
// ============================================================================
|
||||
|
||||
interface SprintProgressProps {
|
||||
/** Current sprint data */
|
||||
sprint: Sprint | null;
|
||||
/** Burndown chart data */
|
||||
burndownData?: BurndownDataPoint[];
|
||||
/** List of available sprints for selector */
|
||||
availableSprints?: { id: string; name: string }[];
|
||||
/** Currently selected sprint ID */
|
||||
selectedSprintId?: string;
|
||||
/** Callback when sprint selection changes */
|
||||
onSprintChange?: (sprintId: string) => void;
|
||||
/** Whether data is loading */
|
||||
isLoading?: boolean;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Helper Functions
|
||||
// ============================================================================
|
||||
|
||||
function formatSprintDates(startDate?: string, endDate?: string): string {
|
||||
if (!startDate || !endDate) return 'Dates not set';
|
||||
try {
|
||||
const start = format(new Date(startDate), 'MMM d');
|
||||
const end = format(new Date(endDate), 'MMM d, yyyy');
|
||||
return `${start} - ${end}`;
|
||||
} catch {
|
||||
return 'Invalid dates';
|
||||
}
|
||||
}
|
||||
|
||||
function calculateProgress(sprint: Sprint): number {
|
||||
if (sprint.total_issues === 0) return 0;
|
||||
return Math.round((sprint.completed_issues / sprint.total_issues) * 100);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Subcomponents
|
||||
// ============================================================================
|
||||
|
||||
interface StatCardProps {
|
||||
value: number;
|
||||
label: string;
|
||||
colorClass: string;
|
||||
}
|
||||
|
||||
function StatCard({ value, label, colorClass }: StatCardProps) {
|
||||
return (
|
||||
<div className="rounded-lg border p-3 text-center">
|
||||
<div className={cn('text-2xl font-bold', colorClass)}>{value}</div>
|
||||
<div className="text-xs text-muted-foreground">{label}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SprintProgressSkeleton() {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-5 w-40" />
|
||||
<Skeleton className="h-4 w-56" />
|
||||
</div>
|
||||
<Skeleton className="h-9 w-32" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-6">
|
||||
{/* Progress bar skeleton */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-4 w-12" />
|
||||
</div>
|
||||
<Skeleton className="h-2 w-full rounded-full" />
|
||||
</div>
|
||||
|
||||
{/* Stats grid skeleton */}
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-4">
|
||||
{[1, 2, 3, 4].map((i) => (
|
||||
<div key={i} className="rounded-lg border p-3 text-center">
|
||||
<Skeleton className="mx-auto h-8 w-8" />
|
||||
<Skeleton className="mx-auto mt-1 h-3 w-16" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Burndown skeleton */}
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-28" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main Component
|
||||
// ============================================================================
|
||||
|
||||
export function SprintProgress({
|
||||
sprint,
|
||||
burndownData = [],
|
||||
availableSprints = [],
|
||||
selectedSprintId,
|
||||
onSprintChange,
|
||||
isLoading = false,
|
||||
className,
|
||||
}: SprintProgressProps) {
|
||||
if (isLoading) {
|
||||
return <SprintProgressSkeleton />;
|
||||
}
|
||||
|
||||
if (!sprint) {
|
||||
return (
|
||||
<Card className={className} data-testid="sprint-progress">
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<TrendingUp className="h-5 w-5" aria-hidden="true" />
|
||||
Sprint Overview
|
||||
</CardTitle>
|
||||
<CardDescription>No active sprint</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-col items-center justify-center py-8 text-center text-muted-foreground">
|
||||
<Calendar className="mb-2 h-8 w-8" aria-hidden="true" />
|
||||
<p className="text-sm">No sprint is currently active</p>
|
||||
<p className="mt-1 text-xs">Create a sprint to track progress</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
const progress = calculateProgress(sprint);
|
||||
const dateRange = formatSprintDates(sprint.start_date, sprint.end_date);
|
||||
|
||||
return (
|
||||
<Card className={className} data-testid="sprint-progress">
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<TrendingUp className="h-5 w-5" aria-hidden="true" />
|
||||
Sprint Overview
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{sprint.name} ({dateRange})
|
||||
</CardDescription>
|
||||
</div>
|
||||
|
||||
{availableSprints.length > 1 && onSprintChange && (
|
||||
<Select
|
||||
value={selectedSprintId || sprint.id}
|
||||
onValueChange={onSprintChange}
|
||||
>
|
||||
<SelectTrigger className="w-32" aria-label="Select sprint">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{availableSprints.map((s) => (
|
||||
<SelectItem key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-6">
|
||||
{/* Sprint Progress */}
|
||||
<ProgressBar
|
||||
value={progress}
|
||||
showLabel
|
||||
aria-label={`Sprint progress: ${progress}% complete`}
|
||||
/>
|
||||
|
||||
{/* Issue Stats Grid */}
|
||||
<div
|
||||
className="grid grid-cols-2 gap-4 sm:grid-cols-4"
|
||||
role="list"
|
||||
aria-label="Sprint issue statistics"
|
||||
>
|
||||
<StatCard
|
||||
value={sprint.completed_issues}
|
||||
label="Completed"
|
||||
colorClass="text-green-600"
|
||||
/>
|
||||
<StatCard
|
||||
value={sprint.in_progress_issues}
|
||||
label="In Progress"
|
||||
colorClass="text-blue-600"
|
||||
/>
|
||||
<StatCard
|
||||
value={sprint.blocked_issues}
|
||||
label="Blocked"
|
||||
colorClass="text-red-600"
|
||||
/>
|
||||
<StatCard
|
||||
value={sprint.todo_issues}
|
||||
label="To Do"
|
||||
colorClass="text-gray-600"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Burndown Chart */}
|
||||
<div>
|
||||
<h4 className="mb-2 text-sm font-medium">Burndown Chart</h4>
|
||||
<BurndownChart data={burndownData} height={120} />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
97
frontend/src/components/projects/StatusBadge.tsx
Normal file
97
frontend/src/components/projects/StatusBadge.tsx
Normal file
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Status Badge Components
|
||||
*
|
||||
* Reusable badge components for displaying project and autonomy status.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { CircleDot } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { ProjectStatus, AutonomyLevel } from './types';
|
||||
|
||||
// ============================================================================
|
||||
// Project Status Badge
|
||||
// ============================================================================
|
||||
|
||||
const projectStatusConfig: Record<ProjectStatus, { label: string; className: string }> = {
|
||||
draft: {
|
||||
label: 'Draft',
|
||||
className: 'bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200',
|
||||
},
|
||||
in_progress: {
|
||||
label: 'In Progress',
|
||||
className: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200',
|
||||
},
|
||||
paused: {
|
||||
label: 'Paused',
|
||||
className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200',
|
||||
},
|
||||
completed: {
|
||||
label: 'Completed',
|
||||
className: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200',
|
||||
},
|
||||
blocked: {
|
||||
label: 'Blocked',
|
||||
className: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200',
|
||||
},
|
||||
archived: {
|
||||
label: 'Archived',
|
||||
className: 'bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400',
|
||||
},
|
||||
};
|
||||
|
||||
interface ProjectStatusBadgeProps {
|
||||
status: ProjectStatus;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function ProjectStatusBadge({ status, className }: ProjectStatusBadgeProps) {
|
||||
const config = projectStatusConfig[status] || projectStatusConfig.draft;
|
||||
|
||||
return (
|
||||
<Badge variant="outline" className={cn(config.className, className)}>
|
||||
{config.label}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Autonomy Level Badge
|
||||
// ============================================================================
|
||||
|
||||
const autonomyLevelConfig: Record<AutonomyLevel, { label: string; description: string }> = {
|
||||
full_control: {
|
||||
label: 'Full Control',
|
||||
description: 'Approve every action',
|
||||
},
|
||||
milestone: {
|
||||
label: 'Milestone',
|
||||
description: 'Approve at sprint boundaries',
|
||||
},
|
||||
autonomous: {
|
||||
label: 'Autonomous',
|
||||
description: 'Only major decisions',
|
||||
},
|
||||
};
|
||||
|
||||
interface AutonomyBadgeProps {
|
||||
level: AutonomyLevel;
|
||||
showDescription?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function AutonomyBadge({ level, showDescription = false, className }: AutonomyBadgeProps) {
|
||||
const config = autonomyLevelConfig[level] || autonomyLevelConfig.milestone;
|
||||
|
||||
return (
|
||||
<Badge variant="secondary" className={cn('gap-1', className)} title={config.description}>
|
||||
<CircleDot className="h-3 w-3" aria-hidden="true" />
|
||||
{config.label}
|
||||
{showDescription && (
|
||||
<span className="text-muted-foreground"> - {config.description}</span>
|
||||
)}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
19
frontend/src/components/projects/index.ts
Normal file
19
frontend/src/components/projects/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Project Components
|
||||
*
|
||||
* Export all project-related components for use throughout the application.
|
||||
*
|
||||
* @module components/projects
|
||||
*/
|
||||
|
||||
// Wizard Components
|
||||
export { ProjectWizard, StepIndicator, SelectableCard } from './wizard';
|
||||
|
||||
// Re-export wizard types
|
||||
export type {
|
||||
WizardState,
|
||||
WizardStep,
|
||||
ProjectComplexity,
|
||||
ClientMode,
|
||||
AutonomyLevel,
|
||||
} from './wizard';
|
||||
120
frontend/src/components/projects/types.ts
Normal file
120
frontend/src/components/projects/types.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Project Dashboard Types
|
||||
*
|
||||
* Type definitions for project-related components.
|
||||
* These types will be updated when the API endpoints are implemented.
|
||||
*
|
||||
* @module components/projects/types
|
||||
*/
|
||||
|
||||
// ============================================================================
|
||||
// Project Types
|
||||
// ============================================================================
|
||||
|
||||
export type ProjectStatus = 'draft' | 'in_progress' | 'paused' | 'completed' | 'blocked' | 'archived';
|
||||
|
||||
export type AutonomyLevel = 'full_control' | 'milestone' | 'autonomous';
|
||||
|
||||
export interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
status: ProjectStatus;
|
||||
autonomy_level: AutonomyLevel;
|
||||
current_sprint_id?: string;
|
||||
created_at: string;
|
||||
updated_at?: string;
|
||||
owner_id: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Agent Types
|
||||
// ============================================================================
|
||||
|
||||
export type AgentStatus = 'idle' | 'active' | 'working' | 'pending' | 'error' | 'terminated';
|
||||
|
||||
export interface AgentInstance {
|
||||
id: string;
|
||||
agent_type_id: string;
|
||||
project_id: string;
|
||||
name: string;
|
||||
role: string;
|
||||
status: AgentStatus;
|
||||
current_task?: string;
|
||||
last_activity_at?: string;
|
||||
spawned_at: string;
|
||||
avatar?: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Sprint Types
|
||||
// ============================================================================
|
||||
|
||||
export type SprintStatus = 'planning' | 'active' | 'review' | 'completed';
|
||||
|
||||
export interface Sprint {
|
||||
id: string;
|
||||
project_id: string;
|
||||
name: string;
|
||||
goal?: string;
|
||||
status: SprintStatus;
|
||||
start_date?: string;
|
||||
end_date?: string;
|
||||
total_issues: number;
|
||||
completed_issues: number;
|
||||
in_progress_issues: number;
|
||||
blocked_issues: number;
|
||||
todo_issues: number;
|
||||
}
|
||||
|
||||
export interface BurndownDataPoint {
|
||||
day: number;
|
||||
date?: string;
|
||||
remaining: number;
|
||||
ideal: number;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Issue Types
|
||||
// ============================================================================
|
||||
|
||||
export type IssueStatus = 'open' | 'in_progress' | 'in_review' | 'blocked' | 'done' | 'closed';
|
||||
|
||||
export type IssuePriority = 'low' | 'medium' | 'high' | 'critical';
|
||||
|
||||
export interface Issue {
|
||||
id: string;
|
||||
project_id: string;
|
||||
sprint_id?: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
status: IssueStatus;
|
||||
priority: IssuePriority;
|
||||
assignee_id?: string;
|
||||
created_at: string;
|
||||
updated_at?: string;
|
||||
labels?: string[];
|
||||
}
|
||||
|
||||
export interface IssueSummary {
|
||||
open: number;
|
||||
in_progress: number;
|
||||
in_review: number;
|
||||
blocked: number;
|
||||
done: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Activity Types
|
||||
// ============================================================================
|
||||
|
||||
export interface ActivityItem {
|
||||
id: string;
|
||||
type: 'agent_message' | 'issue_update' | 'agent_status' | 'approval_request' | 'sprint_event' | 'system';
|
||||
agent?: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
requires_action?: boolean;
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
227
frontend/src/components/projects/wizard/ProjectWizard.tsx
Normal file
227
frontend/src/components/projects/wizard/ProjectWizard.tsx
Normal file
@@ -0,0 +1,227 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Project Creation Wizard
|
||||
*
|
||||
* Multi-step wizard for creating new Syndarix projects.
|
||||
* Adapts based on project complexity - scripts use a simplified 4-step flow.
|
||||
*/
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { ArrowLeft, ArrowRight, Check, CheckCircle2, Loader2 } from 'lucide-react';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { apiClient } from '@/lib/api/client';
|
||||
|
||||
import { StepIndicator } from './StepIndicator';
|
||||
import { useWizardState, type ProjectCreateData } from './useWizardState';
|
||||
import { WIZARD_STEPS } from './constants';
|
||||
import {
|
||||
BasicInfoStep,
|
||||
ComplexityStep,
|
||||
ClientModeStep,
|
||||
AutonomyStep,
|
||||
AgentChatStep,
|
||||
ReviewStep,
|
||||
} from './steps';
|
||||
|
||||
/**
|
||||
* Project response from API
|
||||
*/
|
||||
interface ProjectResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string | null;
|
||||
autonomy_level: string;
|
||||
status: string;
|
||||
settings: Record<string, unknown>;
|
||||
owner_id: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
agent_count: number;
|
||||
issue_count: number;
|
||||
active_sprint_name: string | null;
|
||||
}
|
||||
|
||||
interface ProjectWizardProps {
|
||||
locale: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function ProjectWizard({ locale, className }: ProjectWizardProps) {
|
||||
const router = useRouter();
|
||||
const [isCreated, setIsCreated] = useState(false);
|
||||
|
||||
const {
|
||||
state,
|
||||
updateState,
|
||||
resetState,
|
||||
isScriptMode,
|
||||
canProceed,
|
||||
goNext,
|
||||
goBack,
|
||||
getProjectData,
|
||||
} = useWizardState();
|
||||
|
||||
// Project creation mutation using the configured API client
|
||||
const createProjectMutation = useMutation({
|
||||
mutationFn: async (projectData: ProjectCreateData): Promise<ProjectResponse> => {
|
||||
// Call the projects API endpoint
|
||||
// Note: The API client already handles authentication via interceptors
|
||||
const response = await apiClient.instance.post<ProjectResponse>(
|
||||
'/api/v1/projects',
|
||||
{
|
||||
name: projectData.name,
|
||||
slug: projectData.slug,
|
||||
description: projectData.description,
|
||||
autonomy_level: projectData.autonomy_level,
|
||||
settings: projectData.settings,
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
setIsCreated(true);
|
||||
},
|
||||
onError: (error) => {
|
||||
// Error handling - in production, show toast notification
|
||||
console.error('Failed to create project:', error);
|
||||
},
|
||||
});
|
||||
|
||||
const handleCreate = () => {
|
||||
const projectData = getProjectData();
|
||||
createProjectMutation.mutate(projectData);
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
resetState();
|
||||
setIsCreated(false);
|
||||
createProjectMutation.reset();
|
||||
};
|
||||
|
||||
const handleGoToProject = () => {
|
||||
// Navigate to project dashboard - using slug from successful creation
|
||||
if (createProjectMutation.data) {
|
||||
router.push(`/${locale}/projects/${createProjectMutation.data.slug}`);
|
||||
} else {
|
||||
router.push(`/${locale}/projects`);
|
||||
}
|
||||
};
|
||||
|
||||
// Success screen
|
||||
if (isCreated && createProjectMutation.data) {
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className="mx-auto max-w-2xl">
|
||||
<Card className="text-center">
|
||||
<CardContent className="space-y-6 p-8">
|
||||
<div className="mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-green-100 dark:bg-green-900">
|
||||
<CheckCircle2 className="h-8 w-8 text-green-600 dark:text-green-400" aria-hidden="true" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold">Project Created Successfully!</h2>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
"{createProjectMutation.data.name}" has been created. The Product Owner
|
||||
agent will begin the requirements discovery process shortly.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col justify-center gap-4 sm:flex-row">
|
||||
<Button onClick={handleGoToProject}>Go to Project Dashboard</Button>
|
||||
<Button variant="outline" onClick={handleReset}>
|
||||
Create Another Project
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className="mx-auto max-w-3xl">
|
||||
{/* Step Indicator */}
|
||||
<div className="mb-8">
|
||||
<StepIndicator currentStep={state.step} isScriptMode={isScriptMode} />
|
||||
</div>
|
||||
|
||||
{/* Step Content */}
|
||||
<Card>
|
||||
<CardContent className="p-6 md:p-8">
|
||||
{state.step === WIZARD_STEPS.BASIC_INFO && (
|
||||
<BasicInfoStep state={state} updateState={updateState} />
|
||||
)}
|
||||
{state.step === WIZARD_STEPS.COMPLEXITY && (
|
||||
<ComplexityStep state={state} updateState={updateState} />
|
||||
)}
|
||||
{state.step === WIZARD_STEPS.CLIENT_MODE && !isScriptMode && (
|
||||
<ClientModeStep state={state} updateState={updateState} />
|
||||
)}
|
||||
{state.step === WIZARD_STEPS.AUTONOMY && !isScriptMode && (
|
||||
<AutonomyStep state={state} updateState={updateState} />
|
||||
)}
|
||||
{state.step === WIZARD_STEPS.AGENT_CHAT && <AgentChatStep />}
|
||||
{state.step === WIZARD_STEPS.REVIEW && <ReviewStep state={state} />}
|
||||
</CardContent>
|
||||
|
||||
{/* Navigation Footer */}
|
||||
<Separator />
|
||||
<div className="flex items-center justify-between p-6">
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={goBack}
|
||||
disabled={state.step === WIZARD_STEPS.BASIC_INFO}
|
||||
className={state.step === WIZARD_STEPS.BASIC_INFO ? 'invisible' : ''}
|
||||
>
|
||||
<ArrowLeft className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
Back
|
||||
</Button>
|
||||
|
||||
<div className="flex gap-2">
|
||||
{state.step < WIZARD_STEPS.REVIEW ? (
|
||||
<Button onClick={goNext} disabled={!canProceed}>
|
||||
Next
|
||||
<ArrowRight className="ml-2 h-4 w-4" aria-hidden="true" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
onClick={handleCreate}
|
||||
disabled={createProjectMutation.isPending}
|
||||
>
|
||||
{createProjectMutation.isPending ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" aria-hidden="true" />
|
||||
Creating...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Check className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
Create Project
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error display */}
|
||||
{createProjectMutation.isError && (
|
||||
<div className="border-t bg-destructive/10 p-4">
|
||||
<p className="text-sm text-destructive">
|
||||
Failed to create project. Please try again.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
44
frontend/src/components/projects/wizard/SelectableCard.tsx
Normal file
44
frontend/src/components/projects/wizard/SelectableCard.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Selectable Card Component
|
||||
*
|
||||
* A button-based card that can be selected/deselected.
|
||||
* Used for complexity, client mode, and autonomy selection.
|
||||
*/
|
||||
|
||||
import type { ReactNode } from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface SelectableCardProps {
|
||||
selected: boolean;
|
||||
onClick: () => void;
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
'aria-label'?: string;
|
||||
}
|
||||
|
||||
export function SelectableCard({
|
||||
selected,
|
||||
onClick,
|
||||
children,
|
||||
className,
|
||||
'aria-label': ariaLabel,
|
||||
}: SelectableCardProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
aria-pressed={selected}
|
||||
aria-label={ariaLabel}
|
||||
className={cn(
|
||||
'w-full rounded-lg border-2 p-4 text-left transition-all',
|
||||
'hover:border-primary/50 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
|
||||
selected ? 'border-primary bg-primary/5' : 'border-border',
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
50
frontend/src/components/projects/wizard/StepIndicator.tsx
Normal file
50
frontend/src/components/projects/wizard/StepIndicator.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Step Indicator Component
|
||||
*
|
||||
* Shows progress through the wizard steps with visual feedback.
|
||||
* Dynamically adjusts based on whether script mode is active.
|
||||
*/
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
import { getStepLabels, getDisplayStep, getTotalSteps } from './constants';
|
||||
|
||||
interface StepIndicatorProps {
|
||||
currentStep: number;
|
||||
isScriptMode: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function StepIndicator({ currentStep, isScriptMode, className }: StepIndicatorProps) {
|
||||
const steps = getStepLabels(isScriptMode);
|
||||
const totalSteps = getTotalSteps(isScriptMode);
|
||||
const displayStep = getDisplayStep(currentStep, isScriptMode);
|
||||
|
||||
return (
|
||||
<div className={cn('w-full', className)}>
|
||||
<div className="mb-2 flex items-center justify-between text-sm text-muted-foreground">
|
||||
<span>
|
||||
Step {displayStep} of {totalSteps}
|
||||
</span>
|
||||
<span>{steps[displayStep - 1]}</span>
|
||||
</div>
|
||||
<div className="flex gap-1" role="progressbar" aria-valuenow={displayStep} aria-valuemax={totalSteps}>
|
||||
{Array.from({ length: totalSteps }, (_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={cn(
|
||||
'h-2 flex-1 rounded-full transition-colors',
|
||||
i + 1 < displayStep
|
||||
? 'bg-primary'
|
||||
: i + 1 === displayStep
|
||||
? 'bg-primary/70'
|
||||
: 'bg-muted'
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
188
frontend/src/components/projects/wizard/constants.ts
Normal file
188
frontend/src/components/projects/wizard/constants.ts
Normal file
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* Constants for the Project Creation Wizard
|
||||
*/
|
||||
|
||||
import {
|
||||
FileCode,
|
||||
Folder,
|
||||
Layers,
|
||||
Building2,
|
||||
Zap,
|
||||
HelpCircle,
|
||||
Shield,
|
||||
Milestone,
|
||||
Bot,
|
||||
} from 'lucide-react';
|
||||
|
||||
import type { ComplexityOption, ClientModeOption, AutonomyOption } from './types';
|
||||
|
||||
/**
|
||||
* Complexity options with descriptions
|
||||
* Note: Timelines match the exact requirements from Issue #50
|
||||
*/
|
||||
export const complexityOptions: ComplexityOption[] = [
|
||||
{
|
||||
id: 'script',
|
||||
label: 'Script',
|
||||
icon: FileCode,
|
||||
description: 'Single-file utilities, automation scripts, CLI tools',
|
||||
scope: 'Minutes to 1-2 hours, single file or small module',
|
||||
examples: 'Data migration script, API integration helper, Build tool plugin',
|
||||
skipConfig: true,
|
||||
},
|
||||
{
|
||||
id: 'simple',
|
||||
label: 'Simple',
|
||||
icon: Folder,
|
||||
description: 'Small applications with clear requirements',
|
||||
scope: '2-3 days, handful of files/components',
|
||||
examples: 'Landing page, REST API endpoint, Browser extension',
|
||||
skipConfig: false,
|
||||
},
|
||||
{
|
||||
id: 'medium',
|
||||
label: 'Medium',
|
||||
icon: Layers,
|
||||
description: 'Full applications with multiple features',
|
||||
scope: '2-3 weeks, multiple modules/services',
|
||||
examples: 'Admin dashboard, E-commerce store, Mobile app',
|
||||
skipConfig: false,
|
||||
},
|
||||
{
|
||||
id: 'complex',
|
||||
label: 'Complex',
|
||||
icon: Building2,
|
||||
description: 'Enterprise systems with many moving parts',
|
||||
scope: '2-3 months, distributed architecture',
|
||||
examples: 'SaaS platform, Microservices ecosystem, Data pipeline',
|
||||
skipConfig: false,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Client mode options
|
||||
*/
|
||||
export const clientModeOptions: ClientModeOption[] = [
|
||||
{
|
||||
id: 'technical',
|
||||
label: 'Technical Mode',
|
||||
icon: Zap,
|
||||
description: "I'll provide detailed technical specifications",
|
||||
details: [
|
||||
'Upload existing specs or PRDs',
|
||||
'Define API contracts and schemas',
|
||||
'Specify architecture patterns',
|
||||
'Direct sprint planning input',
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'auto',
|
||||
label: 'Auto Mode',
|
||||
icon: HelpCircle,
|
||||
description: 'Help me figure out what I need',
|
||||
details: [
|
||||
'Guided requirements discovery',
|
||||
'AI suggests best practices',
|
||||
'Interactive brainstorming sessions',
|
||||
'Progressive refinement of scope',
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Autonomy level options with approval matrix
|
||||
*/
|
||||
export const autonomyOptions: AutonomyOption[] = [
|
||||
{
|
||||
id: 'full_control',
|
||||
label: 'Full Control',
|
||||
icon: Shield,
|
||||
description: 'Review every action before it happens',
|
||||
approvals: {
|
||||
codeChanges: true,
|
||||
issueUpdates: true,
|
||||
architectureDecisions: true,
|
||||
sprintPlanning: true,
|
||||
deployments: true,
|
||||
},
|
||||
recommended: 'New users or critical projects',
|
||||
},
|
||||
{
|
||||
id: 'milestone',
|
||||
label: 'Milestone',
|
||||
icon: Milestone,
|
||||
description: 'Review at sprint boundaries',
|
||||
approvals: {
|
||||
codeChanges: false,
|
||||
issueUpdates: false,
|
||||
architectureDecisions: true,
|
||||
sprintPlanning: true,
|
||||
deployments: true,
|
||||
},
|
||||
recommended: 'Balanced control (recommended)',
|
||||
},
|
||||
{
|
||||
id: 'autonomous',
|
||||
label: 'Autonomous',
|
||||
icon: Bot,
|
||||
description: 'Only major decisions require approval',
|
||||
approvals: {
|
||||
codeChanges: false,
|
||||
issueUpdates: false,
|
||||
architectureDecisions: true,
|
||||
sprintPlanning: false,
|
||||
deployments: true,
|
||||
},
|
||||
recommended: 'Experienced users or low-risk projects',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Step configuration for wizard navigation
|
||||
*/
|
||||
export const WIZARD_STEPS = {
|
||||
BASIC_INFO: 1,
|
||||
COMPLEXITY: 2,
|
||||
CLIENT_MODE: 3,
|
||||
AUTONOMY: 4,
|
||||
AGENT_CHAT: 5,
|
||||
REVIEW: 6,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Total steps based on complexity mode
|
||||
*/
|
||||
export const getTotalSteps = (isScriptMode: boolean): number => {
|
||||
return isScriptMode ? 4 : 6;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get step labels based on complexity mode
|
||||
*/
|
||||
export const getStepLabels = (isScriptMode: boolean): string[] => {
|
||||
if (isScriptMode) {
|
||||
return ['Basic Info', 'Complexity', 'Agent Chat', 'Review'];
|
||||
}
|
||||
return ['Basic Info', 'Complexity', 'Client Mode', 'Autonomy', 'Agent Chat', 'Review'];
|
||||
};
|
||||
|
||||
/**
|
||||
* Map actual step to display step for scripts
|
||||
*/
|
||||
export const getDisplayStep = (actualStep: number, isScriptMode: boolean): number => {
|
||||
if (!isScriptMode) return actualStep;
|
||||
|
||||
// For scripts: 1->1, 2->2, 5->3, 6->4
|
||||
switch (actualStep) {
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
case 5:
|
||||
return 3;
|
||||
case 6:
|
||||
return 4;
|
||||
default:
|
||||
return actualStep;
|
||||
}
|
||||
};
|
||||
26
frontend/src/components/projects/wizard/index.ts
Normal file
26
frontend/src/components/projects/wizard/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Project Creation Wizard
|
||||
*
|
||||
* Multi-step wizard for creating new Syndarix projects.
|
||||
*/
|
||||
|
||||
export { ProjectWizard } from './ProjectWizard';
|
||||
export { StepIndicator } from './StepIndicator';
|
||||
export { SelectableCard } from './SelectableCard';
|
||||
|
||||
// Re-export types
|
||||
export type {
|
||||
WizardState,
|
||||
WizardStep,
|
||||
ProjectComplexity,
|
||||
ClientMode,
|
||||
AutonomyLevel,
|
||||
} from './types';
|
||||
|
||||
// Re-export constants
|
||||
export {
|
||||
complexityOptions,
|
||||
clientModeOptions,
|
||||
autonomyOptions,
|
||||
WIZARD_STEPS,
|
||||
} from './constants';
|
||||
171
frontend/src/components/projects/wizard/steps/AgentChatStep.tsx
Normal file
171
frontend/src/components/projects/wizard/steps/AgentChatStep.tsx
Normal file
@@ -0,0 +1,171 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Step 5: Agent Chat Placeholder
|
||||
*
|
||||
* Preview of the requirements discovery chat interface.
|
||||
* This will be fully implemented in Phase 4.
|
||||
*/
|
||||
|
||||
import { Bot, User, MessageSquare, Sparkles } from 'lucide-react';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface MockMessage {
|
||||
id: number;
|
||||
role: 'agent' | 'user';
|
||||
name: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
const mockMessages: MockMessage[] = [
|
||||
{
|
||||
id: 1,
|
||||
role: 'agent',
|
||||
name: 'Product Owner Agent',
|
||||
message:
|
||||
"Hello! I'm your Product Owner agent. I'll help you define what we're building. Can you tell me more about your project goals?",
|
||||
timestamp: '10:00 AM',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
role: 'user',
|
||||
name: 'You',
|
||||
message:
|
||||
'I want to build an e-commerce platform for selling handmade crafts. It should have user accounts, a product catalog, and checkout.',
|
||||
timestamp: '10:02 AM',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
role: 'agent',
|
||||
name: 'Product Owner Agent',
|
||||
message:
|
||||
"Great! Let me break this down into user stories. For the MVP, I'd suggest focusing on: user registration/login, product browsing with categories, and a simple cart checkout. Should we also include seller accounts or just a single store?",
|
||||
timestamp: '10:03 AM',
|
||||
},
|
||||
];
|
||||
|
||||
export function AgentChatStep() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<h2 className="text-2xl font-bold">Requirements Discovery</h2>
|
||||
<Badge variant="secondary">Coming in Phase 4</Badge>
|
||||
</div>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
In the full version, you'll chat with our Product Owner agent here to define
|
||||
requirements.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="border-b pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-primary/10">
|
||||
<Bot className="h-5 w-5 text-primary" aria-hidden="true" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-base">Product Owner Agent</CardTitle>
|
||||
<CardDescription>Requirements discovery and sprint planning</CardDescription>
|
||||
</div>
|
||||
<Badge variant="outline" className="ml-auto">
|
||||
Preview Only
|
||||
</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
{/* Chat Messages Area */}
|
||||
<div
|
||||
className="max-h-80 space-y-4 overflow-y-auto p-4"
|
||||
role="log"
|
||||
aria-label="Chat preview messages"
|
||||
>
|
||||
{mockMessages.map((msg) => (
|
||||
<div
|
||||
key={msg.id}
|
||||
className={cn('flex gap-3', msg.role === 'user' ? 'flex-row-reverse' : '')}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'flex h-8 w-8 shrink-0 items-center justify-center rounded-full',
|
||||
msg.role === 'agent' ? 'bg-primary/10' : 'bg-muted'
|
||||
)}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{msg.role === 'agent' ? (
|
||||
<Bot className="h-4 w-4 text-primary" />
|
||||
) : (
|
||||
<User className="h-4 w-4 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
'max-w-[80%] rounded-lg px-4 py-2',
|
||||
msg.role === 'agent' ? 'bg-muted' : 'bg-primary text-primary-foreground'
|
||||
)}
|
||||
>
|
||||
<p className="text-sm">{msg.message}</p>
|
||||
<p
|
||||
className={cn(
|
||||
'mt-1 text-xs',
|
||||
msg.role === 'agent' ? 'text-muted-foreground' : 'text-primary-foreground/70'
|
||||
)}
|
||||
>
|
||||
{msg.timestamp}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Chat Input Area (disabled preview) */}
|
||||
<div className="border-t p-4">
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
placeholder="Type your message... (disabled in preview)"
|
||||
disabled
|
||||
className="flex-1"
|
||||
aria-label="Chat input (disabled in preview)"
|
||||
/>
|
||||
<Button disabled aria-label="Send message (disabled in preview)">
|
||||
<MessageSquare className="h-4 w-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="mt-2 text-center text-xs text-muted-foreground">
|
||||
This chat interface is a preview. Full agent interaction will be available in Phase 4.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="border-dashed bg-muted/30">
|
||||
<CardContent className="flex items-center gap-4 p-6">
|
||||
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-primary/10">
|
||||
<Sparkles className="h-6 w-6 text-primary" aria-hidden="true" />
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-medium">What to Expect in the Full Version</h4>
|
||||
<ul className="mt-2 space-y-1 text-sm text-muted-foreground">
|
||||
<li>- Interactive requirements gathering with AI Product Owner</li>
|
||||
<li>- Architecture spike with BA and Architect agents</li>
|
||||
<li>- Collaborative backlog creation and prioritization</li>
|
||||
<li>- Real-time refinement of user stories</li>
|
||||
</ul>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
153
frontend/src/components/projects/wizard/steps/AutonomyStep.tsx
Normal file
153
frontend/src/components/projects/wizard/steps/AutonomyStep.tsx
Normal file
@@ -0,0 +1,153 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Step 4: Autonomy Level Selection
|
||||
*
|
||||
* Allows users to choose how much control they want over agent actions.
|
||||
* Includes a detailed approval matrix comparison.
|
||||
* Skipped for script complexity projects.
|
||||
*/
|
||||
|
||||
import { Check, AlertCircle } from 'lucide-react';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { SelectableCard } from '../SelectableCard';
|
||||
import { autonomyOptions } from '../constants';
|
||||
import type { WizardState, AutonomyLevel, ApprovalMatrix } from '../types';
|
||||
import { approvalLabels } from '../types';
|
||||
|
||||
interface AutonomyStepProps {
|
||||
state: WizardState;
|
||||
updateState: (updates: Partial<WizardState>) => void;
|
||||
}
|
||||
|
||||
export function AutonomyStep({ state, updateState }: AutonomyStepProps) {
|
||||
const handleSelect = (autonomyLevel: AutonomyLevel) => {
|
||||
updateState({ autonomyLevel });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold">Autonomy Level</h2>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
How much control do you want over the AI agents' actions?
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4" role="radiogroup" aria-label="Autonomy level options">
|
||||
{autonomyOptions.map((option) => {
|
||||
const Icon = option.icon;
|
||||
const isSelected = state.autonomyLevel === option.id;
|
||||
|
||||
return (
|
||||
<SelectableCard
|
||||
key={option.id}
|
||||
selected={isSelected}
|
||||
onClick={() => handleSelect(option.id)}
|
||||
aria-label={`${option.label}: ${option.description}`}
|
||||
>
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-start md:justify-between">
|
||||
<div className="flex items-start gap-4">
|
||||
<div
|
||||
className={cn(
|
||||
'flex h-10 w-10 shrink-0 items-center justify-center rounded-lg',
|
||||
isSelected ? 'bg-primary text-primary-foreground' : 'bg-muted'
|
||||
)}
|
||||
>
|
||||
<Icon className="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<h3 className="font-semibold">{option.label}</h3>
|
||||
{isSelected && (
|
||||
<div className="flex h-5 w-5 items-center justify-center rounded-full bg-primary text-primary-foreground">
|
||||
<Check className="h-3 w-3" aria-hidden="true" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">{option.description}</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
<span className="font-medium">Best for:</span> {option.recommended}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2 md:justify-end">
|
||||
{Object.entries(option.approvals).map(([key, requiresApproval]) => (
|
||||
<Badge
|
||||
key={key}
|
||||
variant={requiresApproval ? 'default' : 'secondary'}
|
||||
className="text-xs"
|
||||
>
|
||||
{requiresApproval ? 'Approve' : 'Auto'}:{' '}
|
||||
{approvalLabels[key as keyof ApprovalMatrix]}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</SelectableCard>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<Card className="bg-muted/50">
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="flex items-center gap-2 text-base">
|
||||
<AlertCircle className="h-4 w-4" aria-hidden="true" />
|
||||
Approval Matrix
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm" aria-label="Approval requirements by autonomy level">
|
||||
<thead>
|
||||
<tr className="border-b">
|
||||
<th scope="col" className="pb-2 text-left font-medium">
|
||||
Action Type
|
||||
</th>
|
||||
<th scope="col" className="pb-2 text-center font-medium">
|
||||
Full Control
|
||||
</th>
|
||||
<th scope="col" className="pb-2 text-center font-medium">
|
||||
Milestone
|
||||
</th>
|
||||
<th scope="col" className="pb-2 text-center font-medium">
|
||||
Autonomous
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{Object.keys(autonomyOptions[0].approvals).map((key) => (
|
||||
<tr key={key}>
|
||||
<td className="py-2 text-muted-foreground">
|
||||
{approvalLabels[key as keyof ApprovalMatrix]}
|
||||
</td>
|
||||
{autonomyOptions.map((option) => (
|
||||
<td key={option.id} className="py-2 text-center">
|
||||
{option.approvals[key as keyof ApprovalMatrix] ? (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
Required
|
||||
</Badge>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">Automatic</span>
|
||||
)}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
142
frontend/src/components/projects/wizard/steps/BasicInfoStep.tsx
Normal file
142
frontend/src/components/projects/wizard/steps/BasicInfoStep.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Step 1: Basic Information
|
||||
*
|
||||
* Collects project name, description, and optional repository URL.
|
||||
*/
|
||||
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { GitBranch } from 'lucide-react';
|
||||
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import type { WizardState } from '../types';
|
||||
|
||||
const basicInfoSchema = z.object({
|
||||
projectName: z
|
||||
.string()
|
||||
.min(3, 'Project name must be at least 3 characters')
|
||||
.max(255, 'Project name must be less than 255 characters'),
|
||||
description: z.string().max(2000, 'Description must be less than 2000 characters').optional(),
|
||||
repoUrl: z.string().url('Please enter a valid URL').or(z.literal('')).optional(),
|
||||
});
|
||||
|
||||
type BasicInfoFormData = z.infer<typeof basicInfoSchema>;
|
||||
|
||||
interface BasicInfoStepProps {
|
||||
state: WizardState;
|
||||
updateState: (updates: Partial<WizardState>) => void;
|
||||
}
|
||||
|
||||
export function BasicInfoStep({ state, updateState }: BasicInfoStepProps) {
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
trigger,
|
||||
} = useForm<BasicInfoFormData>({
|
||||
resolver: zodResolver(basicInfoSchema),
|
||||
defaultValues: {
|
||||
projectName: state.projectName,
|
||||
description: state.description,
|
||||
repoUrl: state.repoUrl,
|
||||
},
|
||||
mode: 'onBlur',
|
||||
});
|
||||
|
||||
const handleChange = (field: keyof BasicInfoFormData, value: string) => {
|
||||
updateState({ [field]: value });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold">Create New Project</h2>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
Let's start with the basics. Give your project a name and description.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="project-name">
|
||||
Project Name <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="project-name"
|
||||
placeholder="e.g., E-Commerce Platform Redesign"
|
||||
{...register('projectName')}
|
||||
value={state.projectName}
|
||||
onChange={(e) => {
|
||||
handleChange('projectName', e.target.value);
|
||||
if (errors.projectName) {
|
||||
trigger('projectName');
|
||||
}
|
||||
}}
|
||||
onBlur={() => trigger('projectName')}
|
||||
aria-invalid={!!errors.projectName}
|
||||
aria-describedby={errors.projectName ? 'project-name-error' : undefined}
|
||||
/>
|
||||
{errors.projectName && (
|
||||
<p id="project-name-error" className="text-sm text-destructive">
|
||||
{errors.projectName.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="description">Description (Optional)</Label>
|
||||
<Textarea
|
||||
id="description"
|
||||
placeholder="Briefly describe what this project is about..."
|
||||
{...register('description')}
|
||||
value={state.description}
|
||||
onChange={(e) => handleChange('description', e.target.value)}
|
||||
rows={3}
|
||||
aria-describedby="description-hint"
|
||||
/>
|
||||
<p id="description-hint" className="text-xs text-muted-foreground">
|
||||
A clear description helps the AI agents understand your project better.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="repo-url">Repository URL (Optional)</Label>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex h-9 w-9 items-center justify-center rounded-md border bg-muted">
|
||||
<GitBranch className="h-4 w-4 text-muted-foreground" aria-hidden="true" />
|
||||
</div>
|
||||
<Input
|
||||
id="repo-url"
|
||||
placeholder="https://github.com/your-org/your-repo"
|
||||
{...register('repoUrl')}
|
||||
value={state.repoUrl}
|
||||
onChange={(e) => {
|
||||
handleChange('repoUrl', e.target.value);
|
||||
if (errors.repoUrl) {
|
||||
trigger('repoUrl');
|
||||
}
|
||||
}}
|
||||
onBlur={() => trigger('repoUrl')}
|
||||
className="flex-1"
|
||||
aria-invalid={!!errors.repoUrl}
|
||||
aria-describedby={errors.repoUrl ? 'repo-url-error' : 'repo-url-hint'}
|
||||
/>
|
||||
</div>
|
||||
{errors.repoUrl ? (
|
||||
<p id="repo-url-error" className="text-sm text-destructive">
|
||||
{errors.repoUrl.message}
|
||||
</p>
|
||||
) : (
|
||||
<p id="repo-url-hint" className="text-xs text-muted-foreground">
|
||||
Connect an existing repository or leave blank to create a new one.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Step 3: Client Mode Selection
|
||||
*
|
||||
* Allows users to choose how they want to interact with Syndarix agents.
|
||||
* Skipped for script complexity projects.
|
||||
*/
|
||||
|
||||
import { Check, CheckCircle2 } from 'lucide-react';
|
||||
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { SelectableCard } from '../SelectableCard';
|
||||
import { clientModeOptions } from '../constants';
|
||||
import type { WizardState, ClientMode } from '../types';
|
||||
|
||||
interface ClientModeStepProps {
|
||||
state: WizardState;
|
||||
updateState: (updates: Partial<WizardState>) => void;
|
||||
}
|
||||
|
||||
export function ClientModeStep({ state, updateState }: ClientModeStepProps) {
|
||||
const handleSelect = (clientMode: ClientMode) => {
|
||||
updateState({ clientMode });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold">How Would You Like to Work?</h2>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
Choose how you want to interact with Syndarix agents.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-2" role="radiogroup" aria-label="Client interaction mode options">
|
||||
{clientModeOptions.map((option) => {
|
||||
const Icon = option.icon;
|
||||
const isSelected = state.clientMode === option.id;
|
||||
|
||||
return (
|
||||
<SelectableCard
|
||||
key={option.id}
|
||||
selected={isSelected}
|
||||
onClick={() => handleSelect(option.id)}
|
||||
className="h-full"
|
||||
aria-label={`${option.label}: ${option.description}`}
|
||||
>
|
||||
<div className="flex h-full flex-col space-y-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<div
|
||||
className={cn(
|
||||
'flex h-12 w-12 items-center justify-center rounded-lg',
|
||||
isSelected ? 'bg-primary text-primary-foreground' : 'bg-muted'
|
||||
)}
|
||||
>
|
||||
<Icon className="h-6 w-6" aria-hidden="true" />
|
||||
</div>
|
||||
{isSelected && (
|
||||
<div className="flex h-6 w-6 items-center justify-center rounded-full bg-primary text-primary-foreground">
|
||||
<Check className="h-4 w-4" aria-hidden="true" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold">{option.label}</h3>
|
||||
<p className="mt-1 text-muted-foreground">{option.description}</p>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
<ul className="flex-1 space-y-2">
|
||||
{option.details.map((detail) => (
|
||||
<li key={detail} className="flex items-start gap-2 text-sm">
|
||||
<CheckCircle2
|
||||
className={cn(
|
||||
'mt-0.5 h-4 w-4 shrink-0',
|
||||
isSelected ? 'text-primary' : 'text-muted-foreground'
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="text-muted-foreground">{detail}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</SelectableCard>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Step 2: Complexity Assessment
|
||||
*
|
||||
* Allows users to select the project complexity level.
|
||||
* Script complexity triggers simplified flow (skips steps 3-4).
|
||||
*/
|
||||
|
||||
import { Check } from 'lucide-react';
|
||||
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { SelectableCard } from '../SelectableCard';
|
||||
import { complexityOptions } from '../constants';
|
||||
import type { WizardState, ProjectComplexity } from '../types';
|
||||
|
||||
interface ComplexityStepProps {
|
||||
state: WizardState;
|
||||
updateState: (updates: Partial<WizardState>) => void;
|
||||
}
|
||||
|
||||
export function ComplexityStep({ state, updateState }: ComplexityStepProps) {
|
||||
const handleSelect = (complexity: ProjectComplexity) => {
|
||||
updateState({ complexity });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold">Project Complexity</h2>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
How complex is your project? This helps us assign the right resources.
|
||||
</p>
|
||||
{state.complexity === 'script' && (
|
||||
<p className="mt-2 text-sm text-primary">
|
||||
Scripts use a simplified flow - you'll skip to agent chat directly.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2" role="radiogroup" aria-label="Project complexity options">
|
||||
{complexityOptions.map((option) => {
|
||||
const Icon = option.icon;
|
||||
const isSelected = state.complexity === option.id;
|
||||
|
||||
return (
|
||||
<SelectableCard
|
||||
key={option.id}
|
||||
selected={isSelected}
|
||||
onClick={() => handleSelect(option.id)}
|
||||
aria-label={`${option.label}: ${option.description}`}
|
||||
>
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div
|
||||
className={cn(
|
||||
'flex h-10 w-10 items-center justify-center rounded-lg',
|
||||
isSelected ? 'bg-primary text-primary-foreground' : 'bg-muted'
|
||||
)}
|
||||
>
|
||||
<Icon className="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
{isSelected && (
|
||||
<div className="flex h-6 w-6 items-center justify-center rounded-full bg-primary text-primary-foreground">
|
||||
<Check className="h-4 w-4" aria-hidden="true" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-semibold">{option.label}</h3>
|
||||
<p className="mt-1 text-sm text-muted-foreground">{option.description}</p>
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="space-y-1 text-sm">
|
||||
<p className="text-muted-foreground">
|
||||
<span className="font-medium text-foreground">Scope:</span> {option.scope}
|
||||
</p>
|
||||
<p className="text-muted-foreground">
|
||||
<span className="font-medium text-foreground">Examples:</span> {option.examples}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</SelectableCard>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
158
frontend/src/components/projects/wizard/steps/ReviewStep.tsx
Normal file
158
frontend/src/components/projects/wizard/steps/ReviewStep.tsx
Normal file
@@ -0,0 +1,158 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* Step 6: Review & Confirmation
|
||||
*
|
||||
* Shows a summary of all selections before creating the project.
|
||||
*/
|
||||
|
||||
import { CheckCircle2 } from 'lucide-react';
|
||||
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { complexityOptions, clientModeOptions, autonomyOptions } from '../constants';
|
||||
import type { WizardState } from '../types';
|
||||
|
||||
interface ReviewStepProps {
|
||||
state: WizardState;
|
||||
}
|
||||
|
||||
export function ReviewStep({ state }: ReviewStepProps) {
|
||||
const complexity = complexityOptions.find((o) => o.id === state.complexity);
|
||||
const clientMode = clientModeOptions.find((o) => o.id === state.clientMode);
|
||||
const autonomy = autonomyOptions.find((o) => o.id === state.autonomyLevel);
|
||||
|
||||
const isScriptMode = state.complexity === 'script';
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold">Review Your Project</h2>
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
Please review your selections before creating the project.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
{/* Basic Info Card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Basic Information</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div>
|
||||
<p className="text-sm font-medium">Project Name</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{state.projectName || 'Not specified'}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium">Description</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{state.description || 'No description provided'}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium">Repository</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{state.repoUrl || 'New repository will be created'}
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Complexity Card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Project Complexity</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{complexity ? (
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10">
|
||||
<complexity.icon className="h-5 w-5 text-primary" aria-hidden="true" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium">{complexity.label}</p>
|
||||
<p className="text-sm text-muted-foreground">{complexity.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">Not selected</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Client Mode Card - show for non-scripts or show auto-selected for scripts */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Interaction Mode</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isScriptMode ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Auto Mode (automatically set for script projects)
|
||||
</p>
|
||||
) : clientMode ? (
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10">
|
||||
<clientMode.icon className="h-5 w-5 text-primary" aria-hidden="true" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium">{clientMode.label}</p>
|
||||
<p className="text-sm text-muted-foreground">{clientMode.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">Not selected</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Autonomy Card - show for non-scripts or show auto-selected for scripts */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Autonomy Level</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isScriptMode ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Autonomous (automatically set for script projects)
|
||||
</p>
|
||||
) : autonomy ? (
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10">
|
||||
<autonomy.icon className="h-5 w-5 text-primary" aria-hidden="true" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium">{autonomy.label}</p>
|
||||
<p className="text-sm text-muted-foreground">{autonomy.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">Not selected</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Summary Alert */}
|
||||
<Card className="border-primary/50 bg-primary/5">
|
||||
<CardContent className="flex items-start gap-4 p-6">
|
||||
<CheckCircle2 className="mt-0.5 h-5 w-5 shrink-0 text-primary" aria-hidden="true" />
|
||||
<div>
|
||||
<h4 className="font-medium">Ready to Create</h4>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
Once you create this project, Syndarix will set up your environment and begin the
|
||||
requirements discovery phase with the Product Owner agent.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
10
frontend/src/components/projects/wizard/steps/index.ts
Normal file
10
frontend/src/components/projects/wizard/steps/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Export all wizard step components
|
||||
*/
|
||||
|
||||
export { BasicInfoStep } from './BasicInfoStep';
|
||||
export { ComplexityStep } from './ComplexityStep';
|
||||
export { ClientModeStep } from './ClientModeStep';
|
||||
export { AutonomyStep } from './AutonomyStep';
|
||||
export { AgentChatStep } from './AgentChatStep';
|
||||
export { ReviewStep } from './ReviewStep';
|
||||
109
frontend/src/components/projects/wizard/types.ts
Normal file
109
frontend/src/components/projects/wizard/types.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Types and constants for the Project Creation Wizard
|
||||
*/
|
||||
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
|
||||
/**
|
||||
* Project complexity levels matching backend enum
|
||||
*/
|
||||
export type ProjectComplexity = 'script' | 'simple' | 'medium' | 'complex';
|
||||
|
||||
/**
|
||||
* Client interaction mode matching backend enum
|
||||
*/
|
||||
export type ClientMode = 'technical' | 'auto';
|
||||
|
||||
/**
|
||||
* Autonomy level matching backend enum
|
||||
*/
|
||||
export type AutonomyLevel = 'full_control' | 'milestone' | 'autonomous';
|
||||
|
||||
/**
|
||||
* Wizard step numbers
|
||||
*/
|
||||
export type WizardStep = 1 | 2 | 3 | 4 | 5 | 6;
|
||||
|
||||
/**
|
||||
* Full wizard state
|
||||
*/
|
||||
export interface WizardState {
|
||||
step: WizardStep;
|
||||
projectName: string;
|
||||
description: string;
|
||||
repoUrl: string;
|
||||
complexity: ProjectComplexity | null;
|
||||
clientMode: ClientMode | null;
|
||||
autonomyLevel: AutonomyLevel | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Complexity option configuration
|
||||
*/
|
||||
export interface ComplexityOption {
|
||||
id: ProjectComplexity;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
description: string;
|
||||
scope: string;
|
||||
examples: string;
|
||||
skipConfig: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client mode option configuration
|
||||
*/
|
||||
export interface ClientModeOption {
|
||||
id: ClientMode;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
description: string;
|
||||
details: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Approval types for autonomy matrix
|
||||
*/
|
||||
export interface ApprovalMatrix {
|
||||
codeChanges: boolean;
|
||||
issueUpdates: boolean;
|
||||
architectureDecisions: boolean;
|
||||
sprintPlanning: boolean;
|
||||
deployments: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autonomy option configuration
|
||||
*/
|
||||
export interface AutonomyOption {
|
||||
id: AutonomyLevel;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
description: string;
|
||||
approvals: ApprovalMatrix;
|
||||
recommended: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial wizard state
|
||||
*/
|
||||
export const initialWizardState: WizardState = {
|
||||
step: 1,
|
||||
projectName: '',
|
||||
description: '',
|
||||
repoUrl: '',
|
||||
complexity: null,
|
||||
clientMode: null,
|
||||
autonomyLevel: null,
|
||||
};
|
||||
|
||||
/**
|
||||
* Human-readable labels for approval matrix keys
|
||||
*/
|
||||
export const approvalLabels: Record<keyof ApprovalMatrix, string> = {
|
||||
codeChanges: 'Code Changes',
|
||||
issueUpdates: 'Issue Updates',
|
||||
architectureDecisions: 'Architecture Decisions',
|
||||
sprintPlanning: 'Sprint Planning',
|
||||
deployments: 'Deployments',
|
||||
};
|
||||
164
frontend/src/components/projects/wizard/useWizardState.ts
Normal file
164
frontend/src/components/projects/wizard/useWizardState.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Custom hook for managing wizard state
|
||||
*
|
||||
* Handles step navigation logic including script mode shortcuts.
|
||||
*/
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
|
||||
import type { WizardState, WizardStep } from './types';
|
||||
import { initialWizardState } from './types';
|
||||
import { WIZARD_STEPS } from './constants';
|
||||
|
||||
interface UseWizardStateReturn {
|
||||
state: WizardState;
|
||||
updateState: (updates: Partial<WizardState>) => void;
|
||||
resetState: () => void;
|
||||
isScriptMode: boolean;
|
||||
canProceed: boolean;
|
||||
goNext: () => void;
|
||||
goBack: () => void;
|
||||
getProjectData: () => ProjectCreateData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data structure for project creation API call
|
||||
*/
|
||||
export interface ProjectCreateData {
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string | undefined;
|
||||
autonomy_level: 'full_control' | 'milestone' | 'autonomous';
|
||||
settings: {
|
||||
complexity: string;
|
||||
client_mode: string;
|
||||
repo_url?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a URL-safe slug from a project name
|
||||
*/
|
||||
function generateSlug(name: string): string {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^\w\s-]/g, '') // Remove special characters
|
||||
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
||||
.replace(/-+/g, '-') // Replace multiple hyphens with single
|
||||
.replace(/^-+|-+$/g, ''); // Remove leading/trailing hyphens
|
||||
}
|
||||
|
||||
export function useWizardState(): UseWizardStateReturn {
|
||||
const [state, setState] = useState<WizardState>(initialWizardState);
|
||||
|
||||
const isScriptMode = state.complexity === 'script';
|
||||
|
||||
const updateState = useCallback((updates: Partial<WizardState>) => {
|
||||
setState((prev) => ({ ...prev, ...updates }));
|
||||
}, []);
|
||||
|
||||
const resetState = useCallback(() => {
|
||||
setState(initialWizardState);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Check if user can proceed to next step
|
||||
*/
|
||||
const canProceed = (() => {
|
||||
switch (state.step) {
|
||||
case WIZARD_STEPS.BASIC_INFO:
|
||||
return state.projectName.trim().length >= 3;
|
||||
case WIZARD_STEPS.COMPLEXITY:
|
||||
return state.complexity !== null;
|
||||
case WIZARD_STEPS.CLIENT_MODE:
|
||||
return isScriptMode || state.clientMode !== null;
|
||||
case WIZARD_STEPS.AUTONOMY:
|
||||
return isScriptMode || state.autonomyLevel !== null;
|
||||
case WIZARD_STEPS.AGENT_CHAT:
|
||||
return true; // Agent chat is preview only
|
||||
case WIZARD_STEPS.REVIEW:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Navigate to next step, handling script mode skip logic
|
||||
*/
|
||||
const goNext = useCallback(() => {
|
||||
if (!canProceed) return;
|
||||
|
||||
setState((prev) => {
|
||||
let nextStep = (prev.step + 1) as WizardStep;
|
||||
const currentIsScriptMode = prev.complexity === 'script';
|
||||
|
||||
// For scripts, skip from step 2 directly to step 5 (agent chat)
|
||||
if (currentIsScriptMode && prev.step === WIZARD_STEPS.COMPLEXITY) {
|
||||
return {
|
||||
...prev,
|
||||
step: WIZARD_STEPS.AGENT_CHAT as WizardStep,
|
||||
clientMode: 'auto',
|
||||
autonomyLevel: 'autonomous',
|
||||
};
|
||||
}
|
||||
|
||||
// Don't go past review step
|
||||
if (nextStep > WIZARD_STEPS.REVIEW) {
|
||||
nextStep = WIZARD_STEPS.REVIEW as WizardStep;
|
||||
}
|
||||
|
||||
return { ...prev, step: nextStep };
|
||||
});
|
||||
}, [canProceed]);
|
||||
|
||||
/**
|
||||
* Navigate to previous step, handling script mode skip logic
|
||||
*/
|
||||
const goBack = useCallback(() => {
|
||||
setState((prev) => {
|
||||
if (prev.step <= 1) return prev;
|
||||
|
||||
let prevStep = (prev.step - 1) as WizardStep;
|
||||
const currentIsScriptMode = prev.complexity === 'script';
|
||||
|
||||
// For scripts, go from step 5 back to step 2
|
||||
if (currentIsScriptMode && prev.step === WIZARD_STEPS.AGENT_CHAT) {
|
||||
prevStep = WIZARD_STEPS.COMPLEXITY as WizardStep;
|
||||
}
|
||||
|
||||
return { ...prev, step: prevStep };
|
||||
});
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Get data formatted for the project creation API
|
||||
*/
|
||||
const getProjectData = useCallback((): ProjectCreateData => {
|
||||
const slug = generateSlug(state.projectName);
|
||||
|
||||
return {
|
||||
name: state.projectName.trim(),
|
||||
slug,
|
||||
description: state.description.trim() || undefined,
|
||||
autonomy_level: state.autonomyLevel || 'milestone',
|
||||
settings: {
|
||||
complexity: state.complexity || 'medium',
|
||||
client_mode: state.clientMode || 'auto',
|
||||
...(state.repoUrl && { repo_url: state.repoUrl }),
|
||||
},
|
||||
};
|
||||
}, [state]);
|
||||
|
||||
return {
|
||||
state,
|
||||
updateState,
|
||||
resetState,
|
||||
isScriptMode,
|
||||
canProceed,
|
||||
goNext,
|
||||
goBack,
|
||||
getProjectData,
|
||||
};
|
||||
}
|
||||
84
frontend/src/features/issues/components/ActivityTimeline.tsx
Normal file
84
frontend/src/features/issues/components/ActivityTimeline.tsx
Normal file
@@ -0,0 +1,84 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* ActivityTimeline Component
|
||||
*
|
||||
* Displays issue activity history.
|
||||
*
|
||||
* @module features/issues/components/ActivityTimeline
|
||||
*/
|
||||
|
||||
import { MessageSquare, Bot, User } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { IssueActivity } from '../types';
|
||||
|
||||
interface ActivityTimelineProps {
|
||||
activities: IssueActivity[];
|
||||
onAddComment?: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function ActivityTimeline({
|
||||
activities,
|
||||
onAddComment,
|
||||
className,
|
||||
}: ActivityTimelineProps) {
|
||||
return (
|
||||
<Card className={className}>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<MessageSquare className="h-5 w-5" aria-hidden="true" />
|
||||
Activity
|
||||
</CardTitle>
|
||||
{onAddComment && (
|
||||
<Button variant="outline" size="sm" onClick={onAddComment}>
|
||||
Add Comment
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-6" role="list" aria-label="Issue activity">
|
||||
{activities.map((item, index) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className="flex gap-4"
|
||||
role="listitem"
|
||||
>
|
||||
<div className="relative flex flex-col items-center">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-muted">
|
||||
{item.actor.type === 'agent' ? (
|
||||
<Bot className="h-4 w-4" aria-hidden="true" />
|
||||
) : (
|
||||
<User className="h-4 w-4" aria-hidden="true" />
|
||||
)}
|
||||
</div>
|
||||
{index < activities.length - 1 && (
|
||||
<div className="absolute top-8 h-full w-px bg-border" aria-hidden="true" />
|
||||
)}
|
||||
</div>
|
||||
<div className={cn('flex-1', index < activities.length - 1 && 'pb-6')}>
|
||||
<div className="flex flex-wrap items-baseline gap-2">
|
||||
<span className="font-medium">{item.actor.name}</span>
|
||||
<span className="text-sm text-muted-foreground">{item.message}</span>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<time dateTime={item.timestamp}>{item.timestamp}</time>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{activities.length === 0 && (
|
||||
<div className="py-8 text-center text-muted-foreground">
|
||||
No activity yet
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
70
frontend/src/features/issues/components/BulkActions.tsx
Normal file
70
frontend/src/features/issues/components/BulkActions.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* BulkActions Component
|
||||
*
|
||||
* Actions bar for bulk operations on selected issues.
|
||||
*
|
||||
* @module features/issues/components/BulkActions
|
||||
*/
|
||||
|
||||
import { Trash2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface BulkActionsProps {
|
||||
selectedCount: number;
|
||||
onChangeStatus: () => void;
|
||||
onAssign: () => void;
|
||||
onAddLabels: () => void;
|
||||
onDelete: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function BulkActions({
|
||||
selectedCount,
|
||||
onChangeStatus,
|
||||
onAssign,
|
||||
onAddLabels,
|
||||
onDelete,
|
||||
className,
|
||||
}: BulkActionsProps) {
|
||||
if (selectedCount === 0) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center gap-4 rounded-lg border bg-muted/50 p-3',
|
||||
className
|
||||
)}
|
||||
role="toolbar"
|
||||
aria-label="Bulk actions for selected issues"
|
||||
>
|
||||
<span className="text-sm font-medium">
|
||||
{selectedCount} selected
|
||||
</span>
|
||||
<Separator orientation="vertical" className="h-6" />
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" size="sm" onClick={onChangeStatus}>
|
||||
Change Status
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={onAssign}>
|
||||
Assign
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={onAddLabels}>
|
||||
Add Labels
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="text-destructive hover:text-destructive"
|
||||
onClick={onDelete}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
163
frontend/src/features/issues/components/IssueDetailPanel.tsx
Normal file
163
frontend/src/features/issues/components/IssueDetailPanel.tsx
Normal file
@@ -0,0 +1,163 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* IssueDetailPanel Component
|
||||
*
|
||||
* Side panel showing issue details (assignee, labels, sprint, etc.)
|
||||
*
|
||||
* @module features/issues/components/IssueDetailPanel
|
||||
*/
|
||||
|
||||
import { GitBranch, GitPullRequest, Tag, Bot, User } from 'lucide-react';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { IssueDetail } from '../types';
|
||||
|
||||
interface IssueDetailPanelProps {
|
||||
issue: IssueDetail;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function IssueDetailPanel({ issue, className }: IssueDetailPanelProps) {
|
||||
return (
|
||||
<div className={cn('space-y-6', className)}>
|
||||
{/* Assignment Panel */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">Details</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{/* Assignee */}
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Assignee</p>
|
||||
{issue.assignee ? (
|
||||
<div className="mt-1 flex items-center gap-2">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-primary/10 text-sm font-medium text-primary">
|
||||
{issue.assignee.avatar ||
|
||||
(issue.assignee.type === 'agent' ? (
|
||||
<Bot className="h-4 w-4" aria-hidden="true" />
|
||||
) : (
|
||||
<User className="h-4 w-4" aria-hidden="true" />
|
||||
))}
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium">{issue.assignee.name}</p>
|
||||
<p className="text-xs text-muted-foreground capitalize">
|
||||
{issue.assignee.type}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="mt-1 text-sm text-muted-foreground">Unassigned</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* Reporter */}
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Reporter</p>
|
||||
<div className="mt-1 flex items-center gap-2">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-muted text-sm font-medium">
|
||||
{issue.reporter.avatar ||
|
||||
(issue.reporter.type === 'agent' ? (
|
||||
<Bot className="h-4 w-4" aria-hidden="true" />
|
||||
) : (
|
||||
<User className="h-4 w-4" aria-hidden="true" />
|
||||
))}
|
||||
</div>
|
||||
<p className="font-medium">{issue.reporter.name}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* Sprint */}
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Sprint</p>
|
||||
<p className="font-medium">{issue.sprint || 'Backlog'}</p>
|
||||
</div>
|
||||
|
||||
{/* Story Points */}
|
||||
{issue.story_points !== null && (
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Story Points</p>
|
||||
<p className="font-medium">{issue.story_points}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Due Date */}
|
||||
{issue.due_date && (
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Due Date</p>
|
||||
<p className="font-medium">
|
||||
{new Date(issue.due_date).toLocaleDateString()}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* Labels */}
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Labels</p>
|
||||
<div className="mt-2 flex flex-wrap gap-1">
|
||||
{issue.labels.map((label) => (
|
||||
<Badge
|
||||
key={label.id}
|
||||
variant="secondary"
|
||||
className="text-xs"
|
||||
style={
|
||||
label.color
|
||||
? { backgroundColor: `${label.color}20`, color: label.color }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<Tag className="mr-1 h-3 w-3" aria-hidden="true" />
|
||||
{label.name}
|
||||
</Badge>
|
||||
))}
|
||||
{issue.labels.length === 0 && (
|
||||
<span className="text-sm text-muted-foreground">No labels</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Development */}
|
||||
{(issue.branch || issue.pull_request) && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">Development</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{issue.branch && (
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch
|
||||
className="h-4 w-4 text-muted-foreground"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="font-mono text-sm">{issue.branch}</span>
|
||||
</div>
|
||||
)}
|
||||
{issue.pull_request && (
|
||||
<div className="flex items-center gap-2">
|
||||
<GitPullRequest
|
||||
className="h-4 w-4 text-muted-foreground"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="text-sm">{issue.pull_request}</span>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
Open
|
||||
</Badge>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
205
frontend/src/features/issues/components/IssueFilters.tsx
Normal file
205
frontend/src/features/issues/components/IssueFilters.tsx
Normal file
@@ -0,0 +1,205 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* IssueFilters Component
|
||||
*
|
||||
* Filter controls for the issue list.
|
||||
*
|
||||
* @module features/issues/components/IssueFilters
|
||||
*/
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Search, Filter } from 'lucide-react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { IssueFilters as IssueFiltersType, IssueStatus, IssuePriority } from '../types';
|
||||
import { STATUS_ORDER, PRIORITY_ORDER, STATUS_CONFIG, PRIORITY_CONFIG } from '../constants';
|
||||
import { mockSprints, mockAssignees } from '../mocks';
|
||||
|
||||
interface IssueFiltersProps {
|
||||
filters: IssueFiltersType;
|
||||
onFiltersChange: (filters: IssueFiltersType) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function IssueFilters({ filters, onFiltersChange, className }: IssueFiltersProps) {
|
||||
const [showExtended, setShowExtended] = useState(false);
|
||||
|
||||
const handleSearchChange = (value: string) => {
|
||||
onFiltersChange({ ...filters, search: value || undefined });
|
||||
};
|
||||
|
||||
const handleStatusChange = (value: string) => {
|
||||
onFiltersChange({
|
||||
...filters,
|
||||
status: value as IssueStatus | 'all',
|
||||
});
|
||||
};
|
||||
|
||||
const handlePriorityChange = (value: string) => {
|
||||
onFiltersChange({
|
||||
...filters,
|
||||
priority: value as IssuePriority | 'all',
|
||||
});
|
||||
};
|
||||
|
||||
const handleSprintChange = (value: string) => {
|
||||
onFiltersChange({
|
||||
...filters,
|
||||
sprint: value as string | 'all' | 'backlog',
|
||||
});
|
||||
};
|
||||
|
||||
const handleAssigneeChange = (value: string) => {
|
||||
onFiltersChange({
|
||||
...filters,
|
||||
assignee: value as string | 'all' | 'unassigned',
|
||||
});
|
||||
};
|
||||
|
||||
const handleClearFilters = () => {
|
||||
onFiltersChange({
|
||||
search: undefined,
|
||||
status: 'all',
|
||||
priority: 'all',
|
||||
sprint: 'all',
|
||||
assignee: 'all',
|
||||
labels: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
const hasActiveFilters =
|
||||
filters.search ||
|
||||
(filters.status && filters.status !== 'all') ||
|
||||
(filters.priority && filters.priority !== 'all') ||
|
||||
(filters.sprint && filters.sprint !== 'all') ||
|
||||
(filters.assignee && filters.assignee !== 'all');
|
||||
|
||||
return (
|
||||
<div className={cn('space-y-4', className)}>
|
||||
{/* Search and Quick Filters */}
|
||||
<div className="flex flex-col gap-4 sm:flex-row">
|
||||
<div className="relative flex-1">
|
||||
<Search
|
||||
className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<Input
|
||||
id="issue-search"
|
||||
placeholder="Search issues..."
|
||||
value={filters.search || ''}
|
||||
onChange={(e) => handleSearchChange(e.target.value)}
|
||||
className="pl-9"
|
||||
aria-label="Search issues"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Select value={filters.status || 'all'} onValueChange={handleStatusChange}>
|
||||
<SelectTrigger className="w-32" aria-label="Filter by status">
|
||||
<SelectValue placeholder="Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Status</SelectItem>
|
||||
{STATUS_ORDER.map((status) => (
|
||||
<SelectItem key={status} value={status}>
|
||||
{STATUS_CONFIG[status].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => setShowExtended(!showExtended)}
|
||||
className={cn(showExtended && 'bg-muted')}
|
||||
aria-expanded={showExtended}
|
||||
aria-label="Toggle extended filters"
|
||||
>
|
||||
<Filter className="h-4 w-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Extended Filters */}
|
||||
{showExtended && (
|
||||
<Card className="p-4">
|
||||
<div className="grid gap-4 sm:grid-cols-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="priority-filter">Priority</Label>
|
||||
<Select
|
||||
value={filters.priority || 'all'}
|
||||
onValueChange={handlePriorityChange}
|
||||
>
|
||||
<SelectTrigger id="priority-filter">
|
||||
<SelectValue placeholder="All" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All</SelectItem>
|
||||
{PRIORITY_ORDER.map((priority) => (
|
||||
<SelectItem key={priority} value={priority}>
|
||||
{PRIORITY_CONFIG[priority].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="sprint-filter">Sprint</Label>
|
||||
<Select value={filters.sprint || 'all'} onValueChange={handleSprintChange}>
|
||||
<SelectTrigger id="sprint-filter">
|
||||
<SelectValue placeholder="All" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Sprints</SelectItem>
|
||||
{mockSprints.map((sprint) => (
|
||||
<SelectItem key={sprint} value={sprint}>
|
||||
{sprint}
|
||||
</SelectItem>
|
||||
))}
|
||||
<SelectItem value="backlog">Backlog</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="assignee-filter">Assignee</Label>
|
||||
<Select
|
||||
value={filters.assignee || 'all'}
|
||||
onValueChange={handleAssigneeChange}
|
||||
>
|
||||
<SelectTrigger id="assignee-filter">
|
||||
<SelectValue placeholder="All" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All</SelectItem>
|
||||
<SelectItem value="unassigned">Unassigned</SelectItem>
|
||||
{mockAssignees.map((assignee) => (
|
||||
<SelectItem key={assignee.id} value={assignee.id}>
|
||||
{assignee.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex items-end">
|
||||
{hasActiveFilters && (
|
||||
<Button variant="ghost" size="sm" onClick={handleClearFilters}>
|
||||
Clear Filters
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
265
frontend/src/features/issues/components/IssueTable.tsx
Normal file
265
frontend/src/features/issues/components/IssueTable.tsx
Normal file
@@ -0,0 +1,265 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* IssueTable Component
|
||||
*
|
||||
* Sortable table displaying issues with selection support.
|
||||
*
|
||||
* @module features/issues/components/IssueTable
|
||||
*/
|
||||
|
||||
import { ChevronUp, ChevronDown, MoreVertical, Bot, User, CircleDot } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/components/ui/table';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import type { IssueSummary, IssueSort, IssueSortField, IssueSortDirection } from '../types';
|
||||
|
||||
/**
|
||||
* Convert our sort direction to ARIA sort value
|
||||
*/
|
||||
function toAriaSortValue(
|
||||
field: IssueSortField,
|
||||
currentField: IssueSortField,
|
||||
direction: IssueSortDirection
|
||||
): 'ascending' | 'descending' | 'none' | undefined {
|
||||
if (field !== currentField) return undefined;
|
||||
return direction === 'asc' ? 'ascending' : 'descending';
|
||||
}
|
||||
|
||||
import { StatusBadge } from './StatusBadge';
|
||||
import { PriorityBadge } from './PriorityBadge';
|
||||
import { SyncStatusIndicator } from './SyncStatusIndicator';
|
||||
|
||||
interface IssueTableProps {
|
||||
issues: IssueSummary[];
|
||||
selectedIssues: string[];
|
||||
onSelectionChange: (ids: string[]) => void;
|
||||
onIssueClick: (id: string) => void;
|
||||
sort: IssueSort;
|
||||
onSortChange: (sort: IssueSort) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function IssueTable({
|
||||
issues,
|
||||
selectedIssues,
|
||||
onSelectionChange,
|
||||
onIssueClick,
|
||||
sort,
|
||||
onSortChange,
|
||||
className,
|
||||
}: IssueTableProps) {
|
||||
const handleSelectAll = () => {
|
||||
if (selectedIssues.length === issues.length) {
|
||||
onSelectionChange([]);
|
||||
} else {
|
||||
onSelectionChange(issues.map((i) => i.id));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectIssue = (id: string, e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (selectedIssues.includes(id)) {
|
||||
onSelectionChange(selectedIssues.filter((i) => i !== id));
|
||||
} else {
|
||||
onSelectionChange([...selectedIssues, id]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSort = (field: IssueSortField) => {
|
||||
if (sort.field === field) {
|
||||
onSortChange({
|
||||
field,
|
||||
direction: sort.direction === 'asc' ? 'desc' : 'asc',
|
||||
});
|
||||
} else {
|
||||
onSortChange({ field, direction: 'desc' });
|
||||
}
|
||||
};
|
||||
|
||||
const SortIcon = ({ field }: { field: IssueSortField }) => {
|
||||
if (sort.field !== field) return null;
|
||||
return sort.direction === 'asc' ? (
|
||||
<ChevronUp className="ml-1 inline h-4 w-4" aria-hidden="true" />
|
||||
) : (
|
||||
<ChevronDown className="ml-1 inline h-4 w-4" aria-hidden="true" />
|
||||
);
|
||||
};
|
||||
|
||||
const allSelected = selectedIssues.length === issues.length && issues.length > 0;
|
||||
const someSelected = selectedIssues.length > 0 && !allSelected;
|
||||
|
||||
return (
|
||||
<Card className={className}>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-12">
|
||||
<Checkbox
|
||||
checked={allSelected}
|
||||
ref={(el) => {
|
||||
if (el) {
|
||||
(el as unknown as HTMLInputElement).indeterminate = someSelected;
|
||||
}
|
||||
}}
|
||||
onCheckedChange={handleSelectAll}
|
||||
aria-label={allSelected ? 'Deselect all issues' : 'Select all issues'}
|
||||
/>
|
||||
</TableHead>
|
||||
<TableHead
|
||||
className="w-20 cursor-pointer select-none"
|
||||
onClick={() => handleSort('number')}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-sort={toAriaSortValue('number', sort.field, sort.direction)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleSort('number')}
|
||||
>
|
||||
#
|
||||
<SortIcon field="number" />
|
||||
</TableHead>
|
||||
<TableHead>Title</TableHead>
|
||||
<TableHead className="w-32">Status</TableHead>
|
||||
<TableHead
|
||||
className="w-24 cursor-pointer select-none"
|
||||
onClick={() => handleSort('priority')}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-sort={toAriaSortValue('priority', sort.field, sort.direction)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleSort('priority')}
|
||||
>
|
||||
Priority
|
||||
<SortIcon field="priority" />
|
||||
</TableHead>
|
||||
<TableHead className="w-40">Assignee</TableHead>
|
||||
<TableHead className="w-28">Sprint</TableHead>
|
||||
<TableHead className="w-10">Sync</TableHead>
|
||||
<TableHead className="w-10">
|
||||
<span className="sr-only">Actions</span>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{issues.map((issue) => (
|
||||
<TableRow
|
||||
key={issue.id}
|
||||
className="cursor-pointer"
|
||||
onClick={() => onIssueClick(issue.id)}
|
||||
data-testid={`issue-row-${issue.id}`}
|
||||
>
|
||||
<TableCell onClick={(e) => handleSelectIssue(issue.id, e)}>
|
||||
<Checkbox
|
||||
checked={selectedIssues.includes(issue.id)}
|
||||
onCheckedChange={() => {}}
|
||||
aria-label={`Select issue ${issue.number}`}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-sm text-muted-foreground">
|
||||
{issue.number}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="space-y-1">
|
||||
<p className="font-medium">{issue.title}</p>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{issue.labels.slice(0, 3).map((label) => (
|
||||
<Badge key={label} variant="secondary" className="text-xs">
|
||||
{label}
|
||||
</Badge>
|
||||
))}
|
||||
{issue.labels.length > 3 && (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
+{issue.labels.length - 3}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<StatusBadge status={issue.status} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<PriorityBadge priority={issue.priority} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{issue.assignee ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex h-6 w-6 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">
|
||||
{issue.assignee.type === 'agent' ? (
|
||||
<Bot className="h-3 w-3" aria-hidden="true" />
|
||||
) : (
|
||||
<User className="h-3 w-3" aria-hidden="true" />
|
||||
)}
|
||||
</div>
|
||||
<span className="text-sm">{issue.assignee.name}</span>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">Unassigned</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{issue.sprint ? (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{issue.sprint}
|
||||
</Badge>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">Backlog</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<SyncStatusIndicator status={issue.sync_status} />
|
||||
</TableCell>
|
||||
<TableCell onClick={(e) => e.stopPropagation()}>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
aria-label={`Actions for issue ${issue.number}`}
|
||||
>
|
||||
<MoreVertical className="h-4 w-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => onIssueClick(issue.id)}>
|
||||
View Details
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>Edit</DropdownMenuItem>
|
||||
<DropdownMenuItem>Assign</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem>Sync with Tracker</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-destructive">Delete</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
{issues.length === 0 && (
|
||||
<div className="py-12 text-center">
|
||||
<CircleDot className="mx-auto h-12 w-12 text-muted-foreground" aria-hidden="true" />
|
||||
<h3 className="mt-4 font-semibold">No issues found</h3>
|
||||
<p className="text-muted-foreground">Try adjusting your search or filters</p>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
29
frontend/src/features/issues/components/PriorityBadge.tsx
Normal file
29
frontend/src/features/issues/components/PriorityBadge.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* PriorityBadge Component
|
||||
*
|
||||
* Displays issue priority with appropriate styling.
|
||||
*
|
||||
* @module features/issues/components/PriorityBadge
|
||||
*/
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { IssuePriority } from '../types';
|
||||
import { PRIORITY_CONFIG } from '../constants';
|
||||
|
||||
interface PriorityBadgeProps {
|
||||
priority: IssuePriority;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function PriorityBadge({ priority, className }: PriorityBadgeProps) {
|
||||
const config = PRIORITY_CONFIG[priority] || PRIORITY_CONFIG.medium;
|
||||
|
||||
return (
|
||||
<Badge className={cn(config.color, className)} variant="outline">
|
||||
{config.label}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
51
frontend/src/features/issues/components/StatusBadge.tsx
Normal file
51
frontend/src/features/issues/components/StatusBadge.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* StatusBadge Component
|
||||
*
|
||||
* Displays issue status with appropriate icon and color.
|
||||
*
|
||||
* @module features/issues/components/StatusBadge
|
||||
*/
|
||||
|
||||
import {
|
||||
CircleDot,
|
||||
PlayCircle,
|
||||
Clock,
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
} from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { IssueStatus } from '../types';
|
||||
import { STATUS_CONFIG } from '../constants';
|
||||
|
||||
const STATUS_ICONS = {
|
||||
open: CircleDot,
|
||||
in_progress: PlayCircle,
|
||||
in_review: Clock,
|
||||
blocked: AlertCircle,
|
||||
done: CheckCircle2,
|
||||
closed: XCircle,
|
||||
} as const;
|
||||
|
||||
interface StatusBadgeProps {
|
||||
status: IssueStatus;
|
||||
className?: string;
|
||||
showLabel?: boolean;
|
||||
}
|
||||
|
||||
export function StatusBadge({ status, className, showLabel = true }: StatusBadgeProps) {
|
||||
const config = STATUS_CONFIG[status] || STATUS_CONFIG.open;
|
||||
const Icon = STATUS_ICONS[status] || CircleDot;
|
||||
|
||||
return (
|
||||
<div className={cn('flex items-center gap-1.5', config.color, className)}>
|
||||
<Icon className="h-4 w-4" aria-hidden="true" />
|
||||
{showLabel && (
|
||||
<span className="text-sm font-medium">{config.label}</span>
|
||||
)}
|
||||
<span className="sr-only">{config.label}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
86
frontend/src/features/issues/components/StatusWorkflow.tsx
Normal file
86
frontend/src/features/issues/components/StatusWorkflow.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* StatusWorkflow Component
|
||||
*
|
||||
* Interactive status selector with workflow transitions.
|
||||
*
|
||||
* @module features/issues/components/StatusWorkflow
|
||||
*/
|
||||
|
||||
import {
|
||||
CircleDot,
|
||||
PlayCircle,
|
||||
Clock,
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
} from 'lucide-react';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { IssueStatus } from '../types';
|
||||
import { STATUS_ORDER, STATUS_CONFIG } from '../constants';
|
||||
|
||||
const STATUS_ICONS = {
|
||||
open: CircleDot,
|
||||
in_progress: PlayCircle,
|
||||
in_review: Clock,
|
||||
blocked: AlertCircle,
|
||||
done: CheckCircle2,
|
||||
closed: XCircle,
|
||||
} as const;
|
||||
|
||||
interface StatusWorkflowProps {
|
||||
currentStatus: IssueStatus;
|
||||
onStatusChange: (status: IssueStatus) => void;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function StatusWorkflow({
|
||||
currentStatus,
|
||||
onStatusChange,
|
||||
disabled = false,
|
||||
className,
|
||||
}: StatusWorkflowProps) {
|
||||
return (
|
||||
<Card className={className}>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">Status Workflow</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-2" role="radiogroup" aria-label="Issue status">
|
||||
{STATUS_ORDER.map((status) => {
|
||||
const config = STATUS_CONFIG[status];
|
||||
const Icon = STATUS_ICONS[status];
|
||||
const isActive = currentStatus === status;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={status}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={isActive}
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'flex w-full items-center gap-2 rounded-lg p-2 text-left transition-colors',
|
||||
isActive
|
||||
? 'bg-primary/10 text-primary'
|
||||
: 'hover:bg-muted',
|
||||
disabled && 'cursor-not-allowed opacity-50'
|
||||
)}
|
||||
onClick={() => !disabled && onStatusChange(status)}
|
||||
>
|
||||
<Icon className={cn('h-4 w-4', config.color)} aria-hidden="true" />
|
||||
<span className="text-sm">{config.label}</span>
|
||||
{isActive && (
|
||||
<CheckCircle2 className="ml-auto h-4 w-4" aria-hidden="true" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* SyncStatusIndicator Component
|
||||
*
|
||||
* Displays sync status with external issue trackers.
|
||||
*
|
||||
* @module features/issues/components/SyncStatusIndicator
|
||||
*/
|
||||
|
||||
import { CheckCircle2, RefreshCw, AlertCircle, AlertTriangle } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { SyncStatus } from '../types';
|
||||
import { SYNC_STATUS_CONFIG } from '../constants';
|
||||
|
||||
const SYNC_ICONS = {
|
||||
synced: CheckCircle2,
|
||||
pending: RefreshCw,
|
||||
conflict: AlertTriangle,
|
||||
error: AlertCircle,
|
||||
} as const;
|
||||
|
||||
interface SyncStatusIndicatorProps {
|
||||
status: SyncStatus;
|
||||
className?: string;
|
||||
showLabel?: boolean;
|
||||
}
|
||||
|
||||
export function SyncStatusIndicator({
|
||||
status,
|
||||
className,
|
||||
showLabel = false,
|
||||
}: SyncStatusIndicatorProps) {
|
||||
const config = SYNC_STATUS_CONFIG[status] || SYNC_STATUS_CONFIG.synced;
|
||||
const Icon = SYNC_ICONS[status] || CheckCircle2;
|
||||
const isPending = status === 'pending';
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn('flex items-center gap-1', className)}
|
||||
title={config.label}
|
||||
role="status"
|
||||
aria-label={`Sync status: ${config.label}`}
|
||||
>
|
||||
<Icon
|
||||
className={cn('h-3.5 w-3.5', config.color, isPending && 'animate-spin')}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{showLabel && <span className={cn('text-xs', config.color)}>{config.label}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
15
frontend/src/features/issues/components/index.ts
Normal file
15
frontend/src/features/issues/components/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Issue Management Components
|
||||
*
|
||||
* @module features/issues/components
|
||||
*/
|
||||
|
||||
export { StatusBadge } from './StatusBadge';
|
||||
export { PriorityBadge } from './PriorityBadge';
|
||||
export { SyncStatusIndicator } from './SyncStatusIndicator';
|
||||
export { IssueFilters } from './IssueFilters';
|
||||
export { IssueTable } from './IssueTable';
|
||||
export { BulkActions } from './BulkActions';
|
||||
export { StatusWorkflow } from './StatusWorkflow';
|
||||
export { ActivityTimeline } from './ActivityTimeline';
|
||||
export { IssueDetailPanel } from './IssueDetailPanel';
|
||||
106
frontend/src/features/issues/constants.ts
Normal file
106
frontend/src/features/issues/constants.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Issue Management Constants
|
||||
*
|
||||
* Configuration for status, priority, and workflow.
|
||||
*
|
||||
* @module features/issues/constants
|
||||
*/
|
||||
|
||||
import type {
|
||||
IssueStatus,
|
||||
IssuePriority,
|
||||
StatusConfig,
|
||||
PriorityConfig,
|
||||
StatusTransition,
|
||||
} from './types';
|
||||
|
||||
/**
|
||||
* Status configuration with labels and colors
|
||||
*/
|
||||
export const STATUS_CONFIG: Record<IssueStatus, StatusConfig> = {
|
||||
open: { label: 'Open', color: 'text-blue-500' },
|
||||
in_progress: { label: 'In Progress', color: 'text-yellow-500' },
|
||||
in_review: { label: 'In Review', color: 'text-purple-500' },
|
||||
blocked: { label: 'Blocked', color: 'text-red-500' },
|
||||
done: { label: 'Done', color: 'text-green-500' },
|
||||
closed: { label: 'Closed', color: 'text-muted-foreground' },
|
||||
};
|
||||
|
||||
/**
|
||||
* Priority configuration with labels and colors
|
||||
*/
|
||||
export const PRIORITY_CONFIG: Record<IssuePriority, PriorityConfig> = {
|
||||
high: { label: 'High', color: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200' },
|
||||
medium: {
|
||||
label: 'Medium',
|
||||
color: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200',
|
||||
},
|
||||
low: { label: 'Low', color: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200' },
|
||||
};
|
||||
|
||||
/**
|
||||
* Status workflow transitions
|
||||
* Defines which status transitions are available from each status
|
||||
*/
|
||||
export const STATUS_TRANSITIONS: StatusTransition[] = [
|
||||
{ from: 'open', to: 'in_progress', label: 'Start Work' },
|
||||
{ from: 'in_progress', to: 'in_review', label: 'Submit for Review' },
|
||||
{ from: 'in_progress', to: 'blocked', label: 'Mark Blocked' },
|
||||
{ from: 'in_review', to: 'done', label: 'Mark Done' },
|
||||
{ from: 'in_review', to: 'in_progress', label: 'Request Changes' },
|
||||
{ from: 'blocked', to: 'in_progress', label: 'Unblock' },
|
||||
{ from: 'done', to: 'closed', label: 'Close Issue' },
|
||||
{ from: 'closed', to: 'open', label: 'Reopen' },
|
||||
];
|
||||
|
||||
/**
|
||||
* Get available transitions for a given status
|
||||
*/
|
||||
export function getAvailableTransitions(currentStatus: IssueStatus): StatusTransition[] {
|
||||
return STATUS_TRANSITIONS.filter((t) => t.from === currentStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get primary transition for a given status (the main workflow action)
|
||||
*/
|
||||
export function getPrimaryTransition(currentStatus: IssueStatus): StatusTransition | undefined {
|
||||
const transitions = getAvailableTransitions(currentStatus);
|
||||
return transitions[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* All possible statuses in workflow order
|
||||
*/
|
||||
export const STATUS_ORDER: IssueStatus[] = [
|
||||
'open',
|
||||
'in_progress',
|
||||
'in_review',
|
||||
'blocked',
|
||||
'done',
|
||||
'closed',
|
||||
];
|
||||
|
||||
/**
|
||||
* All possible priorities in order
|
||||
*/
|
||||
export const PRIORITY_ORDER: IssuePriority[] = ['high', 'medium', 'low'];
|
||||
|
||||
/**
|
||||
* Sync status configuration
|
||||
*/
|
||||
export const SYNC_STATUS_CONFIG = {
|
||||
synced: { label: 'Synced', color: 'text-green-500' },
|
||||
pending: { label: 'Syncing', color: 'text-yellow-500' },
|
||||
conflict: { label: 'Conflict', color: 'text-orange-500' },
|
||||
error: { label: 'Sync Error', color: 'text-red-500' },
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Default page size for issue list
|
||||
*/
|
||||
export const DEFAULT_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
* Maximum issues for bulk actions
|
||||
*/
|
||||
export const MAX_BULK_SELECTION = 100;
|
||||
15
frontend/src/features/issues/hooks/index.ts
Normal file
15
frontend/src/features/issues/hooks/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Issue Management Hooks
|
||||
*
|
||||
* @module features/issues/hooks
|
||||
*/
|
||||
|
||||
export {
|
||||
useIssues,
|
||||
useIssue,
|
||||
useUpdateIssue,
|
||||
useUpdateIssueStatus,
|
||||
useBulkIssueAction,
|
||||
useSyncIssue,
|
||||
issueKeys,
|
||||
} from './useIssues';
|
||||
332
frontend/src/features/issues/hooks/useIssues.ts
Normal file
332
frontend/src/features/issues/hooks/useIssues.ts
Normal file
@@ -0,0 +1,332 @@
|
||||
/**
|
||||
* Issue Management React Query Hooks
|
||||
*
|
||||
* Hooks for fetching and mutating issues.
|
||||
* Uses TanStack Query for server state management.
|
||||
*
|
||||
* Note: Until backend API is implemented, these hooks use mock data.
|
||||
* The API integration points are marked for future implementation.
|
||||
*
|
||||
* @module features/issues/hooks/useIssues
|
||||
*/
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import type {
|
||||
IssueSummary,
|
||||
IssueDetail,
|
||||
IssueFilters,
|
||||
IssueSort,
|
||||
IssueUpdateRequest,
|
||||
IssueBulkActionRequest,
|
||||
PaginatedIssuesResponse,
|
||||
} from '../types';
|
||||
import { mockIssues, mockIssueDetail } from '../mocks';
|
||||
|
||||
/**
|
||||
* Query keys for issues
|
||||
*/
|
||||
export const issueKeys = {
|
||||
all: ['issues'] as const,
|
||||
lists: () => [...issueKeys.all, 'list'] as const,
|
||||
list: (projectId: string, filters?: IssueFilters, sort?: IssueSort) =>
|
||||
[...issueKeys.lists(), projectId, filters, sort] as const,
|
||||
details: () => [...issueKeys.all, 'detail'] as const,
|
||||
detail: (issueId: string) => [...issueKeys.details(), issueId] as const,
|
||||
};
|
||||
|
||||
/**
|
||||
* Mock filtering and sorting logic
|
||||
* This simulates server-side filtering until API is ready
|
||||
*/
|
||||
function filterAndSortIssues(
|
||||
issues: IssueSummary[],
|
||||
filters?: IssueFilters,
|
||||
sort?: IssueSort
|
||||
): IssueSummary[] {
|
||||
let result = [...issues];
|
||||
|
||||
if (filters) {
|
||||
// Search filter
|
||||
if (filters.search) {
|
||||
const searchLower = filters.search.toLowerCase();
|
||||
result = result.filter(
|
||||
(issue) =>
|
||||
issue.title.toLowerCase().includes(searchLower) ||
|
||||
issue.description.toLowerCase().includes(searchLower) ||
|
||||
issue.number.toString().includes(searchLower)
|
||||
);
|
||||
}
|
||||
|
||||
// Status filter
|
||||
if (filters.status && filters.status !== 'all') {
|
||||
result = result.filter((issue) => issue.status === filters.status);
|
||||
}
|
||||
|
||||
// Priority filter
|
||||
if (filters.priority && filters.priority !== 'all') {
|
||||
result = result.filter((issue) => issue.priority === filters.priority);
|
||||
}
|
||||
|
||||
// Sprint filter
|
||||
if (filters.sprint && filters.sprint !== 'all') {
|
||||
if (filters.sprint === 'backlog') {
|
||||
result = result.filter((issue) => !issue.sprint);
|
||||
} else {
|
||||
result = result.filter((issue) => issue.sprint === filters.sprint);
|
||||
}
|
||||
}
|
||||
|
||||
// Assignee filter
|
||||
if (filters.assignee && filters.assignee !== 'all') {
|
||||
if (filters.assignee === 'unassigned') {
|
||||
result = result.filter((issue) => !issue.assignee);
|
||||
} else {
|
||||
result = result.filter((issue) => issue.assignee?.id === filters.assignee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sorting
|
||||
if (sort) {
|
||||
const direction = sort.direction === 'asc' ? 1 : -1;
|
||||
result.sort((a, b) => {
|
||||
switch (sort.field) {
|
||||
case 'number':
|
||||
return (a.number - b.number) * direction;
|
||||
case 'priority': {
|
||||
const priorityOrder = { high: 3, medium: 2, low: 1 };
|
||||
return (priorityOrder[a.priority] - priorityOrder[b.priority]) * direction;
|
||||
}
|
||||
case 'updated_at':
|
||||
return (new Date(a.updated_at).getTime() - new Date(b.updated_at).getTime()) * direction;
|
||||
case 'created_at':
|
||||
return (new Date(a.created_at).getTime() - new Date(b.created_at).getTime()) * direction;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch paginated issues for a project
|
||||
*
|
||||
* @param projectId - Project ID
|
||||
* @param filters - Optional filters
|
||||
* @param sort - Optional sort configuration
|
||||
* @param page - Page number (1-based)
|
||||
* @param pageSize - Number of items per page
|
||||
*/
|
||||
export function useIssues(
|
||||
projectId: string,
|
||||
filters?: IssueFilters,
|
||||
sort?: IssueSort,
|
||||
page: number = 1,
|
||||
pageSize: number = 25
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: issueKeys.list(projectId, filters, sort),
|
||||
queryFn: async (): Promise<PaginatedIssuesResponse> => {
|
||||
// TODO: Replace with actual API call when backend is ready
|
||||
// const response = await getProjectIssues({
|
||||
// path: { project_id: projectId },
|
||||
// query: { ...filters, ...sort, page, page_size: pageSize },
|
||||
// });
|
||||
|
||||
// Simulate API delay
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
const filteredIssues = filterAndSortIssues(mockIssues, filters, sort);
|
||||
const start = (page - 1) * pageSize;
|
||||
const paginatedIssues = filteredIssues.slice(start, start + pageSize);
|
||||
|
||||
return {
|
||||
data: paginatedIssues,
|
||||
pagination: {
|
||||
total: filteredIssues.length,
|
||||
page,
|
||||
page_size: pageSize,
|
||||
total_pages: Math.ceil(filteredIssues.length / pageSize),
|
||||
has_next: start + pageSize < filteredIssues.length,
|
||||
has_prev: page > 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
staleTime: 30000, // 30 seconds
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch a single issue detail
|
||||
*
|
||||
* @param issueId - Issue ID
|
||||
*/
|
||||
export function useIssue(issueId: string) {
|
||||
return useQuery({
|
||||
queryKey: issueKeys.detail(issueId),
|
||||
queryFn: async (): Promise<IssueDetail> => {
|
||||
// TODO: Replace with actual API call when backend is ready
|
||||
// const response = await getIssue({
|
||||
// path: { issue_id: issueId },
|
||||
// });
|
||||
|
||||
// Simulate API delay
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
// Return mock detail for any issue ID
|
||||
return {
|
||||
...mockIssueDetail,
|
||||
id: issueId,
|
||||
};
|
||||
},
|
||||
staleTime: 30000,
|
||||
enabled: !!issueId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to update an issue
|
||||
*/
|
||||
export function useUpdateIssue() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
issueId,
|
||||
data,
|
||||
}: {
|
||||
issueId: string;
|
||||
data: IssueUpdateRequest;
|
||||
}): Promise<IssueDetail> => {
|
||||
// TODO: Replace with actual API call when backend is ready
|
||||
// const response = await updateIssue({
|
||||
// path: { issue_id: issueId },
|
||||
// body: data,
|
||||
// });
|
||||
|
||||
// Simulate API delay
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
// Return updated mock data - only apply non-label fields from data
|
||||
return {
|
||||
...mockIssueDetail,
|
||||
id: issueId,
|
||||
title: data.title || mockIssueDetail.title,
|
||||
description: data.description || mockIssueDetail.description,
|
||||
status: data.status || mockIssueDetail.status,
|
||||
priority: data.priority || mockIssueDetail.priority,
|
||||
sprint: data.sprint !== undefined ? data.sprint : mockIssueDetail.sprint,
|
||||
due_date: data.due_date !== undefined ? data.due_date : mockIssueDetail.due_date,
|
||||
};
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
// Invalidate and update cache
|
||||
queryClient.invalidateQueries({ queryKey: issueKeys.lists() });
|
||||
queryClient.setQueryData(issueKeys.detail(data.id), data);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to update issue status (optimistic update)
|
||||
*/
|
||||
export function useUpdateIssueStatus() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
issueId,
|
||||
status,
|
||||
}: {
|
||||
issueId: string;
|
||||
status: IssueUpdateRequest['status'];
|
||||
}): Promise<IssueDetail> => {
|
||||
// TODO: Replace with actual API call
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
return {
|
||||
...mockIssueDetail,
|
||||
id: issueId,
|
||||
status: status || mockIssueDetail.status,
|
||||
};
|
||||
},
|
||||
onMutate: async ({ issueId, status }) => {
|
||||
// Cancel outgoing refetches
|
||||
await queryClient.cancelQueries({ queryKey: issueKeys.detail(issueId) });
|
||||
|
||||
// Snapshot previous value
|
||||
const previousIssue = queryClient.getQueryData<IssueDetail>(issueKeys.detail(issueId));
|
||||
|
||||
// Optimistically update
|
||||
if (previousIssue && status) {
|
||||
queryClient.setQueryData(issueKeys.detail(issueId), {
|
||||
...previousIssue,
|
||||
status,
|
||||
});
|
||||
}
|
||||
|
||||
return { previousIssue };
|
||||
},
|
||||
onError: (_err, { issueId }, context) => {
|
||||
// Rollback on error
|
||||
if (context?.previousIssue) {
|
||||
queryClient.setQueryData(issueKeys.detail(issueId), context.previousIssue);
|
||||
}
|
||||
},
|
||||
onSettled: () => {
|
||||
// Invalidate lists to refetch
|
||||
queryClient.invalidateQueries({ queryKey: issueKeys.lists() });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for bulk actions on issues
|
||||
*/
|
||||
export function useBulkIssueAction() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (request: IssueBulkActionRequest): Promise<{ affected_count: number }> => {
|
||||
// TODO: Replace with actual API call
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
return { affected_count: request.issue_ids.length };
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Invalidate all issue queries
|
||||
queryClient.invalidateQueries({ queryKey: issueKeys.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to sync an issue with external tracker
|
||||
*/
|
||||
export function useSyncIssue() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ issueId }: { issueId: string }): Promise<IssueSummary> => {
|
||||
// TODO: Replace with actual API call
|
||||
// const response = await syncIssue({
|
||||
// path: { issue_id: issueId },
|
||||
// body: { direction: 'bidirectional' },
|
||||
// });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
const issue = mockIssues.find((i) => i.id === issueId);
|
||||
return {
|
||||
...(issue || mockIssues[0]),
|
||||
sync_status: 'synced',
|
||||
};
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({ queryKey: issueKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: issueKeys.detail(data.id) });
|
||||
},
|
||||
});
|
||||
}
|
||||
70
frontend/src/features/issues/index.ts
Normal file
70
frontend/src/features/issues/index.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Issue Management Feature
|
||||
*
|
||||
* Complete issue tracking and management for Syndarix projects.
|
||||
*
|
||||
* @module features/issues
|
||||
*/
|
||||
|
||||
// Components
|
||||
export {
|
||||
StatusBadge,
|
||||
PriorityBadge,
|
||||
SyncStatusIndicator,
|
||||
IssueFilters,
|
||||
IssueTable,
|
||||
BulkActions,
|
||||
StatusWorkflow,
|
||||
ActivityTimeline,
|
||||
IssueDetailPanel,
|
||||
} from './components';
|
||||
|
||||
// Hooks
|
||||
export {
|
||||
useIssues,
|
||||
useIssue,
|
||||
useUpdateIssue,
|
||||
useUpdateIssueStatus,
|
||||
useBulkIssueAction,
|
||||
useSyncIssue,
|
||||
issueKeys,
|
||||
} from './hooks';
|
||||
|
||||
// Types - use explicit names to avoid collision with component IssueFilters
|
||||
export type {
|
||||
IssueStatus,
|
||||
IssuePriority,
|
||||
SyncStatus,
|
||||
ActorType,
|
||||
IssueAssignee,
|
||||
IssueLabel,
|
||||
IssueActivity,
|
||||
IssueSummary,
|
||||
IssueDetail,
|
||||
IssueFilters as IssueFiltersType,
|
||||
IssueSortField,
|
||||
IssueSortDirection,
|
||||
IssueSort,
|
||||
IssueBulkAction,
|
||||
IssueBulkActionRequest,
|
||||
IssueUpdateRequest,
|
||||
IssueSyncRequest,
|
||||
StatusTransition,
|
||||
StatusConfig,
|
||||
PriorityConfig,
|
||||
PaginatedIssuesResponse,
|
||||
} from './types';
|
||||
|
||||
// Constants
|
||||
export {
|
||||
STATUS_CONFIG,
|
||||
PRIORITY_CONFIG,
|
||||
STATUS_TRANSITIONS,
|
||||
getAvailableTransitions,
|
||||
getPrimaryTransition,
|
||||
STATUS_ORDER,
|
||||
PRIORITY_ORDER,
|
||||
SYNC_STATUS_CONFIG,
|
||||
DEFAULT_PAGE_SIZE,
|
||||
MAX_BULK_SELECTION,
|
||||
} from './constants';
|
||||
252
frontend/src/features/issues/mocks.ts
Normal file
252
frontend/src/features/issues/mocks.ts
Normal file
@@ -0,0 +1,252 @@
|
||||
/**
|
||||
* Issue Management Mock Data
|
||||
*
|
||||
* Mock data for development and testing.
|
||||
* This will be removed once the backend API is implemented.
|
||||
*
|
||||
* @module features/issues/mocks
|
||||
*/
|
||||
|
||||
import type { IssueSummary, IssueDetail } from './types';
|
||||
|
||||
/**
|
||||
* Mock issues for list view
|
||||
*/
|
||||
export const mockIssues: IssueSummary[] = [
|
||||
{
|
||||
id: 'ISS-001',
|
||||
number: 42,
|
||||
title: 'Implement user authentication flow',
|
||||
description:
|
||||
'Create complete authentication flow with login, register, and password reset.',
|
||||
status: 'in_progress',
|
||||
priority: 'high',
|
||||
labels: ['feature', 'auth', 'backend'],
|
||||
sprint: 'Sprint 3',
|
||||
assignee: { id: 'agent-be', name: 'Backend Engineer', type: 'agent' },
|
||||
created_at: '2025-01-15T10:30:00Z',
|
||||
updated_at: '2025-01-20T14:22:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
{
|
||||
id: 'ISS-002',
|
||||
number: 43,
|
||||
title: 'Design product catalog component',
|
||||
description: 'Create reusable product card and catalog grid components.',
|
||||
status: 'in_review',
|
||||
priority: 'medium',
|
||||
labels: ['feature', 'frontend', 'ui'],
|
||||
sprint: 'Sprint 3',
|
||||
assignee: { id: 'agent-fe', name: 'Frontend Engineer', type: 'agent' },
|
||||
created_at: '2025-01-16T09:00:00Z',
|
||||
updated_at: '2025-01-20T15:30:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
{
|
||||
id: 'ISS-003',
|
||||
number: 44,
|
||||
title: 'Fix cart total calculation bug',
|
||||
description: 'Cart total shows incorrect amount when discount is applied.',
|
||||
status: 'blocked',
|
||||
priority: 'high',
|
||||
labels: ['bug', 'critical', 'backend'],
|
||||
sprint: 'Sprint 3',
|
||||
assignee: { id: 'agent-be', name: 'Backend Engineer', type: 'agent' },
|
||||
created_at: '2025-01-17T11:00:00Z',
|
||||
updated_at: '2025-01-20T13:00:00Z',
|
||||
sync_status: 'pending',
|
||||
blocked_by: 'Waiting for discount API specification',
|
||||
},
|
||||
{
|
||||
id: 'ISS-004',
|
||||
number: 45,
|
||||
title: 'Add product search functionality',
|
||||
description: 'Implement full-text search with filters for the product catalog.',
|
||||
status: 'open',
|
||||
priority: 'medium',
|
||||
labels: ['feature', 'search', 'backend'],
|
||||
sprint: 'Sprint 3',
|
||||
assignee: null,
|
||||
created_at: '2025-01-18T14:00:00Z',
|
||||
updated_at: '2025-01-18T14:00:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
{
|
||||
id: 'ISS-005',
|
||||
number: 46,
|
||||
title: 'Optimize database queries for product listing',
|
||||
description: 'Performance optimization for product queries with pagination.',
|
||||
status: 'done',
|
||||
priority: 'low',
|
||||
labels: ['performance', 'backend', 'database'],
|
||||
sprint: 'Sprint 2',
|
||||
assignee: { id: 'agent-be', name: 'Backend Engineer', type: 'agent' },
|
||||
created_at: '2025-01-10T09:00:00Z',
|
||||
updated_at: '2025-01-18T10:00:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
{
|
||||
id: 'ISS-006',
|
||||
number: 47,
|
||||
title: 'Create checkout page wireframes',
|
||||
description: 'Design wireframes for the checkout flow including payment selection.',
|
||||
status: 'done',
|
||||
priority: 'high',
|
||||
labels: ['design', 'checkout', 'ui'],
|
||||
sprint: 'Sprint 2',
|
||||
assignee: { id: 'agent-po', name: 'Product Owner', type: 'agent' },
|
||||
created_at: '2025-01-08T08:00:00Z',
|
||||
updated_at: '2025-01-15T16:00:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
{
|
||||
id: 'ISS-007',
|
||||
number: 48,
|
||||
title: 'Implement responsive navigation',
|
||||
description: 'Create mobile-friendly navigation with hamburger menu.',
|
||||
status: 'open',
|
||||
priority: 'medium',
|
||||
labels: ['feature', 'frontend', 'responsive'],
|
||||
sprint: null,
|
||||
assignee: null,
|
||||
created_at: '2025-01-19T10:00:00Z',
|
||||
updated_at: '2025-01-19T10:00:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
{
|
||||
id: 'ISS-008',
|
||||
number: 49,
|
||||
title: 'Set up E2E test framework',
|
||||
description: 'Configure Playwright for end-to-end testing.',
|
||||
status: 'in_progress',
|
||||
priority: 'medium',
|
||||
labels: ['testing', 'infrastructure'],
|
||||
sprint: 'Sprint 3',
|
||||
assignee: { id: 'agent-qa', name: 'QA Engineer', type: 'agent' },
|
||||
created_at: '2025-01-20T08:00:00Z',
|
||||
updated_at: '2025-01-20T12:00:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Mock issue detail for detail view
|
||||
*/
|
||||
export const mockIssueDetail: IssueDetail = {
|
||||
id: 'ISS-001',
|
||||
number: 42,
|
||||
title: 'Implement user authentication flow',
|
||||
description: `## Overview
|
||||
Create a complete authentication flow for the e-commerce platform.
|
||||
|
||||
## Requirements
|
||||
- Login with email/password
|
||||
- Registration with email verification
|
||||
- Password reset functionality
|
||||
- OAuth support (Google, GitHub)
|
||||
- JWT token management
|
||||
- Session handling
|
||||
|
||||
## Acceptance Criteria
|
||||
- [ ] Users can register with email and password
|
||||
- [ ] Users receive email verification link
|
||||
- [ ] Users can log in with verified email
|
||||
- [ ] Password reset email is sent within 30 seconds
|
||||
- [ ] OAuth buttons redirect properly
|
||||
- [x] JWT tokens are stored securely
|
||||
- [x] Tokens refresh automatically
|
||||
|
||||
## Technical Notes
|
||||
- Use FastAPI security utilities
|
||||
- Store sessions in Redis
|
||||
- Follow OWASP guidelines`,
|
||||
status: 'in_progress',
|
||||
priority: 'high',
|
||||
labels: [
|
||||
{ id: 'lbl-1', name: 'feature', color: '#3b82f6' },
|
||||
{ id: 'lbl-2', name: 'auth', color: '#8b5cf6' },
|
||||
{ id: 'lbl-3', name: 'backend', color: '#10b981' },
|
||||
{ id: 'lbl-4', name: 'security', color: '#ef4444' },
|
||||
],
|
||||
sprint: 'Sprint 3',
|
||||
milestone: 'MVP Launch',
|
||||
story_points: 8,
|
||||
assignee: { id: 'agent-be', name: 'Backend Engineer', type: 'agent', avatar: 'BE' },
|
||||
reporter: { id: 'agent-po', name: 'Product Owner', type: 'agent', avatar: 'PO' },
|
||||
created_at: '2025-01-15T10:30:00Z',
|
||||
updated_at: '2025-01-20T14:22:00Z',
|
||||
due_date: '2025-02-01',
|
||||
sync_status: 'synced',
|
||||
external_url: 'https://gitea.example.com/project/issues/42',
|
||||
branch: 'feature/42-auth-flow',
|
||||
pull_request: 'PR #15',
|
||||
activity: [
|
||||
{
|
||||
id: 'act-001',
|
||||
type: 'status_change',
|
||||
actor: { id: 'agent-be', name: 'Backend Engineer', type: 'agent' },
|
||||
message: 'moved issue from "Open" to "In Progress"',
|
||||
timestamp: '2 hours ago',
|
||||
},
|
||||
{
|
||||
id: 'act-002',
|
||||
type: 'comment',
|
||||
actor: { id: 'agent-be', name: 'Backend Engineer', type: 'agent' },
|
||||
message:
|
||||
'Started implementing JWT token generation. Using HS256 algorithm as discussed in architecture meeting.',
|
||||
timestamp: '3 hours ago',
|
||||
},
|
||||
{
|
||||
id: 'act-003',
|
||||
type: 'assignment',
|
||||
actor: { id: 'agent-po', name: 'Product Owner', type: 'agent' },
|
||||
message: 'assigned this issue to Backend Engineer',
|
||||
timestamp: '1 day ago',
|
||||
},
|
||||
{
|
||||
id: 'act-004',
|
||||
type: 'label',
|
||||
actor: { id: 'agent-po', name: 'Product Owner', type: 'agent' },
|
||||
message: 'added labels: security, backend',
|
||||
timestamp: '1 day ago',
|
||||
},
|
||||
{
|
||||
id: 'act-005',
|
||||
type: 'created',
|
||||
actor: { id: 'agent-po', name: 'Product Owner', type: 'agent' },
|
||||
message: 'created this issue',
|
||||
timestamp: '5 days ago',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* Mock sprints for filter options
|
||||
*/
|
||||
export const mockSprints = ['Sprint 3', 'Sprint 2', 'Sprint 1'];
|
||||
|
||||
/**
|
||||
* Mock assignees for filter options
|
||||
*/
|
||||
export const mockAssignees = [
|
||||
{ id: 'agent-be', name: 'Backend Engineer', type: 'agent' as const },
|
||||
{ id: 'agent-fe', name: 'Frontend Engineer', type: 'agent' as const },
|
||||
{ id: 'agent-qa', name: 'QA Engineer', type: 'agent' as const },
|
||||
{ id: 'agent-po', name: 'Product Owner', type: 'agent' as const },
|
||||
];
|
||||
|
||||
/**
|
||||
* Mock labels for filter options
|
||||
*/
|
||||
export const mockLabels = [
|
||||
'feature',
|
||||
'bug',
|
||||
'backend',
|
||||
'frontend',
|
||||
'ui',
|
||||
'auth',
|
||||
'testing',
|
||||
'performance',
|
||||
'design',
|
||||
'infrastructure',
|
||||
];
|
||||
192
frontend/src/features/issues/types/index.ts
Normal file
192
frontend/src/features/issues/types/index.ts
Normal file
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* Issue Management Types
|
||||
*
|
||||
* Type definitions for the issue tracking feature.
|
||||
* These types align with the backend API schema for issues.
|
||||
*
|
||||
* @module features/issues/types
|
||||
*/
|
||||
|
||||
/**
|
||||
* Issue status values
|
||||
*/
|
||||
export type IssueStatus = 'open' | 'in_progress' | 'in_review' | 'blocked' | 'done' | 'closed';
|
||||
|
||||
/**
|
||||
* Issue priority values
|
||||
*/
|
||||
export type IssuePriority = 'high' | 'medium' | 'low';
|
||||
|
||||
/**
|
||||
* Sync status with external trackers
|
||||
*/
|
||||
export type SyncStatus = 'synced' | 'pending' | 'conflict' | 'error';
|
||||
|
||||
/**
|
||||
* Actor type for issue activity
|
||||
*/
|
||||
export type ActorType = 'agent' | 'human';
|
||||
|
||||
/**
|
||||
* Issue assignee
|
||||
*/
|
||||
export interface IssueAssignee {
|
||||
id: string;
|
||||
name: string;
|
||||
type: ActorType;
|
||||
avatar?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue label
|
||||
*/
|
||||
export interface IssueLabel {
|
||||
id: string;
|
||||
name: string;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue activity item
|
||||
*/
|
||||
export interface IssueActivity {
|
||||
id: string;
|
||||
type: 'status_change' | 'comment' | 'assignment' | 'label' | 'created' | 'branch' | 'pr';
|
||||
actor: IssueAssignee;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue summary for list views
|
||||
*/
|
||||
export interface IssueSummary {
|
||||
id: string;
|
||||
number: number;
|
||||
title: string;
|
||||
description: string;
|
||||
status: IssueStatus;
|
||||
priority: IssuePriority;
|
||||
labels: string[];
|
||||
sprint: string | null;
|
||||
assignee: IssueAssignee | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
sync_status: SyncStatus;
|
||||
blocked_by?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full issue detail
|
||||
*/
|
||||
export interface IssueDetail extends Omit<IssueSummary, 'labels'> {
|
||||
labels: IssueLabel[];
|
||||
milestone: string | null;
|
||||
story_points: number | null;
|
||||
reporter: IssueAssignee;
|
||||
due_date: string | null;
|
||||
external_url: string | null;
|
||||
branch: string | null;
|
||||
pull_request: string | null;
|
||||
activity: IssueActivity[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue filters
|
||||
*/
|
||||
export interface IssueFilters {
|
||||
search?: string;
|
||||
status?: IssueStatus | 'all';
|
||||
priority?: IssuePriority | 'all';
|
||||
sprint?: string | 'all' | 'backlog';
|
||||
assignee?: string | 'all' | 'unassigned';
|
||||
labels?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue sort options
|
||||
*/
|
||||
export type IssueSortField = 'number' | 'priority' | 'updated_at' | 'created_at' | 'status';
|
||||
export type IssueSortDirection = 'asc' | 'desc';
|
||||
|
||||
export interface IssueSort {
|
||||
field: IssueSortField;
|
||||
direction: IssueSortDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk action types
|
||||
*/
|
||||
export type IssueBulkAction = 'change_status' | 'assign' | 'add_labels' | 'delete';
|
||||
|
||||
export interface IssueBulkActionRequest {
|
||||
action: IssueBulkAction;
|
||||
issue_ids: string[];
|
||||
payload?: {
|
||||
status?: IssueStatus;
|
||||
assignee_id?: string;
|
||||
labels?: string[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue update request
|
||||
*/
|
||||
export interface IssueUpdateRequest {
|
||||
title?: string;
|
||||
description?: string;
|
||||
status?: IssueStatus;
|
||||
priority?: IssuePriority;
|
||||
assignee_id?: string | null;
|
||||
labels?: string[];
|
||||
sprint?: string | null;
|
||||
due_date?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue sync request
|
||||
*/
|
||||
export interface IssueSyncRequest {
|
||||
direction?: 'push' | 'pull' | 'bidirectional';
|
||||
}
|
||||
|
||||
/**
|
||||
* Status workflow transition
|
||||
*/
|
||||
export interface StatusTransition {
|
||||
from: IssueStatus;
|
||||
to: IssueStatus;
|
||||
label: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status configuration
|
||||
*/
|
||||
export interface StatusConfig {
|
||||
label: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Priority configuration
|
||||
*/
|
||||
export interface PriorityConfig {
|
||||
label: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginated issues response
|
||||
*/
|
||||
export interface PaginatedIssuesResponse {
|
||||
data: IssueSummary[];
|
||||
pagination: {
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
total_pages: number;
|
||||
has_next: boolean;
|
||||
has_prev: boolean;
|
||||
};
|
||||
}
|
||||
@@ -3,3 +3,6 @@
|
||||
|
||||
// Authentication hooks
|
||||
export * from './useAuth';
|
||||
|
||||
// Agent Types hooks
|
||||
export * from './useAgentTypes';
|
||||
|
||||
220
frontend/src/lib/api/hooks/useAgentTypes.ts
Normal file
220
frontend/src/lib/api/hooks/useAgentTypes.ts
Normal file
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* Agent Types Hooks
|
||||
*
|
||||
* TanStack Query hooks for managing agent type operations.
|
||||
* Provides data fetching and mutations for the agent-types API.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { apiClient } from '@/lib/api/client';
|
||||
import { useAuth } from '@/lib/auth/AuthContext';
|
||||
import type {
|
||||
AgentTypeCreate,
|
||||
AgentTypeUpdate,
|
||||
AgentTypeResponse,
|
||||
AgentTypeListResponse,
|
||||
AgentTypeListParams,
|
||||
} from '@/lib/api/types/agentTypes';
|
||||
|
||||
/**
|
||||
* Query keys for agent types
|
||||
*/
|
||||
export const agentTypeKeys = {
|
||||
all: ['agent-types'] as const,
|
||||
lists: () => [...agentTypeKeys.all, 'list'] as const,
|
||||
list: (params: AgentTypeListParams) => [...agentTypeKeys.lists(), params] as const,
|
||||
details: () => [...agentTypeKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...agentTypeKeys.details(), id] as const,
|
||||
bySlug: (slug: string) => [...agentTypeKeys.all, 'slug', slug] as const,
|
||||
};
|
||||
|
||||
/**
|
||||
* Default page limit for listing agent types
|
||||
*/
|
||||
const DEFAULT_PAGE_LIMIT = 20;
|
||||
|
||||
/**
|
||||
* Hook to fetch paginated list of agent types
|
||||
*
|
||||
* @param params - Query parameters for filtering and pagination
|
||||
* @returns Query result with agent types list
|
||||
*/
|
||||
export function useAgentTypes(params: AgentTypeListParams = {}) {
|
||||
const { user } = useAuth();
|
||||
|
||||
const {
|
||||
page = 1,
|
||||
limit = DEFAULT_PAGE_LIMIT,
|
||||
is_active = true,
|
||||
search,
|
||||
} = params;
|
||||
|
||||
return useQuery({
|
||||
queryKey: agentTypeKeys.list({ page, limit, is_active, search }),
|
||||
queryFn: async (): Promise<AgentTypeListResponse> => {
|
||||
const response = await apiClient.instance.get('/api/v1/agent-types', {
|
||||
params: {
|
||||
page,
|
||||
limit,
|
||||
is_active,
|
||||
...(search ? { search } : {}),
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!user,
|
||||
staleTime: 30000, // 30 seconds
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch a single agent type by ID
|
||||
*
|
||||
* @param id - Agent type UUID
|
||||
* @returns Query result with agent type details
|
||||
*/
|
||||
export function useAgentType(id: string | null) {
|
||||
const { user } = useAuth();
|
||||
|
||||
return useQuery({
|
||||
queryKey: agentTypeKeys.detail(id ?? ''),
|
||||
queryFn: async (): Promise<AgentTypeResponse> => {
|
||||
if (!id) throw new Error('Agent type ID is required');
|
||||
const response = await apiClient.instance.get(`/api/v1/agent-types/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!user && !!id,
|
||||
staleTime: 60000, // 1 minute
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch an agent type by slug
|
||||
*
|
||||
* @param slug - Agent type slug
|
||||
* @returns Query result with agent type details
|
||||
*/
|
||||
export function useAgentTypeBySlug(slug: string | null) {
|
||||
const { user } = useAuth();
|
||||
|
||||
return useQuery({
|
||||
queryKey: agentTypeKeys.bySlug(slug ?? ''),
|
||||
queryFn: async (): Promise<AgentTypeResponse> => {
|
||||
if (!slug) throw new Error('Agent type slug is required');
|
||||
const response = await apiClient.instance.get(`/api/v1/agent-types/slug/${slug}`);
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!user && !!slug,
|
||||
staleTime: 60000, // 1 minute
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to create a new agent type
|
||||
*
|
||||
* @returns Mutation for creating agent types
|
||||
*/
|
||||
export function useCreateAgentType() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (data: AgentTypeCreate): Promise<AgentTypeResponse> => {
|
||||
const response = await apiClient.instance.post('/api/v1/agent-types', data);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Invalidate all agent type lists to refetch
|
||||
queryClient.invalidateQueries({ queryKey: agentTypeKeys.lists() });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to update an existing agent type
|
||||
*
|
||||
* @returns Mutation for updating agent types
|
||||
*/
|
||||
export function useUpdateAgentType() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
id,
|
||||
data,
|
||||
}: {
|
||||
id: string;
|
||||
data: AgentTypeUpdate;
|
||||
}): Promise<AgentTypeResponse> => {
|
||||
const response = await apiClient.instance.patch(`/api/v1/agent-types/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: (updatedAgentType) => {
|
||||
// Update the cache for this specific agent type
|
||||
queryClient.setQueryData(
|
||||
agentTypeKeys.detail(updatedAgentType.id),
|
||||
updatedAgentType
|
||||
);
|
||||
// Invalidate lists to reflect changes
|
||||
queryClient.invalidateQueries({ queryKey: agentTypeKeys.lists() });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to deactivate (soft delete) an agent type
|
||||
*
|
||||
* @returns Mutation for deactivating agent types
|
||||
*/
|
||||
export function useDeactivateAgentType() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string): Promise<{ success: boolean; message: string }> => {
|
||||
const response = await apiClient.instance.delete(`/api/v1/agent-types/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: (_data, id) => {
|
||||
// Invalidate all agent type queries
|
||||
queryClient.invalidateQueries({ queryKey: agentTypeKeys.all });
|
||||
// Remove specific agent type from cache
|
||||
queryClient.removeQueries({ queryKey: agentTypeKeys.detail(id) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to duplicate an agent type
|
||||
*
|
||||
* @returns Mutation for duplicating agent types
|
||||
*/
|
||||
export function useDuplicateAgentType() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (agentType: AgentTypeResponse): Promise<AgentTypeResponse> => {
|
||||
// Create a new agent type based on the existing one
|
||||
const newAgentType: AgentTypeCreate = {
|
||||
name: `${agentType.name} (Copy)`,
|
||||
slug: `${agentType.slug}-copy`,
|
||||
description: agentType.description,
|
||||
expertise: [...agentType.expertise],
|
||||
personality_prompt: agentType.personality_prompt,
|
||||
primary_model: agentType.primary_model,
|
||||
fallback_models: [...agentType.fallback_models],
|
||||
model_params: { ...agentType.model_params },
|
||||
mcp_servers: [...agentType.mcp_servers],
|
||||
tool_permissions: { ...agentType.tool_permissions },
|
||||
is_active: false, // Start as inactive/draft
|
||||
};
|
||||
|
||||
const response = await apiClient.instance.post('/api/v1/agent-types', newAgentType);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Invalidate lists to show the new duplicate
|
||||
queryClient.invalidateQueries({ queryKey: agentTypeKeys.lists() });
|
||||
},
|
||||
});
|
||||
}
|
||||
137
frontend/src/lib/api/types/agentTypes.ts
Normal file
137
frontend/src/lib/api/types/agentTypes.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* AgentType API Types
|
||||
*
|
||||
* These types mirror the backend Pydantic schemas for AgentType entities.
|
||||
* Used for type-safe API communication with the agent-types endpoints.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base agent type fields shared across create, update, and response schemas
|
||||
*/
|
||||
export interface AgentTypeBase {
|
||||
name: string;
|
||||
slug: string;
|
||||
description?: string | null;
|
||||
expertise: string[];
|
||||
personality_prompt: string;
|
||||
primary_model: string;
|
||||
fallback_models: string[];
|
||||
model_params: Record<string, unknown>;
|
||||
mcp_servers: string[];
|
||||
tool_permissions: Record<string, unknown>;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schema for creating a new agent type
|
||||
*/
|
||||
export interface AgentTypeCreate {
|
||||
name: string;
|
||||
slug: string;
|
||||
description?: string | null;
|
||||
expertise?: string[];
|
||||
personality_prompt: string;
|
||||
primary_model: string;
|
||||
fallback_models?: string[];
|
||||
model_params?: Record<string, unknown>;
|
||||
mcp_servers?: string[];
|
||||
tool_permissions?: Record<string, unknown>;
|
||||
is_active?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schema for updating an existing agent type
|
||||
*/
|
||||
export interface AgentTypeUpdate {
|
||||
name?: string | null;
|
||||
slug?: string | null;
|
||||
description?: string | null;
|
||||
expertise?: string[] | null;
|
||||
personality_prompt?: string | null;
|
||||
primary_model?: string | null;
|
||||
fallback_models?: string[] | null;
|
||||
model_params?: Record<string, unknown> | null;
|
||||
mcp_servers?: string[] | null;
|
||||
tool_permissions?: Record<string, unknown> | null;
|
||||
is_active?: boolean | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schema for agent type API responses
|
||||
*/
|
||||
export interface AgentTypeResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string | null;
|
||||
expertise: string[];
|
||||
personality_prompt: string;
|
||||
primary_model: string;
|
||||
fallback_models: string[];
|
||||
model_params: Record<string, unknown>;
|
||||
mcp_servers: string[];
|
||||
tool_permissions: Record<string, unknown>;
|
||||
is_active: boolean;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
instance_count: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pagination metadata for list responses
|
||||
*/
|
||||
export interface PaginationMeta {
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
total_pages: number;
|
||||
has_next: boolean;
|
||||
has_prev: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schema for paginated agent type list responses
|
||||
*/
|
||||
export interface AgentTypeListResponse {
|
||||
data: AgentTypeResponse[];
|
||||
pagination: PaginationMeta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query parameters for listing agent types
|
||||
*/
|
||||
export interface AgentTypeListParams {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
is_active?: boolean;
|
||||
search?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model parameter configuration with typed fields
|
||||
*/
|
||||
export interface ModelParams {
|
||||
temperature?: number;
|
||||
max_tokens?: number;
|
||||
top_p?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* MCP permission scope configuration
|
||||
*/
|
||||
export interface McpPermission {
|
||||
id: string;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool permission entry
|
||||
*/
|
||||
export interface ToolPermission {
|
||||
tool_id: string;
|
||||
enabled: boolean;
|
||||
scopes?: string[];
|
||||
}
|
||||
8
frontend/src/lib/api/types/index.ts
Normal file
8
frontend/src/lib/api/types/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* API Types
|
||||
*
|
||||
* Custom types for API entities that may not be in the generated client.
|
||||
* These are typically used for Syndarix-specific features.
|
||||
*/
|
||||
|
||||
export * from './agentTypes';
|
||||
@@ -4,4 +4,5 @@
|
||||
* @module lib/hooks
|
||||
*/
|
||||
|
||||
export { useDebounce } from './useDebounce';
|
||||
export { useProjectEvents, type UseProjectEventsOptions, type UseProjectEventsResult } from './useProjectEvents';
|
||||
|
||||
46
frontend/src/lib/hooks/useDebounce.ts
Normal file
46
frontend/src/lib/hooks/useDebounce.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* useDebounce Hook
|
||||
*
|
||||
* Debounces a value by a specified delay.
|
||||
* Useful for search inputs and other user input that triggers API calls.
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
/**
|
||||
* Hook that debounces a value
|
||||
*
|
||||
* @param value - The value to debounce
|
||||
* @param delay - Delay in milliseconds
|
||||
* @returns The debounced value
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const [searchQuery, setSearchQuery] = useState('');
|
||||
* const debouncedSearch = useDebounce(searchQuery, 300);
|
||||
*
|
||||
* // Use debouncedSearch for API calls
|
||||
* useEffect(() => {
|
||||
* fetchResults(debouncedSearch);
|
||||
* }, [debouncedSearch]);
|
||||
* ```
|
||||
*/
|
||||
export function useDebounce<T>(value: T, delay: number): T {
|
||||
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
||||
|
||||
useEffect(() => {
|
||||
// Set up the timeout
|
||||
const timeoutId = setTimeout(() => {
|
||||
setDebouncedValue(value);
|
||||
}, delay);
|
||||
|
||||
// Clean up on value change or unmount
|
||||
return () => {
|
||||
clearTimeout(timeoutId);
|
||||
};
|
||||
}, [value, delay]);
|
||||
|
||||
return debouncedValue;
|
||||
}
|
||||
155
frontend/src/lib/validations/agentType.ts
Normal file
155
frontend/src/lib/validations/agentType.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* Agent Type Form Validation Schemas
|
||||
*
|
||||
* Zod schemas for validating agent type form data.
|
||||
* Used with react-hook-form for form validation.
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Slug validation regex: lowercase letters, numbers, and hyphens only
|
||||
*/
|
||||
const slugRegex = /^[a-z0-9-]+$/;
|
||||
|
||||
/**
|
||||
* Available AI models for agent types
|
||||
*/
|
||||
export const AVAILABLE_MODELS = [
|
||||
{ value: 'claude-opus-4-5-20251101', label: 'Claude Opus 4.5' },
|
||||
{ value: 'claude-sonnet-4-20250514', label: 'Claude Sonnet 4' },
|
||||
{ value: 'claude-3-5-sonnet-20241022', label: 'Claude 3.5 Sonnet' },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Available MCP servers for agent permissions
|
||||
*/
|
||||
export const AVAILABLE_MCP_SERVERS = [
|
||||
{ id: 'gitea', name: 'Gitea', description: 'Git repository management' },
|
||||
{ id: 'knowledge', name: 'Knowledge Base', description: 'Vector database for RAG' },
|
||||
{ id: 'filesystem', name: 'Filesystem', description: 'File read/write operations' },
|
||||
{ id: 'slack', name: 'Slack', description: 'Team communication' },
|
||||
{ id: 'browser', name: 'Browser', description: 'Web browsing and scraping' },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Agent type status options
|
||||
*/
|
||||
export const AGENT_TYPE_STATUS = [
|
||||
{ value: true, label: 'Active' },
|
||||
{ value: false, label: 'Inactive' },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Model params schema
|
||||
*/
|
||||
const modelParamsSchema = z.object({
|
||||
temperature: z.number().min(0).max(2),
|
||||
max_tokens: z.number().int().min(1024).max(128000),
|
||||
top_p: z.number().min(0).max(1),
|
||||
});
|
||||
|
||||
/**
|
||||
* Schema for agent type form fields
|
||||
*/
|
||||
export const agentTypeFormSchema = z.object({
|
||||
name: z
|
||||
.string()
|
||||
.min(1, 'Name is required')
|
||||
.max(255, 'Name must be less than 255 characters'),
|
||||
|
||||
slug: z
|
||||
.string()
|
||||
.min(1, 'Slug is required')
|
||||
.max(255, 'Slug must be less than 255 characters')
|
||||
.regex(slugRegex, 'Slug must contain only lowercase letters, numbers, and hyphens')
|
||||
.refine((val) => !val.startsWith('-') && !val.endsWith('-'), {
|
||||
message: 'Slug cannot start or end with a hyphen',
|
||||
})
|
||||
.refine((val) => !val.includes('--'), {
|
||||
message: 'Slug cannot contain consecutive hyphens',
|
||||
}),
|
||||
|
||||
description: z
|
||||
.string()
|
||||
.max(2000, 'Description must be less than 2000 characters')
|
||||
.nullable()
|
||||
.optional(),
|
||||
|
||||
expertise: z.array(z.string()),
|
||||
|
||||
personality_prompt: z
|
||||
.string()
|
||||
.min(1, 'Personality prompt is required')
|
||||
.max(10000, 'Personality prompt must be less than 10000 characters'),
|
||||
|
||||
primary_model: z.string().min(1, 'Primary model is required'),
|
||||
|
||||
fallback_models: z.array(z.string()),
|
||||
|
||||
model_params: modelParamsSchema,
|
||||
|
||||
mcp_servers: z.array(z.string()),
|
||||
|
||||
tool_permissions: z.record(z.string(), z.unknown()),
|
||||
|
||||
is_active: z.boolean(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Schema for creating a new agent type (alias for backward compatibility)
|
||||
*/
|
||||
export const agentTypeCreateSchema = agentTypeFormSchema;
|
||||
|
||||
/**
|
||||
* Schema for updating an existing agent type
|
||||
* All fields are optional since we support partial updates
|
||||
*/
|
||||
export const agentTypeUpdateSchema = agentTypeFormSchema.partial();
|
||||
|
||||
/**
|
||||
* Type for agent type create form values
|
||||
*/
|
||||
export type AgentTypeCreateFormValues = z.infer<typeof agentTypeCreateSchema>;
|
||||
|
||||
/**
|
||||
* Type for agent type update form values
|
||||
*/
|
||||
export type AgentTypeUpdateFormValues = z.infer<typeof agentTypeUpdateSchema>;
|
||||
|
||||
/**
|
||||
* Default values for creating a new agent type
|
||||
*/
|
||||
export const defaultAgentTypeValues: AgentTypeCreateFormValues = {
|
||||
name: '',
|
||||
slug: '',
|
||||
description: null,
|
||||
expertise: [],
|
||||
personality_prompt: '',
|
||||
primary_model: 'claude-opus-4-5-20251101',
|
||||
fallback_models: ['claude-sonnet-4-20250514'],
|
||||
model_params: {
|
||||
temperature: 0.7,
|
||||
max_tokens: 8192,
|
||||
top_p: 0.95,
|
||||
},
|
||||
mcp_servers: [],
|
||||
tool_permissions: {},
|
||||
is_active: false, // Start as draft
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate slug from name
|
||||
*
|
||||
* @param name - The name to convert to a slug
|
||||
* @returns A valid slug string
|
||||
*/
|
||||
export function generateSlug(name: string): string {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9\s-]/g, '') // Remove special characters
|
||||
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
||||
.replace(/-+/g, '-') // Replace multiple hyphens with single
|
||||
.replace(/^-|-$/g, ''); // Remove leading/trailing hyphens
|
||||
}
|
||||
504
frontend/tests/components/activity/ActivityFeed.test.tsx
Normal file
504
frontend/tests/components/activity/ActivityFeed.test.tsx
Normal file
@@ -0,0 +1,504 @@
|
||||
/**
|
||||
* Tests for ActivityFeed Component
|
||||
*
|
||||
* Tests cover:
|
||||
* - Rendering with events
|
||||
* - Connection state indicator
|
||||
* - Search functionality
|
||||
* - Filter functionality
|
||||
* - Event expansion
|
||||
* - Approval actions
|
||||
* - Time-based grouping
|
||||
* - Loading state
|
||||
* - Empty state
|
||||
*/
|
||||
|
||||
import { render, screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { ActivityFeed } from '@/components/activity/ActivityFeed';
|
||||
import { EventType, type ProjectEvent } from '@/lib/types/events';
|
||||
|
||||
// ============================================================================
|
||||
// Test Data
|
||||
// ============================================================================
|
||||
|
||||
const createMockEvent = (overrides: Partial<ProjectEvent> = {}): ProjectEvent => ({
|
||||
id: `event-${Math.random().toString(36).substr(2, 9)}`,
|
||||
type: EventType.AGENT_MESSAGE,
|
||||
timestamp: new Date().toISOString(),
|
||||
project_id: 'project-001',
|
||||
actor_id: 'agent-001',
|
||||
actor_type: 'agent',
|
||||
payload: {
|
||||
agent_instance_id: 'agent-001',
|
||||
message: 'Test message',
|
||||
message_type: 'info',
|
||||
},
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const mockEvents: ProjectEvent[] = [
|
||||
// Today's events
|
||||
createMockEvent({
|
||||
id: 'event-001',
|
||||
type: EventType.APPROVAL_REQUESTED,
|
||||
timestamp: new Date().toISOString(),
|
||||
payload: {
|
||||
approval_id: 'apr-001',
|
||||
approval_type: 'architecture_decision',
|
||||
description: 'Approval required for API design',
|
||||
requested_by: 'Architect',
|
||||
},
|
||||
}),
|
||||
createMockEvent({
|
||||
id: 'event-002',
|
||||
type: EventType.AGENT_MESSAGE,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 30).toISOString(),
|
||||
payload: {
|
||||
agent_instance_id: 'agent-002',
|
||||
message: 'Completed JWT implementation',
|
||||
message_type: 'info',
|
||||
},
|
||||
}),
|
||||
// Yesterday's event
|
||||
createMockEvent({
|
||||
id: 'event-003',
|
||||
type: EventType.ISSUE_CREATED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(),
|
||||
payload: {
|
||||
issue_id: 'issue-001',
|
||||
title: 'Add rate limiting',
|
||||
priority: 'medium',
|
||||
},
|
||||
}),
|
||||
// This week's event
|
||||
createMockEvent({
|
||||
id: 'event-004',
|
||||
type: EventType.SPRINT_STARTED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 3).toISOString(),
|
||||
payload: {
|
||||
sprint_id: 'sprint-001',
|
||||
sprint_name: 'Sprint 1',
|
||||
goal: 'Complete auth module',
|
||||
},
|
||||
}),
|
||||
// Older event
|
||||
createMockEvent({
|
||||
id: 'event-005',
|
||||
type: EventType.WORKFLOW_COMPLETED,
|
||||
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 10).toISOString(),
|
||||
payload: {
|
||||
workflow_id: 'wf-001',
|
||||
duration_seconds: 3600,
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
// ============================================================================
|
||||
// Tests
|
||||
// ============================================================================
|
||||
|
||||
describe('ActivityFeed', () => {
|
||||
const defaultProps = {
|
||||
events: mockEvents,
|
||||
connectionState: 'connected' as const,
|
||||
};
|
||||
|
||||
describe('Rendering', () => {
|
||||
it('renders the activity feed with test id', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
expect(screen.getByTestId('activity-feed')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the header with title', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
expect(screen.getByText('Activity Feed')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders custom title when provided', () => {
|
||||
render(<ActivityFeed {...defaultProps} title="Project Activity" />);
|
||||
expect(screen.getByText('Project Activity')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides header when showHeader is false', () => {
|
||||
render(<ActivityFeed {...defaultProps} showHeader={false} />);
|
||||
expect(screen.queryByText('Activity Feed')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders events', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
expect(screen.getByTestId('event-item-event-001')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('event-item-event-002')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<ActivityFeed {...defaultProps} className="custom-class" />);
|
||||
expect(screen.getByTestId('activity-feed')).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Connection State', () => {
|
||||
it('renders connection indicator', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
expect(screen.getByTestId('connection-indicator')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows "Live" when connected', () => {
|
||||
render(<ActivityFeed {...defaultProps} connectionState="connected" />);
|
||||
expect(screen.getByText('Live')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows "Connecting..." when connecting', () => {
|
||||
render(<ActivityFeed {...defaultProps} connectionState="connecting" />);
|
||||
expect(screen.getByText('Connecting...')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows "Disconnected" when disconnected', () => {
|
||||
render(<ActivityFeed {...defaultProps} connectionState="disconnected" />);
|
||||
expect(screen.getByText('Disconnected')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows "Error" when error state', () => {
|
||||
render(<ActivityFeed {...defaultProps} connectionState="error" />);
|
||||
expect(screen.getByText('Error')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows reconnect button when disconnected', () => {
|
||||
const onReconnect = jest.fn();
|
||||
render(
|
||||
<ActivityFeed {...defaultProps} connectionState="disconnected" onReconnect={onReconnect} />
|
||||
);
|
||||
const reconnectButton = screen.getByLabelText('Reconnect');
|
||||
expect(reconnectButton).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onReconnect when reconnect button clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onReconnect = jest.fn();
|
||||
render(
|
||||
<ActivityFeed {...defaultProps} connectionState="disconnected" onReconnect={onReconnect} />
|
||||
);
|
||||
|
||||
await user.click(screen.getByLabelText('Reconnect'));
|
||||
expect(onReconnect).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Search Functionality', () => {
|
||||
it('renders search input when enableSearch is true', () => {
|
||||
render(<ActivityFeed {...defaultProps} enableSearch />);
|
||||
expect(screen.getByTestId('search-input')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides search input when enableSearch is false', () => {
|
||||
render(<ActivityFeed {...defaultProps} enableSearch={false} />);
|
||||
expect(screen.queryByTestId('search-input')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('filters events based on search query', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} enableSearch />);
|
||||
|
||||
const searchInput = screen.getByTestId('search-input');
|
||||
await user.type(searchInput, 'JWT');
|
||||
|
||||
// Event with JWT in message should be visible
|
||||
expect(screen.getByText(/Completed JWT implementation/)).toBeInTheDocument();
|
||||
// Other events should be filtered out
|
||||
expect(screen.queryByText(/Approval required for API design/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows empty state when search finds no results', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} enableSearch />);
|
||||
|
||||
const searchInput = screen.getByTestId('search-input');
|
||||
await user.type(searchInput, 'nonexistent query xyz');
|
||||
|
||||
expect(screen.getByTestId('empty-state')).toBeInTheDocument();
|
||||
expect(screen.getByText('No activity found')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Filter Functionality', () => {
|
||||
it('renders filter toggle when enableFiltering is true', () => {
|
||||
render(<ActivityFeed {...defaultProps} enableFiltering />);
|
||||
expect(screen.getByTestId('filter-toggle')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides filter toggle when enableFiltering is false', () => {
|
||||
render(<ActivityFeed {...defaultProps} enableFiltering={false} />);
|
||||
expect(screen.queryByTestId('filter-toggle')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows filter panel when filter toggle is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} enableFiltering />);
|
||||
|
||||
await user.click(screen.getByTestId('filter-toggle'));
|
||||
expect(screen.getByTestId('filter-panel')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('filters events by category when filter is selected', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} enableFiltering />);
|
||||
|
||||
// Open filter panel
|
||||
await user.click(screen.getByTestId('filter-toggle'));
|
||||
|
||||
// Select Issues category
|
||||
const issuesCheckbox = screen.getByLabelText(/Issues/);
|
||||
await user.click(issuesCheckbox);
|
||||
|
||||
// Only issue events should be visible
|
||||
expect(screen.getByText(/Add rate limiting/)).toBeInTheDocument();
|
||||
// Agent events should be filtered out
|
||||
expect(screen.queryByText(/Completed JWT implementation/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows pending only when filter is selected', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} enableFiltering />);
|
||||
|
||||
// Open filter panel
|
||||
await user.click(screen.getByTestId('filter-toggle'));
|
||||
|
||||
// Select pending only
|
||||
const pendingCheckbox = screen.getByLabelText(/Show only pending approvals/);
|
||||
await user.click(pendingCheckbox);
|
||||
|
||||
// Only approval requested events should be visible
|
||||
expect(screen.getByText(/Approval required for API design/)).toBeInTheDocument();
|
||||
// Other events should be filtered out
|
||||
expect(screen.queryByText(/Completed JWT implementation/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('clears filters when Clear Filters is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} enableFiltering enableSearch />);
|
||||
|
||||
// Add search query
|
||||
await user.type(screen.getByTestId('search-input'), 'JWT');
|
||||
|
||||
// Open filter panel and select a filter
|
||||
await user.click(screen.getByTestId('filter-toggle'));
|
||||
await user.click(screen.getByLabelText(/Issues/));
|
||||
|
||||
// Clear filters
|
||||
await user.click(screen.getByText('Clear Filters'));
|
||||
|
||||
// All events should be visible again
|
||||
expect(screen.getByText(/Completed JWT implementation/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Approval required for API design/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Event Expansion', () => {
|
||||
it('expands event details when clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
await user.click(eventItem);
|
||||
|
||||
expect(screen.getByTestId('event-details')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('collapses event details when clicked again', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
|
||||
// Expand
|
||||
await user.click(eventItem);
|
||||
expect(screen.getByTestId('event-details')).toBeInTheDocument();
|
||||
|
||||
// Collapse
|
||||
await user.click(eventItem);
|
||||
expect(screen.queryByTestId('event-details')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows raw payload in expanded details', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
await user.click(eventItem);
|
||||
|
||||
// Check for payload content
|
||||
expect(screen.getByText(/View raw payload/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Approval Actions', () => {
|
||||
it('shows approve and reject buttons for pending approvals', () => {
|
||||
render(<ActivityFeed {...defaultProps} onApprove={jest.fn()} onReject={jest.fn()} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
expect(within(eventItem).getByTestId('approve-button')).toBeInTheDocument();
|
||||
expect(within(eventItem).getByTestId('reject-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show action buttons for non-approval events', () => {
|
||||
render(<ActivityFeed {...defaultProps} onApprove={jest.fn()} onReject={jest.fn()} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-002');
|
||||
expect(within(eventItem).queryByTestId('approve-button')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onApprove when approve button clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onApprove = jest.fn();
|
||||
render(<ActivityFeed {...defaultProps} onApprove={onApprove} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
await user.click(within(eventItem).getByTestId('approve-button'));
|
||||
|
||||
expect(onApprove).toHaveBeenCalledTimes(1);
|
||||
expect(onApprove).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 'event-001' })
|
||||
);
|
||||
});
|
||||
|
||||
it('calls onReject when reject button clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onReject = jest.fn();
|
||||
render(<ActivityFeed {...defaultProps} onReject={onReject} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
await user.click(within(eventItem).getByTestId('reject-button'));
|
||||
|
||||
expect(onReject).toHaveBeenCalledTimes(1);
|
||||
expect(onReject).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 'event-001' })
|
||||
);
|
||||
});
|
||||
|
||||
it('shows pending count badge', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
expect(screen.getByText('1 pending')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Time-Based Grouping', () => {
|
||||
it('groups events by time period', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
|
||||
// Check for time period headers
|
||||
expect(screen.getByTestId('event-group-today')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows event count in group header', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
|
||||
const todayGroup = screen.getByTestId('event-group-today');
|
||||
// Today has 2 events in our mock data
|
||||
expect(within(todayGroup).getByText('2')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Loading State', () => {
|
||||
it('shows loading skeleton when isLoading is true', () => {
|
||||
render(<ActivityFeed {...defaultProps} isLoading />);
|
||||
expect(screen.getByTestId('loading-skeleton')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides events when loading', () => {
|
||||
render(<ActivityFeed {...defaultProps} isLoading />);
|
||||
expect(screen.queryByTestId('event-item-event-001')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Empty State', () => {
|
||||
it('shows empty state when no events', () => {
|
||||
render(<ActivityFeed {...defaultProps} events={[]} />);
|
||||
expect(screen.getByTestId('empty-state')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows appropriate message when no events and no filters', () => {
|
||||
render(<ActivityFeed {...defaultProps} events={[]} />);
|
||||
expect(screen.getByText(/Activity will appear here/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows appropriate message when filtered to empty', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} enableSearch />);
|
||||
|
||||
await user.type(screen.getByTestId('search-input'), 'nonexistent');
|
||||
|
||||
expect(screen.getByText(/Try adjusting your search or filters/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Event Click Handler', () => {
|
||||
it('calls onEventClick when event is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onEventClick = jest.fn();
|
||||
render(<ActivityFeed {...defaultProps} onEventClick={onEventClick} />);
|
||||
|
||||
await user.click(screen.getByTestId('event-item-event-001'));
|
||||
|
||||
expect(onEventClick).toHaveBeenCalledTimes(1);
|
||||
expect(onEventClick).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 'event-001' })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Compact Mode', () => {
|
||||
it('applies compact styling when compact is true', () => {
|
||||
render(<ActivityFeed {...defaultProps} compact />);
|
||||
|
||||
// Check for compact-specific styling (p-2 instead of p-4)
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
// The event item should have compact padding
|
||||
expect(eventItem).toHaveClass('p-2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Accessibility', () => {
|
||||
it('has proper ARIA labels for interactive elements', () => {
|
||||
render(<ActivityFeed {...defaultProps} onReconnect={jest.fn()} connectionState="disconnected" />);
|
||||
|
||||
expect(screen.getByLabelText('Reconnect')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('event items are keyboard accessible', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
|
||||
const eventItem = screen.getByTestId('event-item-event-001');
|
||||
|
||||
// Focus and activate with keyboard
|
||||
eventItem.focus();
|
||||
await user.keyboard('{Enter}');
|
||||
|
||||
expect(screen.getByTestId('event-details')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders semantic HTML structure', () => {
|
||||
render(<ActivityFeed {...defaultProps} />);
|
||||
|
||||
// Check for proper heading hierarchy
|
||||
const heading = screen.getByText('Today');
|
||||
expect(heading.tagName).toBe('H3');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Max Height', () => {
|
||||
it('applies max height styling', () => {
|
||||
const { container } = render(<ActivityFeed {...defaultProps} maxHeight={500} />);
|
||||
|
||||
const scrollContainer = container.querySelector('.overflow-y-auto');
|
||||
expect(scrollContainer).toHaveStyle({ maxHeight: '500px' });
|
||||
});
|
||||
|
||||
it('handles string max height', () => {
|
||||
const { container } = render(<ActivityFeed {...defaultProps} maxHeight="auto" />);
|
||||
|
||||
const scrollContainer = container.querySelector('.overflow-y-auto');
|
||||
expect(scrollContainer).toHaveStyle({ maxHeight: 'auto' });
|
||||
});
|
||||
});
|
||||
});
|
||||
223
frontend/tests/components/agents/AgentTypeDetail.test.tsx
Normal file
223
frontend/tests/components/agents/AgentTypeDetail.test.tsx
Normal file
@@ -0,0 +1,223 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { AgentTypeDetail } from '@/components/agents/AgentTypeDetail';
|
||||
import type { AgentTypeResponse } from '@/lib/api/types/agentTypes';
|
||||
|
||||
const mockAgentType: AgentTypeResponse = {
|
||||
id: 'type-001',
|
||||
name: 'Software Architect',
|
||||
slug: 'software-architect',
|
||||
description: 'Designs system architecture and makes technology decisions',
|
||||
expertise: ['system design', 'api design', 'security', 'scalability'],
|
||||
personality_prompt: `You are a Senior Software Architect with 15+ years of experience.
|
||||
|
||||
Your approach is:
|
||||
1. Pragmatic: You favor proven solutions
|
||||
2. Security-minded: Security is a first-class concern
|
||||
3. Documentation-focused: You believe in ADRs`,
|
||||
primary_model: 'claude-opus-4-5-20251101',
|
||||
fallback_models: ['claude-sonnet-4-20250514'],
|
||||
model_params: { temperature: 0.7, max_tokens: 8192, top_p: 0.95 },
|
||||
mcp_servers: ['gitea', 'knowledge', 'filesystem'],
|
||||
tool_permissions: {},
|
||||
is_active: true,
|
||||
created_at: '2025-01-10T00:00:00Z',
|
||||
updated_at: '2025-01-18T00:00:00Z',
|
||||
instance_count: 2,
|
||||
};
|
||||
|
||||
describe('AgentTypeDetail', () => {
|
||||
const defaultProps = {
|
||||
agentType: mockAgentType,
|
||||
isLoading: false,
|
||||
onBack: jest.fn(),
|
||||
onEdit: jest.fn(),
|
||||
onDuplicate: jest.fn(),
|
||||
onDeactivate: jest.fn(),
|
||||
isDeactivating: false,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('renders agent type name', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Software Architect')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders active status badge', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Active')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders inactive status badge for inactive agent type', () => {
|
||||
render(
|
||||
<AgentTypeDetail {...defaultProps} agentType={{ ...mockAgentType, is_active: false }} />
|
||||
);
|
||||
expect(screen.getByText('Inactive')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders description card', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Description')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Designs system architecture and makes technology decisions')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders expertise areas', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Expertise Areas')).toBeInTheDocument();
|
||||
expect(screen.getByText('system design')).toBeInTheDocument();
|
||||
expect(screen.getByText('api design')).toBeInTheDocument();
|
||||
expect(screen.getByText('security')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders personality prompt', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Personality Prompt')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(/You are a Senior Software Architect with 15\+ years of experience/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders MCP permissions section', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('MCP Permissions')).toBeInTheDocument();
|
||||
expect(screen.getByText('Gitea')).toBeInTheDocument();
|
||||
expect(screen.getByText('Knowledge Base')).toBeInTheDocument();
|
||||
expect(screen.getByText('Filesystem')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows enabled/disabled status for MCP servers', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
// Should show 3 "Enabled" badges for gitea, knowledge, filesystem
|
||||
const enabledBadges = screen.getAllByText('Enabled');
|
||||
expect(enabledBadges.length).toBe(3);
|
||||
// Should show 2 "Disabled" badges for slack, browser
|
||||
const disabledBadges = screen.getAllByText('Disabled');
|
||||
expect(disabledBadges.length).toBe(2);
|
||||
});
|
||||
|
||||
it('renders model configuration', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Model Configuration')).toBeInTheDocument();
|
||||
expect(screen.getByText('Primary Model')).toBeInTheDocument();
|
||||
expect(screen.getByText('Claude Opus 4.5')).toBeInTheDocument();
|
||||
expect(screen.getByText('Failover Model')).toBeInTheDocument();
|
||||
expect(screen.getByText('Claude Sonnet 4')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders model parameters', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Temperature')).toBeInTheDocument();
|
||||
expect(screen.getByText('0.7')).toBeInTheDocument();
|
||||
expect(screen.getByText('Max Tokens')).toBeInTheDocument();
|
||||
expect(screen.getByText('8,192')).toBeInTheDocument();
|
||||
expect(screen.getByText('Top P')).toBeInTheDocument();
|
||||
expect(screen.getByText('0.95')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders instance count', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Instances')).toBeInTheDocument();
|
||||
expect(screen.getByText('2')).toBeInTheDocument();
|
||||
expect(screen.getByText('Active instances')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onBack when back button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /go back/i }));
|
||||
expect(defaultProps.onBack).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onEdit when edit button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /edit/i }));
|
||||
expect(defaultProps.onEdit).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onDuplicate when duplicate button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /duplicate/i }));
|
||||
expect(defaultProps.onDuplicate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('shows loading skeleton when isLoading is true', () => {
|
||||
const { container } = render(
|
||||
<AgentTypeDetail {...defaultProps} agentType={null} isLoading={true} />
|
||||
);
|
||||
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('shows not found state when agentType is null', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} agentType={null} isLoading={false} />);
|
||||
expect(screen.getByText('Agent type not found')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('The requested agent type could not be found')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows danger zone with deactivate button', () => {
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
expect(screen.getByText('Danger Zone')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /deactivate type/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows confirmation dialog when deactivate is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /deactivate type/i }));
|
||||
expect(screen.getByText('Are you sure?')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /cancel/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /deactivate$/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onDeactivate when confirmation is accepted', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeDetail {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /deactivate type/i }));
|
||||
await user.click(screen.getByRole('button', { name: /^deactivate$/i }));
|
||||
expect(defaultProps.onDeactivate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<AgentTypeDetail {...defaultProps} className="custom-class" />
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('shows no description message when description is null', () => {
|
||||
render(
|
||||
<AgentTypeDetail {...defaultProps} agentType={{ ...mockAgentType, description: null }} />
|
||||
);
|
||||
expect(screen.getByText('No description provided')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows no expertise message when expertise is empty', () => {
|
||||
render(
|
||||
<AgentTypeDetail {...defaultProps} agentType={{ ...mockAgentType, expertise: [] }} />
|
||||
);
|
||||
expect(screen.getByText('No expertise areas defined')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows "None configured" when no fallback model', () => {
|
||||
render(
|
||||
<AgentTypeDetail
|
||||
{...defaultProps}
|
||||
agentType={{ ...mockAgentType, fallback_models: [] }}
|
||||
/>
|
||||
);
|
||||
expect(screen.getByText('None configured')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
242
frontend/tests/components/agents/AgentTypeForm.test.tsx
Normal file
242
frontend/tests/components/agents/AgentTypeForm.test.tsx
Normal file
@@ -0,0 +1,242 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { AgentTypeForm } from '@/components/agents/AgentTypeForm';
|
||||
import type { AgentTypeResponse } from '@/lib/api/types/agentTypes';
|
||||
|
||||
const mockAgentType: AgentTypeResponse = {
|
||||
id: 'type-001',
|
||||
name: 'Software Architect',
|
||||
slug: 'software-architect',
|
||||
description: 'Designs system architecture',
|
||||
expertise: ['system design', 'api design'],
|
||||
personality_prompt: 'You are a Software Architect...',
|
||||
primary_model: 'claude-opus-4-5-20251101',
|
||||
fallback_models: ['claude-sonnet-4-20250514'],
|
||||
model_params: { temperature: 0.7, max_tokens: 8192, top_p: 0.95 },
|
||||
mcp_servers: ['gitea'],
|
||||
tool_permissions: {},
|
||||
is_active: true,
|
||||
created_at: '2025-01-10T00:00:00Z',
|
||||
updated_at: '2025-01-18T00:00:00Z',
|
||||
instance_count: 2,
|
||||
};
|
||||
|
||||
describe('AgentTypeForm', () => {
|
||||
const defaultProps = {
|
||||
onSubmit: jest.fn(),
|
||||
onCancel: jest.fn(),
|
||||
isSubmitting: false,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Create Mode', () => {
|
||||
it('renders create form title', () => {
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
expect(screen.getByText('Create Agent Type')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Define a new agent type template')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders all tabs', () => {
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
expect(screen.getByRole('tab', { name: /basic info/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: /model/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: /permissions/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: /personality/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders basic info fields by default', () => {
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
expect(screen.getByLabelText(/name/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/slug/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/description/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('auto-generates slug from name', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
const nameInput = screen.getByLabelText(/name/i);
|
||||
await user.type(nameInput, 'Product Owner');
|
||||
|
||||
const slugInput = screen.getByLabelText(/slug/i) as HTMLInputElement;
|
||||
await waitFor(() => {
|
||||
expect(slugInput.value).toBe('product-owner');
|
||||
});
|
||||
});
|
||||
|
||||
it('shows validation error for empty name', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /create/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Name is required')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('shows validation error for empty personality prompt', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
// Fill name to pass first validation
|
||||
await user.type(screen.getByLabelText(/name/i), 'Test Agent');
|
||||
|
||||
// Switch to personality tab
|
||||
await user.click(screen.getByRole('tab', { name: /personality/i }));
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /create/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Personality prompt is required')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('submits with default values when minimum required fields are filled', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
// Fill name (which auto-generates slug)
|
||||
await user.type(screen.getByLabelText(/name/i), 'Test Agent');
|
||||
|
||||
// Wait for slug to auto-populate
|
||||
await waitFor(() => {
|
||||
expect((screen.getByLabelText(/slug/i) as HTMLInputElement).value).toBe('test-agent');
|
||||
});
|
||||
|
||||
// Note: onSubmit will not be called because personality_prompt is required
|
||||
// This test just verifies the form fields are working correctly
|
||||
expect(defaultProps.onSubmit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls onCancel when cancel button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /cancel/i }));
|
||||
expect(defaultProps.onCancel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onCancel when back button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /go back/i }));
|
||||
expect(defaultProps.onCancel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Edit Mode', () => {
|
||||
it('renders edit form title', () => {
|
||||
render(<AgentTypeForm {...defaultProps} agentType={mockAgentType} />);
|
||||
expect(screen.getByText('Edit Agent Type')).toBeInTheDocument();
|
||||
expect(screen.getByText('Modify agent type configuration')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('pre-fills form with agent type data', () => {
|
||||
render(<AgentTypeForm {...defaultProps} agentType={mockAgentType} />);
|
||||
|
||||
const nameInput = screen.getByLabelText(/name/i) as HTMLInputElement;
|
||||
expect(nameInput.value).toBe('Software Architect');
|
||||
|
||||
const slugInput = screen.getByLabelText(/slug/i) as HTMLInputElement;
|
||||
expect(slugInput.value).toBe('software-architect');
|
||||
});
|
||||
|
||||
it('shows save changes button', () => {
|
||||
render(<AgentTypeForm {...defaultProps} agentType={mockAgentType} />);
|
||||
expect(screen.getByRole('button', { name: /save changes/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not auto-generate slug when editing', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} agentType={mockAgentType} />);
|
||||
|
||||
const nameInput = screen.getByLabelText(/name/i);
|
||||
await user.clear(nameInput);
|
||||
await user.type(nameInput, 'New Name');
|
||||
|
||||
// Slug should remain unchanged
|
||||
const slugInput = screen.getByLabelText(/slug/i) as HTMLInputElement;
|
||||
expect(slugInput.value).toBe('software-architect');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Tabs', () => {
|
||||
it('renders all tab triggers', () => {
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
expect(screen.getByRole('tab', { name: /basic info/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: /model/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: /permissions/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: /personality/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('basic info tab is active by default', () => {
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
// Basic Info content should be visible
|
||||
expect(screen.getByLabelText(/name/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/slug/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/description/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Expertise Management', () => {
|
||||
it('adds expertise when add button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
const expertiseInput = screen.getByPlaceholderText(/e.g., system design/i);
|
||||
await user.type(expertiseInput, 'new skill');
|
||||
await user.click(screen.getByRole('button', { name: /^add$/i }));
|
||||
|
||||
expect(screen.getByText('new skill')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('adds expertise on enter key', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} />);
|
||||
|
||||
const expertiseInput = screen.getByPlaceholderText(/e.g., system design/i);
|
||||
await user.type(expertiseInput, 'keyboard skill{Enter}');
|
||||
|
||||
expect(screen.getByText('keyboard skill')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('removes expertise when X button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeForm {...defaultProps} agentType={mockAgentType} />);
|
||||
|
||||
// Should have existing expertise
|
||||
expect(screen.getByText('system design')).toBeInTheDocument();
|
||||
|
||||
// Click remove button
|
||||
const removeButton = screen.getByRole('button', { name: /remove system design/i });
|
||||
await user.click(removeButton);
|
||||
|
||||
expect(screen.queryByText('system design')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Form State', () => {
|
||||
it('disables buttons when submitting', () => {
|
||||
render(<AgentTypeForm {...defaultProps} isSubmitting={true} />);
|
||||
|
||||
expect(screen.getByRole('button', { name: /saving/i })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: /cancel/i })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<AgentTypeForm {...defaultProps} className="custom-class" />
|
||||
);
|
||||
expect(container.querySelector('form')).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
});
|
||||
183
frontend/tests/components/agents/AgentTypeList.test.tsx
Normal file
183
frontend/tests/components/agents/AgentTypeList.test.tsx
Normal file
@@ -0,0 +1,183 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { AgentTypeList } from '@/components/agents/AgentTypeList';
|
||||
import type { AgentTypeResponse } from '@/lib/api/types/agentTypes';
|
||||
|
||||
const mockAgentTypes: AgentTypeResponse[] = [
|
||||
{
|
||||
id: 'type-001',
|
||||
name: 'Product Owner',
|
||||
slug: 'product-owner',
|
||||
description: 'Manages product backlog and prioritizes features',
|
||||
expertise: ['requirements', 'user stories', 'prioritization'],
|
||||
personality_prompt: 'You are a Product Owner...',
|
||||
primary_model: 'claude-opus-4-5-20251101',
|
||||
fallback_models: ['claude-sonnet-4-20250514'],
|
||||
model_params: { temperature: 0.7, max_tokens: 8192, top_p: 0.95 },
|
||||
mcp_servers: ['gitea', 'knowledge'],
|
||||
tool_permissions: {},
|
||||
is_active: true,
|
||||
created_at: '2025-01-15T00:00:00Z',
|
||||
updated_at: '2025-01-20T00:00:00Z',
|
||||
instance_count: 3,
|
||||
},
|
||||
{
|
||||
id: 'type-002',
|
||||
name: 'Software Architect',
|
||||
slug: 'software-architect',
|
||||
description: 'Designs system architecture and makes technology decisions',
|
||||
expertise: ['system design', 'api design', 'security'],
|
||||
personality_prompt: 'You are a Software Architect...',
|
||||
primary_model: 'claude-opus-4-5-20251101',
|
||||
fallback_models: [],
|
||||
model_params: { temperature: 0.5, max_tokens: 8192, top_p: 0.9 },
|
||||
mcp_servers: ['gitea'],
|
||||
tool_permissions: {},
|
||||
is_active: false,
|
||||
created_at: '2025-01-10T00:00:00Z',
|
||||
updated_at: '2025-01-18T00:00:00Z',
|
||||
instance_count: 0,
|
||||
},
|
||||
];
|
||||
|
||||
describe('AgentTypeList', () => {
|
||||
const defaultProps = {
|
||||
agentTypes: mockAgentTypes,
|
||||
isLoading: false,
|
||||
searchQuery: '',
|
||||
onSearchChange: jest.fn(),
|
||||
statusFilter: 'all',
|
||||
onStatusFilterChange: jest.fn(),
|
||||
onSelect: jest.fn(),
|
||||
onCreate: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('renders page title and description', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(screen.getByText('Agent Types')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Configure templates for spawning AI agent instances')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders create button', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(screen.getByRole('button', { name: /create agent type/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders search input', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(screen.getByPlaceholderText('Search agent types...')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders all agent types', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(screen.getByText('Product Owner')).toBeInTheDocument();
|
||||
expect(screen.getByText('Software Architect')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows description for each agent type', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(
|
||||
screen.getByText('Manages product backlog and prioritizes features')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Designs system architecture and makes technology decisions')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows active status badge for active agent types', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(screen.getByText('Active')).toBeInTheDocument();
|
||||
expect(screen.getByText('Inactive')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows expertise tags', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(screen.getByText('requirements')).toBeInTheDocument();
|
||||
expect(screen.getByText('user stories')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows instance count', () => {
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
expect(screen.getByText('3 instances')).toBeInTheDocument();
|
||||
expect(screen.getByText('0 instances')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onSelect when agent type card is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByText('Product Owner'));
|
||||
expect(defaultProps.onSelect).toHaveBeenCalledWith('type-001');
|
||||
});
|
||||
|
||||
it('calls onCreate when create button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /create agent type/i }));
|
||||
expect(defaultProps.onCreate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onSearchChange when search input changes', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
|
||||
const searchInput = screen.getByPlaceholderText('Search agent types...');
|
||||
await user.type(searchInput, 'architect');
|
||||
expect(defaultProps.onSearchChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows loading skeletons when isLoading is true', () => {
|
||||
const { container } = render(
|
||||
<AgentTypeList {...defaultProps} agentTypes={[]} isLoading={true} />
|
||||
);
|
||||
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('shows empty state when no agent types', () => {
|
||||
render(<AgentTypeList {...defaultProps} agentTypes={[]} />);
|
||||
expect(screen.getByText('No agent types found')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Create your first agent type to get started')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows filter hint in empty state when filters are applied', () => {
|
||||
render(
|
||||
<AgentTypeList {...defaultProps} agentTypes={[]} searchQuery="nonexistent" />
|
||||
);
|
||||
expect(screen.getByText('Try adjusting your search or filters')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows +N badge when expertise has more than 3 items', () => {
|
||||
const agentWithManySkills: AgentTypeResponse = {
|
||||
...mockAgentTypes[0],
|
||||
expertise: ['skill1', 'skill2', 'skill3', 'skill4', 'skill5'],
|
||||
};
|
||||
render(<AgentTypeList {...defaultProps} agentTypes={[agentWithManySkills]} />);
|
||||
expect(screen.getByText('+2')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('supports keyboard navigation on agent type cards', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AgentTypeList {...defaultProps} />);
|
||||
|
||||
const cards = screen.getAllByRole('button', { name: /view .* agent type/i });
|
||||
cards[0].focus();
|
||||
await user.keyboard('{Enter}');
|
||||
expect(defaultProps.onSelect).toHaveBeenCalledWith('type-001');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<AgentTypeList {...defaultProps} className="custom-class" />
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
117
frontend/tests/components/projects/AgentPanel.test.tsx
Normal file
117
frontend/tests/components/projects/AgentPanel.test.tsx
Normal file
@@ -0,0 +1,117 @@
|
||||
import { render, screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { AgentPanel } from '@/components/projects/AgentPanel';
|
||||
import type { AgentInstance } from '@/components/projects/types';
|
||||
|
||||
const mockAgents: AgentInstance[] = [
|
||||
{
|
||||
id: 'agent-001',
|
||||
agent_type_id: 'type-po',
|
||||
project_id: 'proj-001',
|
||||
name: 'Product Owner',
|
||||
role: 'product_owner',
|
||||
status: 'active',
|
||||
current_task: 'Reviewing user stories',
|
||||
last_activity_at: new Date().toISOString(),
|
||||
spawned_at: '2025-01-15T00:00:00Z',
|
||||
avatar: 'PO',
|
||||
},
|
||||
{
|
||||
id: 'agent-002',
|
||||
agent_type_id: 'type-be',
|
||||
project_id: 'proj-001',
|
||||
name: 'Backend Engineer',
|
||||
role: 'backend_engineer',
|
||||
status: 'idle',
|
||||
current_task: 'Waiting for review',
|
||||
last_activity_at: new Date().toISOString(),
|
||||
spawned_at: '2025-01-15T00:00:00Z',
|
||||
},
|
||||
];
|
||||
|
||||
describe('AgentPanel', () => {
|
||||
it('renders agent panel with title', () => {
|
||||
render(<AgentPanel agents={mockAgents} />);
|
||||
expect(screen.getByText('Active Agents')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows correct active agent count', () => {
|
||||
render(<AgentPanel agents={mockAgents} />);
|
||||
expect(screen.getByText('1 of 2 agents working')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders all agents', () => {
|
||||
render(<AgentPanel agents={mockAgents} />);
|
||||
expect(screen.getByText('Product Owner')).toBeInTheDocument();
|
||||
expect(screen.getByText('Backend Engineer')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows agent current task', () => {
|
||||
render(<AgentPanel agents={mockAgents} />);
|
||||
expect(screen.getByText('Reviewing user stories')).toBeInTheDocument();
|
||||
expect(screen.getByText('Waiting for review')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders empty state when no agents', () => {
|
||||
render(<AgentPanel agents={[]} />);
|
||||
expect(screen.getByText('No agents assigned to this project')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows loading skeleton when isLoading is true', () => {
|
||||
const { container } = render(<AgentPanel agents={[]} isLoading />);
|
||||
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('calls onManageAgents when button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onManageAgents = jest.fn();
|
||||
render(<AgentPanel agents={mockAgents} onManageAgents={onManageAgents} />);
|
||||
|
||||
await user.click(screen.getByText('Manage Agents'));
|
||||
expect(onManageAgents).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('shows action menu when actions are provided', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onAgentAction = jest.fn();
|
||||
render(<AgentPanel agents={mockAgents} onAgentAction={onAgentAction} />);
|
||||
|
||||
const agentItem = screen.getByTestId('agent-item-agent-001');
|
||||
const menuButton = within(agentItem).getByRole('button', {
|
||||
name: /actions for product owner/i,
|
||||
});
|
||||
|
||||
await user.click(menuButton);
|
||||
expect(screen.getByText('View Details')).toBeInTheDocument();
|
||||
expect(screen.getByText('Pause Agent')).toBeInTheDocument();
|
||||
expect(screen.getByText('Terminate Agent')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onAgentAction with correct params when action is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onAgentAction = jest.fn();
|
||||
render(<AgentPanel agents={mockAgents} onAgentAction={onAgentAction} />);
|
||||
|
||||
const agentItem = screen.getByTestId('agent-item-agent-001');
|
||||
const menuButton = within(agentItem).getByRole('button', {
|
||||
name: /actions for product owner/i,
|
||||
});
|
||||
|
||||
await user.click(menuButton);
|
||||
await user.click(screen.getByText('View Details'));
|
||||
|
||||
expect(onAgentAction).toHaveBeenCalledWith('agent-001', 'view');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<AgentPanel agents={mockAgents} className="custom-class" />);
|
||||
expect(screen.getByTestId('agent-panel')).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('shows avatar initials for agent', () => {
|
||||
render(<AgentPanel agents={mockAgents} />);
|
||||
expect(screen.getByText('PO')).toBeInTheDocument();
|
||||
// Backend Engineer should have generated initials "BE"
|
||||
expect(screen.getByText('BE')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { AgentStatusIndicator } from '@/components/projects/AgentStatusIndicator';
|
||||
|
||||
describe('AgentStatusIndicator', () => {
|
||||
it('renders idle status with correct color', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="idle" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('bg-yellow-500');
|
||||
});
|
||||
|
||||
it('renders active status with correct color', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="active" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('bg-green-500');
|
||||
});
|
||||
|
||||
it('renders working status with animation', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="working" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('bg-green-500');
|
||||
expect(indicator).toHaveClass('animate-pulse');
|
||||
});
|
||||
|
||||
it('renders pending status with correct color', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="pending" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('bg-gray-400');
|
||||
});
|
||||
|
||||
it('renders error status with correct color', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="error" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('bg-red-500');
|
||||
});
|
||||
|
||||
it('renders terminated status with correct color', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="terminated" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('bg-gray-600');
|
||||
});
|
||||
|
||||
it('applies small size by default', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="active" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('h-2', 'w-2');
|
||||
});
|
||||
|
||||
it('applies medium size when specified', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="active" size="md" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('h-3', 'w-3');
|
||||
});
|
||||
|
||||
it('applies large size when specified', () => {
|
||||
const { container } = render(<AgentStatusIndicator status="active" size="lg" />);
|
||||
const indicator = container.querySelector('span > span');
|
||||
expect(indicator).toHaveClass('h-4', 'w-4');
|
||||
});
|
||||
|
||||
it('shows label when showLabel is true', () => {
|
||||
render(<AgentStatusIndicator status="active" showLabel />);
|
||||
expect(screen.getByText('Active')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show label by default', () => {
|
||||
render(<AgentStatusIndicator status="active" />);
|
||||
expect(screen.queryByText('Active')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('has accessible status role and label', () => {
|
||||
render(<AgentStatusIndicator status="active" />);
|
||||
expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'Status: Active');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<AgentStatusIndicator status="active" className="custom-class" />
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
81
frontend/tests/components/projects/IssueSummary.test.tsx
Normal file
81
frontend/tests/components/projects/IssueSummary.test.tsx
Normal file
@@ -0,0 +1,81 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IssueSummary } from '@/components/projects/IssueSummary';
|
||||
import type { IssueSummary as IssueSummaryType } from '@/components/projects/types';
|
||||
|
||||
const mockSummary: IssueSummaryType = {
|
||||
open: 12,
|
||||
in_progress: 8,
|
||||
in_review: 3,
|
||||
blocked: 2,
|
||||
done: 45,
|
||||
total: 70,
|
||||
};
|
||||
|
||||
describe('IssueSummary', () => {
|
||||
it('renders issue summary with title', () => {
|
||||
render(<IssueSummary summary={mockSummary} />);
|
||||
expect(screen.getByText('Issue Summary')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays all status counts', () => {
|
||||
render(<IssueSummary summary={mockSummary} />);
|
||||
|
||||
expect(screen.getByText('Open')).toBeInTheDocument();
|
||||
expect(screen.getByText('12')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('In Progress')).toBeInTheDocument();
|
||||
expect(screen.getByText('8')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('In Review')).toBeInTheDocument();
|
||||
expect(screen.getByText('3')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Blocked')).toBeInTheDocument();
|
||||
expect(screen.getByText('2')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Completed')).toBeInTheDocument();
|
||||
expect(screen.getByText('45')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders empty state when summary is null', () => {
|
||||
render(<IssueSummary summary={null} />);
|
||||
expect(screen.getByText('No issues found')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows loading skeleton when isLoading is true', () => {
|
||||
const { container } = render(<IssueSummary summary={null} isLoading />);
|
||||
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('shows View All Issues button with total count', () => {
|
||||
const onViewAllIssues = jest.fn();
|
||||
render(<IssueSummary summary={mockSummary} onViewAllIssues={onViewAllIssues} />);
|
||||
|
||||
expect(screen.getByRole('button', { name: /view all issues/i })).toBeInTheDocument();
|
||||
expect(screen.getByText('View All Issues (70)')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onViewAllIssues when button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onViewAllIssues = jest.fn();
|
||||
render(<IssueSummary summary={mockSummary} onViewAllIssues={onViewAllIssues} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /view all issues/i }));
|
||||
expect(onViewAllIssues).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not show View All button when onViewAllIssues is not provided', () => {
|
||||
render(<IssueSummary summary={mockSummary} />);
|
||||
expect(screen.queryByRole('button', { name: /view all issues/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<IssueSummary summary={mockSummary} className="custom-class" />);
|
||||
expect(screen.getByTestId('issue-summary')).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('has accessible list role for status items', () => {
|
||||
render(<IssueSummary summary={mockSummary} />);
|
||||
expect(screen.getByRole('list', { name: /issue counts by status/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
92
frontend/tests/components/projects/ProgressBar.test.tsx
Normal file
92
frontend/tests/components/projects/ProgressBar.test.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { ProgressBar } from '@/components/projects/ProgressBar';
|
||||
|
||||
describe('ProgressBar', () => {
|
||||
it('renders with correct progress value', () => {
|
||||
render(<ProgressBar value={50} />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveAttribute('aria-valuenow', '50');
|
||||
expect(progressbar).toHaveAttribute('aria-valuemin', '0');
|
||||
expect(progressbar).toHaveAttribute('aria-valuemax', '100');
|
||||
});
|
||||
|
||||
it('renders with correct accessible label', () => {
|
||||
render(<ProgressBar value={75} />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveAttribute('aria-label', 'Progress: 75%');
|
||||
});
|
||||
|
||||
it('clamps value to 0-100 range', () => {
|
||||
const { rerender } = render(<ProgressBar value={150} />);
|
||||
let progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveAttribute('aria-valuenow', '100');
|
||||
|
||||
rerender(<ProgressBar value={-50} />);
|
||||
progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveAttribute('aria-valuenow', '0');
|
||||
});
|
||||
|
||||
it('applies small size class when specified', () => {
|
||||
render(<ProgressBar value={50} size="sm" />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveClass('h-1');
|
||||
});
|
||||
|
||||
it('applies default size class', () => {
|
||||
render(<ProgressBar value={50} />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveClass('h-2');
|
||||
});
|
||||
|
||||
it('applies large size class when specified', () => {
|
||||
render(<ProgressBar value={50} size="lg" />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveClass('h-3');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(<ProgressBar value={50} className="custom-class" />);
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('shows label when showLabel is true', () => {
|
||||
render(<ProgressBar value={75} showLabel />);
|
||||
expect(screen.getByText('Progress')).toBeInTheDocument();
|
||||
expect(screen.getByText('75%')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show label by default', () => {
|
||||
render(<ProgressBar value={75} />);
|
||||
expect(screen.queryByText('Progress')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies default variant styles', () => {
|
||||
const { container } = render(<ProgressBar value={50} />);
|
||||
const bar = container.querySelector('[style*="width"]');
|
||||
expect(bar).toHaveClass('bg-primary');
|
||||
});
|
||||
|
||||
it('applies success variant styles', () => {
|
||||
const { container } = render(<ProgressBar value={50} variant="success" />);
|
||||
const bar = container.querySelector('[style*="width"]');
|
||||
expect(bar).toHaveClass('bg-green-500');
|
||||
});
|
||||
|
||||
it('applies warning variant styles', () => {
|
||||
const { container } = render(<ProgressBar value={50} variant="warning" />);
|
||||
const bar = container.querySelector('[style*="width"]');
|
||||
expect(bar).toHaveClass('bg-yellow-500');
|
||||
});
|
||||
|
||||
it('applies error variant styles', () => {
|
||||
const { container } = render(<ProgressBar value={50} variant="error" />);
|
||||
const bar = container.querySelector('[style*="width"]');
|
||||
expect(bar).toHaveClass('bg-red-500');
|
||||
});
|
||||
|
||||
it('uses custom aria-label when provided', () => {
|
||||
render(<ProgressBar value={50} aria-label="Custom label" />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveAttribute('aria-label', 'Custom label');
|
||||
});
|
||||
});
|
||||
145
frontend/tests/components/projects/ProjectHeader.test.tsx
Normal file
145
frontend/tests/components/projects/ProjectHeader.test.tsx
Normal file
@@ -0,0 +1,145 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { ProjectHeader } from '@/components/projects/ProjectHeader';
|
||||
import type { Project } from '@/components/projects/types';
|
||||
|
||||
const mockProject: Project = {
|
||||
id: 'proj-001',
|
||||
name: 'Test Project',
|
||||
description: 'A test project for unit testing',
|
||||
status: 'in_progress',
|
||||
autonomy_level: 'milestone',
|
||||
created_at: '2025-01-15T00:00:00Z',
|
||||
owner_id: 'user-001',
|
||||
};
|
||||
|
||||
describe('ProjectHeader', () => {
|
||||
it('renders project name', () => {
|
||||
render(<ProjectHeader project={mockProject} />);
|
||||
expect(screen.getByText('Test Project')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders project description', () => {
|
||||
render(<ProjectHeader project={mockProject} />);
|
||||
expect(screen.getByText('A test project for unit testing')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders project status badge', () => {
|
||||
render(<ProjectHeader project={mockProject} />);
|
||||
expect(screen.getByText('In Progress')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders autonomy level badge', () => {
|
||||
render(<ProjectHeader project={mockProject} />);
|
||||
expect(screen.getByText('Milestone')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders nothing when project is null', () => {
|
||||
const { container } = render(<ProjectHeader project={null} />);
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it('shows loading skeleton when isLoading is true', () => {
|
||||
const { container } = render(<ProjectHeader project={null} isLoading />);
|
||||
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('shows pause button when canPause is true and project is in_progress', () => {
|
||||
const onPauseProject = jest.fn();
|
||||
render(
|
||||
<ProjectHeader
|
||||
project={mockProject}
|
||||
canPause={true}
|
||||
onPauseProject={onPauseProject}
|
||||
/>
|
||||
);
|
||||
expect(screen.getByRole('button', { name: /pause project/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show pause button when project is not in_progress', () => {
|
||||
const completedProject = { ...mockProject, status: 'completed' as const };
|
||||
render(<ProjectHeader project={completedProject} canPause={true} />);
|
||||
expect(screen.queryByRole('button', { name: /pause project/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows run sprint button when canStart is true', () => {
|
||||
const onStartSprint = jest.fn();
|
||||
render(
|
||||
<ProjectHeader
|
||||
project={mockProject}
|
||||
canStart={true}
|
||||
onStartSprint={onStartSprint}
|
||||
/>
|
||||
);
|
||||
expect(screen.getByRole('button', { name: /run sprint/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show run sprint button when project is completed', () => {
|
||||
const completedProject = { ...mockProject, status: 'completed' as const };
|
||||
render(<ProjectHeader project={completedProject} canStart={true} />);
|
||||
expect(screen.queryByRole('button', { name: /run sprint/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onStartSprint when run sprint button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onStartSprint = jest.fn();
|
||||
render(
|
||||
<ProjectHeader
|
||||
project={mockProject}
|
||||
canStart={true}
|
||||
onStartSprint={onStartSprint}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /run sprint/i }));
|
||||
expect(onStartSprint).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onPauseProject when pause button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onPauseProject = jest.fn();
|
||||
render(
|
||||
<ProjectHeader
|
||||
project={mockProject}
|
||||
canPause={true}
|
||||
onPauseProject={onPauseProject}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /pause project/i }));
|
||||
expect(onPauseProject).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onCreateSprint when new sprint button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onCreateSprint = jest.fn();
|
||||
render(
|
||||
<ProjectHeader
|
||||
project={mockProject}
|
||||
onCreateSprint={onCreateSprint}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /new sprint/i }));
|
||||
expect(onCreateSprint).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onSettings when settings button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onSettings = jest.fn();
|
||||
render(
|
||||
<ProjectHeader
|
||||
project={mockProject}
|
||||
onSettings={onSettings}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /project settings/i }));
|
||||
expect(onSettings).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<ProjectHeader project={mockProject} className="custom-class" />);
|
||||
expect(screen.getByTestId('project-header')).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
147
frontend/tests/components/projects/RecentActivity.test.tsx
Normal file
147
frontend/tests/components/projects/RecentActivity.test.tsx
Normal file
@@ -0,0 +1,147 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { RecentActivity } from '@/components/projects/RecentActivity';
|
||||
import type { ActivityItem } from '@/components/projects/types';
|
||||
|
||||
const mockActivities: ActivityItem[] = [
|
||||
{
|
||||
id: 'act-001',
|
||||
type: 'agent_message',
|
||||
agent: 'Product Owner',
|
||||
message: 'Approved user story #42',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
id: 'act-002',
|
||||
type: 'issue_update',
|
||||
agent: 'Backend Engineer',
|
||||
message: 'Moved issue #38 to review',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
id: 'act-003',
|
||||
type: 'approval_request',
|
||||
agent: 'Architect',
|
||||
message: 'Requesting API design approval',
|
||||
timestamp: new Date().toISOString(),
|
||||
requires_action: true,
|
||||
},
|
||||
];
|
||||
|
||||
describe('RecentActivity', () => {
|
||||
it('renders recent activity with title', () => {
|
||||
render(<RecentActivity activities={mockActivities} />);
|
||||
expect(screen.getByText('Recent Activity')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays all activities', () => {
|
||||
render(<RecentActivity activities={mockActivities} />);
|
||||
expect(screen.getByText('Product Owner')).toBeInTheDocument();
|
||||
expect(screen.getByText('Approved user story #42')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Backend Engineer')).toBeInTheDocument();
|
||||
expect(screen.getByText('Moved issue #38 to review')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Architect')).toBeInTheDocument();
|
||||
expect(screen.getByText('Requesting API design approval')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders empty state when no activities', () => {
|
||||
render(<RecentActivity activities={[]} />);
|
||||
expect(screen.getByText('No recent activity')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows loading skeleton when isLoading is true', () => {
|
||||
const { container } = render(<RecentActivity activities={[]} isLoading />);
|
||||
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('respects maxItems prop', () => {
|
||||
render(<RecentActivity activities={mockActivities} maxItems={2} />);
|
||||
expect(screen.getByText('Product Owner')).toBeInTheDocument();
|
||||
expect(screen.getByText('Backend Engineer')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Architect')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows View All button when there are more activities than maxItems', () => {
|
||||
const onViewAll = jest.fn();
|
||||
render(
|
||||
<RecentActivity
|
||||
activities={mockActivities}
|
||||
maxItems={2}
|
||||
onViewAll={onViewAll}
|
||||
/>
|
||||
);
|
||||
expect(screen.getByRole('button', { name: /view all/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show View All button when all activities are shown', () => {
|
||||
const onViewAll = jest.fn();
|
||||
render(
|
||||
<RecentActivity
|
||||
activities={mockActivities}
|
||||
maxItems={5}
|
||||
onViewAll={onViewAll}
|
||||
/>
|
||||
);
|
||||
expect(screen.queryByRole('button', { name: /view all/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onViewAll when View All button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onViewAll = jest.fn();
|
||||
render(
|
||||
<RecentActivity
|
||||
activities={mockActivities}
|
||||
maxItems={2}
|
||||
onViewAll={onViewAll}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /view all/i }));
|
||||
expect(onViewAll).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('shows Review Request button for items requiring action', () => {
|
||||
const onActionClick = jest.fn();
|
||||
render(
|
||||
<RecentActivity
|
||||
activities={mockActivities}
|
||||
onActionClick={onActionClick}
|
||||
/>
|
||||
);
|
||||
expect(screen.getByRole('button', { name: /review request/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onActionClick when Review Request button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onActionClick = jest.fn();
|
||||
render(
|
||||
<RecentActivity
|
||||
activities={mockActivities}
|
||||
onActionClick={onActionClick}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /review request/i }));
|
||||
expect(onActionClick).toHaveBeenCalledWith('act-003');
|
||||
});
|
||||
|
||||
it('highlights activities requiring action', () => {
|
||||
render(<RecentActivity activities={mockActivities} />);
|
||||
|
||||
const activityItem = screen.getByTestId('activity-item-act-003');
|
||||
const iconContainer = activityItem.querySelector('.bg-yellow-100');
|
||||
expect(iconContainer).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<RecentActivity activities={mockActivities} className="custom-class" />);
|
||||
expect(screen.getByTestId('recent-activity')).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('has accessible list role', () => {
|
||||
render(<RecentActivity activities={mockActivities} />);
|
||||
expect(screen.getByRole('list', { name: /recent project activity/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
132
frontend/tests/components/projects/SprintProgress.test.tsx
Normal file
132
frontend/tests/components/projects/SprintProgress.test.tsx
Normal file
@@ -0,0 +1,132 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { SprintProgress } from '@/components/projects/SprintProgress';
|
||||
import type { Sprint, BurndownDataPoint } from '@/components/projects/types';
|
||||
|
||||
const mockSprint: Sprint = {
|
||||
id: 'sprint-001',
|
||||
project_id: 'proj-001',
|
||||
name: 'Sprint 3',
|
||||
goal: 'Complete checkout flow',
|
||||
status: 'active',
|
||||
start_date: '2025-01-27',
|
||||
end_date: '2025-02-10',
|
||||
total_issues: 15,
|
||||
completed_issues: 8,
|
||||
in_progress_issues: 4,
|
||||
blocked_issues: 1,
|
||||
todo_issues: 2,
|
||||
};
|
||||
|
||||
const mockBurndownData: BurndownDataPoint[] = [
|
||||
{ day: 1, remaining: 45, ideal: 45 },
|
||||
{ day: 2, remaining: 42, ideal: 42 },
|
||||
{ day: 3, remaining: 38, ideal: 39 },
|
||||
{ day: 4, remaining: 35, ideal: 36 },
|
||||
{ day: 5, remaining: 30, ideal: 33 },
|
||||
];
|
||||
|
||||
describe('SprintProgress', () => {
|
||||
it('renders sprint progress with title', () => {
|
||||
render(<SprintProgress sprint={mockSprint} />);
|
||||
expect(screen.getByText('Sprint Overview')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays sprint name and date range', () => {
|
||||
render(<SprintProgress sprint={mockSprint} />);
|
||||
expect(screen.getByText(/Sprint 3/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Jan 27 - Feb 10, 2025/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows progress percentage', () => {
|
||||
render(<SprintProgress sprint={mockSprint} />);
|
||||
// 8/15 = 53%
|
||||
expect(screen.getByText('53%')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays issue statistics', () => {
|
||||
render(<SprintProgress sprint={mockSprint} />);
|
||||
|
||||
expect(screen.getByText('Completed')).toBeInTheDocument();
|
||||
expect(screen.getByText('8')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('In Progress')).toBeInTheDocument();
|
||||
expect(screen.getByText('4')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Blocked')).toBeInTheDocument();
|
||||
expect(screen.getByText('1')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('To Do')).toBeInTheDocument();
|
||||
expect(screen.getByText('2')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders empty state when sprint is null', () => {
|
||||
render(<SprintProgress sprint={null} />);
|
||||
expect(screen.getByText('No active sprint')).toBeInTheDocument();
|
||||
expect(screen.getByText('No sprint is currently active')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows loading skeleton when isLoading is true', () => {
|
||||
const { container } = render(<SprintProgress sprint={null} isLoading />);
|
||||
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('renders burndown chart when data is provided', () => {
|
||||
render(<SprintProgress sprint={mockSprint} burndownData={mockBurndownData} />);
|
||||
expect(screen.getByText('Burndown Chart')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows sprint selector when multiple sprints are available', () => {
|
||||
const availableSprints = [
|
||||
{ id: 'sprint-001', name: 'Sprint 3' },
|
||||
{ id: 'sprint-002', name: 'Sprint 2' },
|
||||
];
|
||||
const onSprintChange = jest.fn();
|
||||
|
||||
render(
|
||||
<SprintProgress
|
||||
sprint={mockSprint}
|
||||
availableSprints={availableSprints}
|
||||
selectedSprintId="sprint-001"
|
||||
onSprintChange={onSprintChange}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('combobox', { name: /select sprint/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Note: Radix Select doesn't work well with jsdom. Skipping interactive test.
|
||||
// This would need to be tested in E2E tests with Playwright.
|
||||
it.skip('calls onSprintChange when sprint is selected', async () => {
|
||||
const user = userEvent.setup();
|
||||
const availableSprints = [
|
||||
{ id: 'sprint-001', name: 'Sprint 3' },
|
||||
{ id: 'sprint-002', name: 'Sprint 2' },
|
||||
];
|
||||
const onSprintChange = jest.fn();
|
||||
|
||||
render(
|
||||
<SprintProgress
|
||||
sprint={mockSprint}
|
||||
availableSprints={availableSprints}
|
||||
selectedSprintId="sprint-001"
|
||||
onSprintChange={onSprintChange}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: /select sprint/i }));
|
||||
await user.click(screen.getByText('Sprint 2'));
|
||||
|
||||
expect(onSprintChange).toHaveBeenCalledWith('sprint-002');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<SprintProgress sprint={mockSprint} className="custom-class" />);
|
||||
expect(screen.getByTestId('sprint-progress')).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('has accessible list role for issue statistics', () => {
|
||||
render(<SprintProgress sprint={mockSprint} />);
|
||||
expect(screen.getByRole('list', { name: /sprint issue statistics/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
72
frontend/tests/components/projects/StatusBadge.test.tsx
Normal file
72
frontend/tests/components/projects/StatusBadge.test.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { ProjectStatusBadge, AutonomyBadge } from '@/components/projects/StatusBadge';
|
||||
|
||||
describe('ProjectStatusBadge', () => {
|
||||
it('renders in_progress status correctly', () => {
|
||||
render(<ProjectStatusBadge status="in_progress" />);
|
||||
expect(screen.getByText('In Progress')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders completed status correctly', () => {
|
||||
render(<ProjectStatusBadge status="completed" />);
|
||||
expect(screen.getByText('Completed')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders blocked status correctly', () => {
|
||||
render(<ProjectStatusBadge status="blocked" />);
|
||||
expect(screen.getByText('Blocked')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders paused status correctly', () => {
|
||||
render(<ProjectStatusBadge status="paused" />);
|
||||
expect(screen.getByText('Paused')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders draft status correctly', () => {
|
||||
render(<ProjectStatusBadge status="draft" />);
|
||||
expect(screen.getByText('Draft')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders archived status correctly', () => {
|
||||
render(<ProjectStatusBadge status="archived" />);
|
||||
expect(screen.getByText('Archived')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<ProjectStatusBadge status="in_progress" className="custom-class" />
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
|
||||
describe('AutonomyBadge', () => {
|
||||
it('renders full_control level correctly', () => {
|
||||
render(<AutonomyBadge level="full_control" />);
|
||||
expect(screen.getByText('Full Control')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders milestone level correctly', () => {
|
||||
render(<AutonomyBadge level="milestone" />);
|
||||
expect(screen.getByText('Milestone')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders autonomous level correctly', () => {
|
||||
render(<AutonomyBadge level="autonomous" />);
|
||||
expect(screen.getByText('Autonomous')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('has title attribute with description', () => {
|
||||
render(<AutonomyBadge level="milestone" />);
|
||||
// The Badge component is the closest ancestor with the title
|
||||
const badge = screen.getByText('Milestone').closest('[title]');
|
||||
expect(badge).toHaveAttribute('title', 'Approve at sprint boundaries');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<AutonomyBadge level="milestone" className="custom-class" />
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Tests for SelectableCard component
|
||||
*/
|
||||
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { SelectableCard } from '@/components/projects/wizard/SelectableCard';
|
||||
|
||||
describe('SelectableCard', () => {
|
||||
const defaultProps = {
|
||||
selected: false,
|
||||
onClick: jest.fn(),
|
||||
children: <span>Card Content</span>,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('renders children', () => {
|
||||
render(<SelectableCard {...defaultProps} />);
|
||||
expect(screen.getByText('Card Content')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onClick when clicked', () => {
|
||||
render(<SelectableCard {...defaultProps} />);
|
||||
fireEvent.click(screen.getByRole('button'));
|
||||
expect(defaultProps.onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('has aria-pressed false when not selected', () => {
|
||||
render(<SelectableCard {...defaultProps} />);
|
||||
expect(screen.getByRole('button')).toHaveAttribute('aria-pressed', 'false');
|
||||
});
|
||||
|
||||
it('has aria-pressed true when selected', () => {
|
||||
render(<SelectableCard {...defaultProps} selected={true} />);
|
||||
expect(screen.getByRole('button')).toHaveAttribute('aria-pressed', 'true');
|
||||
});
|
||||
|
||||
it('applies custom aria-label', () => {
|
||||
render(<SelectableCard {...defaultProps} aria-label="Select option A" />);
|
||||
expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'Select option A');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<SelectableCard {...defaultProps} className="my-custom-class" />);
|
||||
expect(screen.getByRole('button')).toHaveClass('my-custom-class');
|
||||
});
|
||||
|
||||
it('applies selected styles when selected', () => {
|
||||
const { rerender } = render(<SelectableCard {...defaultProps} />);
|
||||
const button = screen.getByRole('button');
|
||||
|
||||
expect(button).toHaveClass('border-border');
|
||||
expect(button).not.toHaveClass('border-primary');
|
||||
|
||||
rerender(<SelectableCard {...defaultProps} selected={true} />);
|
||||
expect(button).toHaveClass('border-primary');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Tests for StepIndicator component
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { StepIndicator } from '@/components/projects/wizard/StepIndicator';
|
||||
|
||||
describe('StepIndicator', () => {
|
||||
describe('non-script mode (6 steps)', () => {
|
||||
it('renders correct step count', () => {
|
||||
render(<StepIndicator currentStep={1} isScriptMode={false} />);
|
||||
expect(screen.getByText('Step 1 of 6')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows correct step label for each step', () => {
|
||||
const { rerender } = render(<StepIndicator currentStep={1} isScriptMode={false} />);
|
||||
expect(screen.getByText('Basic Info')).toBeInTheDocument();
|
||||
|
||||
rerender(<StepIndicator currentStep={2} isScriptMode={false} />);
|
||||
expect(screen.getByText('Complexity')).toBeInTheDocument();
|
||||
|
||||
rerender(<StepIndicator currentStep={3} isScriptMode={false} />);
|
||||
expect(screen.getByText('Client Mode')).toBeInTheDocument();
|
||||
|
||||
rerender(<StepIndicator currentStep={4} isScriptMode={false} />);
|
||||
expect(screen.getByText('Autonomy')).toBeInTheDocument();
|
||||
|
||||
rerender(<StepIndicator currentStep={5} isScriptMode={false} />);
|
||||
expect(screen.getByText('Agent Chat')).toBeInTheDocument();
|
||||
|
||||
rerender(<StepIndicator currentStep={6} isScriptMode={false} />);
|
||||
expect(screen.getByText('Review')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders 6 progress segments', () => {
|
||||
render(<StepIndicator currentStep={3} isScriptMode={false} />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toBeInTheDocument();
|
||||
expect(progressbar).toHaveAttribute('aria-valuenow', '3');
|
||||
expect(progressbar).toHaveAttribute('aria-valuemax', '6');
|
||||
});
|
||||
});
|
||||
|
||||
describe('script mode (4 steps)', () => {
|
||||
it('renders correct step count', () => {
|
||||
render(<StepIndicator currentStep={1} isScriptMode={true} />);
|
||||
expect(screen.getByText('Step 1 of 4')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows correct step labels (no Client Mode or Autonomy)', () => {
|
||||
const { rerender } = render(<StepIndicator currentStep={1} isScriptMode={true} />);
|
||||
expect(screen.getByText('Basic Info')).toBeInTheDocument();
|
||||
|
||||
rerender(<StepIndicator currentStep={2} isScriptMode={true} />);
|
||||
expect(screen.getByText('Complexity')).toBeInTheDocument();
|
||||
|
||||
// Step 5 (Agent Chat) maps to display step 3
|
||||
rerender(<StepIndicator currentStep={5} isScriptMode={true} />);
|
||||
expect(screen.getByText('Step 3 of 4')).toBeInTheDocument();
|
||||
expect(screen.getByText('Agent Chat')).toBeInTheDocument();
|
||||
|
||||
// Step 6 (Review) maps to display step 4
|
||||
rerender(<StepIndicator currentStep={6} isScriptMode={true} />);
|
||||
expect(screen.getByText('Step 4 of 4')).toBeInTheDocument();
|
||||
expect(screen.getByText('Review')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders 4 progress segments', () => {
|
||||
render(<StepIndicator currentStep={5} isScriptMode={true} />);
|
||||
const progressbar = screen.getByRole('progressbar');
|
||||
expect(progressbar).toHaveAttribute('aria-valuemax', '4');
|
||||
});
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<StepIndicator currentStep={1} isScriptMode={false} className="my-custom-class" />
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('my-custom-class');
|
||||
});
|
||||
});
|
||||
154
frontend/tests/components/projects/wizard/constants.test.ts
Normal file
154
frontend/tests/components/projects/wizard/constants.test.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Tests for wizard constants and utility functions
|
||||
*/
|
||||
|
||||
import {
|
||||
complexityOptions,
|
||||
clientModeOptions,
|
||||
autonomyOptions,
|
||||
getTotalSteps,
|
||||
getStepLabels,
|
||||
getDisplayStep,
|
||||
WIZARD_STEPS,
|
||||
} from '@/components/projects/wizard/constants';
|
||||
|
||||
describe('complexityOptions', () => {
|
||||
it('has 4 options', () => {
|
||||
expect(complexityOptions).toHaveLength(4);
|
||||
});
|
||||
|
||||
it('includes script with skipConfig: true', () => {
|
||||
const script = complexityOptions.find((o) => o.id === 'script');
|
||||
expect(script).toBeDefined();
|
||||
expect(script?.skipConfig).toBe(true);
|
||||
});
|
||||
|
||||
it('has other options with skipConfig: false', () => {
|
||||
const others = complexityOptions.filter((o) => o.id !== 'script');
|
||||
expect(others.every((o) => o.skipConfig === false)).toBe(true);
|
||||
});
|
||||
|
||||
it('has correct timelines', () => {
|
||||
const script = complexityOptions.find((o) => o.id === 'script');
|
||||
const simple = complexityOptions.find((o) => o.id === 'simple');
|
||||
const medium = complexityOptions.find((o) => o.id === 'medium');
|
||||
const complex = complexityOptions.find((o) => o.id === 'complex');
|
||||
|
||||
expect(script?.scope).toContain('Minutes to 1-2 hours');
|
||||
expect(simple?.scope).toContain('2-3 days');
|
||||
expect(medium?.scope).toContain('2-3 weeks');
|
||||
expect(complex?.scope).toContain('2-3 months');
|
||||
});
|
||||
});
|
||||
|
||||
describe('clientModeOptions', () => {
|
||||
it('has 2 options', () => {
|
||||
expect(clientModeOptions).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('includes technical and auto modes', () => {
|
||||
const ids = clientModeOptions.map((o) => o.id);
|
||||
expect(ids).toContain('technical');
|
||||
expect(ids).toContain('auto');
|
||||
});
|
||||
});
|
||||
|
||||
describe('autonomyOptions', () => {
|
||||
it('has 3 options', () => {
|
||||
expect(autonomyOptions).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('includes all autonomy levels', () => {
|
||||
const ids = autonomyOptions.map((o) => o.id);
|
||||
expect(ids).toContain('full_control');
|
||||
expect(ids).toContain('milestone');
|
||||
expect(ids).toContain('autonomous');
|
||||
});
|
||||
|
||||
it('has valid approval matrices', () => {
|
||||
autonomyOptions.forEach((option) => {
|
||||
expect(option.approvals).toHaveProperty('codeChanges');
|
||||
expect(option.approvals).toHaveProperty('issueUpdates');
|
||||
expect(option.approvals).toHaveProperty('architectureDecisions');
|
||||
expect(option.approvals).toHaveProperty('sprintPlanning');
|
||||
expect(option.approvals).toHaveProperty('deployments');
|
||||
});
|
||||
});
|
||||
|
||||
it('full_control requires all approvals', () => {
|
||||
const fullControl = autonomyOptions.find((o) => o.id === 'full_control');
|
||||
expect(Object.values(fullControl!.approvals).every(Boolean)).toBe(true);
|
||||
});
|
||||
|
||||
it('autonomous only requires architecture and deployments', () => {
|
||||
const autonomous = autonomyOptions.find((o) => o.id === 'autonomous');
|
||||
expect(autonomous!.approvals.codeChanges).toBe(false);
|
||||
expect(autonomous!.approvals.issueUpdates).toBe(false);
|
||||
expect(autonomous!.approvals.architectureDecisions).toBe(true);
|
||||
expect(autonomous!.approvals.sprintPlanning).toBe(false);
|
||||
expect(autonomous!.approvals.deployments).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTotalSteps', () => {
|
||||
it('returns 6 for non-script mode', () => {
|
||||
expect(getTotalSteps(false)).toBe(6);
|
||||
});
|
||||
|
||||
it('returns 4 for script mode', () => {
|
||||
expect(getTotalSteps(true)).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStepLabels', () => {
|
||||
it('returns 6 labels for non-script mode', () => {
|
||||
const labels = getStepLabels(false);
|
||||
expect(labels).toHaveLength(6);
|
||||
expect(labels).toEqual([
|
||||
'Basic Info',
|
||||
'Complexity',
|
||||
'Client Mode',
|
||||
'Autonomy',
|
||||
'Agent Chat',
|
||||
'Review',
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 4 labels for script mode (no Client Mode or Autonomy)', () => {
|
||||
const labels = getStepLabels(true);
|
||||
expect(labels).toHaveLength(4);
|
||||
expect(labels).toEqual(['Basic Info', 'Complexity', 'Agent Chat', 'Review']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDisplayStep', () => {
|
||||
it('returns actual step for non-script mode', () => {
|
||||
expect(getDisplayStep(1, false)).toBe(1);
|
||||
expect(getDisplayStep(2, false)).toBe(2);
|
||||
expect(getDisplayStep(3, false)).toBe(3);
|
||||
expect(getDisplayStep(4, false)).toBe(4);
|
||||
expect(getDisplayStep(5, false)).toBe(5);
|
||||
expect(getDisplayStep(6, false)).toBe(6);
|
||||
});
|
||||
|
||||
it('maps steps correctly for script mode', () => {
|
||||
// Steps 1 and 2 stay the same
|
||||
expect(getDisplayStep(1, true)).toBe(1);
|
||||
expect(getDisplayStep(2, true)).toBe(2);
|
||||
// Step 5 (Agent Chat) becomes display step 3
|
||||
expect(getDisplayStep(5, true)).toBe(3);
|
||||
// Step 6 (Review) becomes display step 4
|
||||
expect(getDisplayStep(6, true)).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('WIZARD_STEPS', () => {
|
||||
it('has correct step numbers', () => {
|
||||
expect(WIZARD_STEPS.BASIC_INFO).toBe(1);
|
||||
expect(WIZARD_STEPS.COMPLEXITY).toBe(2);
|
||||
expect(WIZARD_STEPS.CLIENT_MODE).toBe(3);
|
||||
expect(WIZARD_STEPS.AUTONOMY).toBe(4);
|
||||
expect(WIZARD_STEPS.AGENT_CHAT).toBe(5);
|
||||
expect(WIZARD_STEPS.REVIEW).toBe(6);
|
||||
});
|
||||
});
|
||||
357
frontend/tests/components/projects/wizard/useWizardState.test.ts
Normal file
357
frontend/tests/components/projects/wizard/useWizardState.test.ts
Normal file
@@ -0,0 +1,357 @@
|
||||
/**
|
||||
* Tests for useWizardState hook
|
||||
*/
|
||||
|
||||
import { renderHook, act } from '@testing-library/react';
|
||||
import { useWizardState } from '@/components/projects/wizard/useWizardState';
|
||||
import { WIZARD_STEPS } from '@/components/projects/wizard/constants';
|
||||
|
||||
describe('useWizardState', () => {
|
||||
describe('initial state', () => {
|
||||
it('starts at step 1', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
expect(result.current.state.step).toBe(1);
|
||||
});
|
||||
|
||||
it('has empty form fields', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
expect(result.current.state.projectName).toBe('');
|
||||
expect(result.current.state.description).toBe('');
|
||||
expect(result.current.state.repoUrl).toBe('');
|
||||
});
|
||||
|
||||
it('has null selections', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
expect(result.current.state.complexity).toBeNull();
|
||||
expect(result.current.state.clientMode).toBeNull();
|
||||
expect(result.current.state.autonomyLevel).toBeNull();
|
||||
});
|
||||
|
||||
it('is not in script mode', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
expect(result.current.isScriptMode).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateState', () => {
|
||||
it('updates project name', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
act(() => {
|
||||
result.current.updateState({ projectName: 'Test Project' });
|
||||
});
|
||||
expect(result.current.state.projectName).toBe('Test Project');
|
||||
});
|
||||
|
||||
it('updates multiple fields at once', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test',
|
||||
description: 'A test project',
|
||||
});
|
||||
});
|
||||
expect(result.current.state.projectName).toBe('Test');
|
||||
expect(result.current.state.description).toBe('A test project');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resetState', () => {
|
||||
it('resets to initial state', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
// Make some changes
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test',
|
||||
complexity: 'medium',
|
||||
step: 3,
|
||||
});
|
||||
});
|
||||
|
||||
// Reset
|
||||
act(() => {
|
||||
result.current.resetState();
|
||||
});
|
||||
|
||||
expect(result.current.state.projectName).toBe('');
|
||||
expect(result.current.state.complexity).toBeNull();
|
||||
expect(result.current.state.step).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canProceed', () => {
|
||||
it('requires project name at least 3 chars for step 1', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
expect(result.current.canProceed).toBe(false);
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ projectName: 'AB' });
|
||||
});
|
||||
expect(result.current.canProceed).toBe(false);
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ projectName: 'ABC' });
|
||||
});
|
||||
expect(result.current.canProceed).toBe(true);
|
||||
});
|
||||
|
||||
it('requires complexity selection for step 2', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
// Move to step 2
|
||||
act(() => {
|
||||
result.current.updateState({ projectName: 'Test', step: 2 });
|
||||
});
|
||||
|
||||
expect(result.current.canProceed).toBe(false);
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ complexity: 'medium' });
|
||||
});
|
||||
expect(result.current.canProceed).toBe(true);
|
||||
});
|
||||
|
||||
it('requires client mode selection for step 3 (non-script)', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test',
|
||||
complexity: 'medium',
|
||||
step: 3,
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.canProceed).toBe(false);
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ clientMode: 'technical' });
|
||||
});
|
||||
expect(result.current.canProceed).toBe(true);
|
||||
});
|
||||
|
||||
it('requires autonomy level for step 4 (non-script)', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test',
|
||||
complexity: 'medium',
|
||||
clientMode: 'auto',
|
||||
step: 4,
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.canProceed).toBe(false);
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ autonomyLevel: 'milestone' });
|
||||
});
|
||||
expect(result.current.canProceed).toBe(true);
|
||||
});
|
||||
|
||||
it('always allows proceeding from step 5 (agent chat)', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ step: 5 });
|
||||
});
|
||||
|
||||
expect(result.current.canProceed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigation', () => {
|
||||
it('goNext increments step', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ projectName: 'Test Project' });
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.goNext();
|
||||
});
|
||||
|
||||
expect(result.current.state.step).toBe(2);
|
||||
});
|
||||
|
||||
it('goBack decrements step', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ projectName: 'Test', step: 3 });
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.goBack();
|
||||
});
|
||||
|
||||
expect(result.current.state.step).toBe(2);
|
||||
});
|
||||
|
||||
it('goBack does nothing at step 1', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.goBack();
|
||||
});
|
||||
|
||||
expect(result.current.state.step).toBe(1);
|
||||
});
|
||||
|
||||
it('does not proceed when canProceed is false', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
// Project name too short
|
||||
act(() => {
|
||||
result.current.updateState({ projectName: 'AB' });
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.goNext();
|
||||
});
|
||||
|
||||
expect(result.current.state.step).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('script mode', () => {
|
||||
it('sets isScriptMode when complexity is script', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({ complexity: 'script' });
|
||||
});
|
||||
|
||||
expect(result.current.isScriptMode).toBe(true);
|
||||
});
|
||||
|
||||
it('skips from step 2 to step 5 for scripts', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
// Set up step 2 with script complexity
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test Script',
|
||||
step: 2,
|
||||
complexity: 'script',
|
||||
});
|
||||
});
|
||||
|
||||
// Go next should skip to step 5
|
||||
act(() => {
|
||||
result.current.goNext();
|
||||
});
|
||||
|
||||
expect(result.current.state.step).toBe(WIZARD_STEPS.AGENT_CHAT);
|
||||
});
|
||||
|
||||
it('auto-sets clientMode and autonomyLevel for scripts', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test Script',
|
||||
step: 2,
|
||||
complexity: 'script',
|
||||
});
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.goNext();
|
||||
});
|
||||
|
||||
expect(result.current.state.clientMode).toBe('auto');
|
||||
expect(result.current.state.autonomyLevel).toBe('autonomous');
|
||||
});
|
||||
|
||||
it('goBack from step 5 goes to step 2 for scripts', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test Script',
|
||||
complexity: 'script',
|
||||
step: 5,
|
||||
});
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.goBack();
|
||||
});
|
||||
|
||||
expect(result.current.state.step).toBe(WIZARD_STEPS.COMPLEXITY);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getProjectData', () => {
|
||||
it('generates correct project data', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'My Test Project',
|
||||
description: 'A description',
|
||||
repoUrl: 'https://github.com/test/repo',
|
||||
complexity: 'medium',
|
||||
clientMode: 'technical',
|
||||
autonomyLevel: 'milestone',
|
||||
});
|
||||
});
|
||||
|
||||
const data = result.current.getProjectData();
|
||||
|
||||
expect(data.name).toBe('My Test Project');
|
||||
expect(data.slug).toBe('my-test-project');
|
||||
expect(data.description).toBe('A description');
|
||||
expect(data.autonomy_level).toBe('milestone');
|
||||
expect(data.settings.complexity).toBe('medium');
|
||||
expect(data.settings.client_mode).toBe('technical');
|
||||
expect(data.settings.repo_url).toBe('https://github.com/test/repo');
|
||||
});
|
||||
|
||||
it('generates URL-safe slug', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'My Project! With Special @#$ Characters',
|
||||
});
|
||||
});
|
||||
|
||||
const data = result.current.getProjectData();
|
||||
expect(data.slug).toBe('my-project-with-special-characters');
|
||||
});
|
||||
|
||||
it('excludes empty repoUrl from settings', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test Project',
|
||||
repoUrl: '',
|
||||
});
|
||||
});
|
||||
|
||||
const data = result.current.getProjectData();
|
||||
expect(data.settings.repo_url).toBeUndefined();
|
||||
});
|
||||
|
||||
it('uses defaults for null values', () => {
|
||||
const { result } = renderHook(() => useWizardState());
|
||||
|
||||
act(() => {
|
||||
result.current.updateState({
|
||||
projectName: 'Test Project',
|
||||
});
|
||||
});
|
||||
|
||||
const data = result.current.getProjectData();
|
||||
expect(data.autonomy_level).toBe('milestone');
|
||||
expect(data.settings.complexity).toBe('medium');
|
||||
expect(data.settings.client_mode).toBe('auto');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* ActivityTimeline Component Tests
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { ActivityTimeline } from '@/features/issues/components/ActivityTimeline';
|
||||
import type { IssueActivity } from '@/features/issues/types';
|
||||
|
||||
const mockActivities: IssueActivity[] = [
|
||||
{
|
||||
id: 'act-1',
|
||||
type: 'status_change',
|
||||
actor: { id: 'user-1', name: 'Test User', type: 'human' },
|
||||
message: 'moved issue from "Open" to "In Progress"',
|
||||
timestamp: '2 hours ago',
|
||||
},
|
||||
{
|
||||
id: 'act-2',
|
||||
type: 'comment',
|
||||
actor: { id: 'agent-1', name: 'Backend Agent', type: 'agent' },
|
||||
message: 'Started working on this issue',
|
||||
timestamp: '3 hours ago',
|
||||
},
|
||||
{
|
||||
id: 'act-3',
|
||||
type: 'created',
|
||||
actor: { id: 'user-2', name: 'Product Owner', type: 'human' },
|
||||
message: 'created this issue',
|
||||
timestamp: '1 day ago',
|
||||
},
|
||||
];
|
||||
|
||||
describe('ActivityTimeline', () => {
|
||||
it('renders all activities', () => {
|
||||
render(<ActivityTimeline activities={mockActivities} />);
|
||||
|
||||
expect(screen.getByText('Test User')).toBeInTheDocument();
|
||||
expect(screen.getByText('Backend Agent')).toBeInTheDocument();
|
||||
expect(screen.getByText('Product Owner')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders activity messages', () => {
|
||||
render(<ActivityTimeline activities={mockActivities} />);
|
||||
|
||||
expect(screen.getByText(/moved issue from "Open" to "In Progress"/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Started working on this issue/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/created this issue/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders timestamps', () => {
|
||||
render(<ActivityTimeline activities={mockActivities} />);
|
||||
|
||||
expect(screen.getByText('2 hours ago')).toBeInTheDocument();
|
||||
expect(screen.getByText('3 hours ago')).toBeInTheDocument();
|
||||
expect(screen.getByText('1 day ago')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows add comment button when callback provided', () => {
|
||||
const mockOnAddComment = jest.fn();
|
||||
render(<ActivityTimeline activities={mockActivities} onAddComment={mockOnAddComment} />);
|
||||
|
||||
expect(screen.getByRole('button', { name: /add comment/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onAddComment when button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const mockOnAddComment = jest.fn();
|
||||
render(<ActivityTimeline activities={mockActivities} onAddComment={mockOnAddComment} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /add comment/i }));
|
||||
expect(mockOnAddComment).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows empty state when no activities', () => {
|
||||
render(<ActivityTimeline activities={[]} />);
|
||||
|
||||
expect(screen.getByText('No activity yet')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<ActivityTimeline activities={mockActivities} className="custom-class" />
|
||||
);
|
||||
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('has proper list role for accessibility', () => {
|
||||
render(<ActivityTimeline activities={mockActivities} />);
|
||||
|
||||
expect(screen.getByRole('list', { name: /issue activity/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
126
frontend/tests/features/issues/components/IssueFilters.test.tsx
Normal file
126
frontend/tests/features/issues/components/IssueFilters.test.tsx
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* IssueFilters Component Tests
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IssueFilters } from '@/features/issues/components/IssueFilters';
|
||||
import type { IssueFilters as IssueFiltersType } from '@/features/issues/types';
|
||||
|
||||
describe('IssueFilters', () => {
|
||||
const defaultFilters: IssueFiltersType = {
|
||||
status: 'all',
|
||||
priority: 'all',
|
||||
sprint: 'all',
|
||||
assignee: 'all',
|
||||
};
|
||||
|
||||
const mockOnFiltersChange = jest.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
mockOnFiltersChange.mockClear();
|
||||
});
|
||||
|
||||
it('renders search input', () => {
|
||||
render(<IssueFilters filters={defaultFilters} onFiltersChange={mockOnFiltersChange} />);
|
||||
|
||||
expect(screen.getByPlaceholderText('Search issues...')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onFiltersChange when search changes', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<IssueFilters filters={defaultFilters} onFiltersChange={mockOnFiltersChange} />);
|
||||
|
||||
const searchInput = screen.getByPlaceholderText('Search issues...');
|
||||
await user.type(searchInput, 'test');
|
||||
|
||||
// onFiltersChange should be called at least once
|
||||
expect(mockOnFiltersChange).toHaveBeenCalled();
|
||||
// The final state should contain the search term 'test' (may be in the last call)
|
||||
const allCalls = mockOnFiltersChange.mock.calls;
|
||||
const lastCall = allCalls[allCalls.length - 1][0];
|
||||
// The search value could include the typed characters
|
||||
expect(lastCall.search).toMatch(/t/);
|
||||
});
|
||||
|
||||
it('renders status filter', () => {
|
||||
render(<IssueFilters filters={defaultFilters} onFiltersChange={mockOnFiltersChange} />);
|
||||
|
||||
expect(screen.getByRole('combobox', { name: /filter by status/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('toggles extended filters when filter button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<IssueFilters filters={defaultFilters} onFiltersChange={mockOnFiltersChange} />);
|
||||
|
||||
// Extended filters should not be visible initially
|
||||
expect(screen.queryByLabelText('Priority')).not.toBeInTheDocument();
|
||||
|
||||
// Click the filter toggle button
|
||||
const filterButton = screen.getByRole('button', { name: /toggle extended filters/i });
|
||||
await user.click(filterButton);
|
||||
|
||||
// Extended filters should now be visible
|
||||
expect(screen.getByLabelText('Priority')).toBeInTheDocument();
|
||||
expect(screen.getByLabelText('Sprint')).toBeInTheDocument();
|
||||
expect(screen.getByLabelText('Assignee')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows clear filters button when filters are active', async () => {
|
||||
const user = userEvent.setup();
|
||||
const activeFilters: IssueFiltersType = {
|
||||
...defaultFilters,
|
||||
status: 'open',
|
||||
};
|
||||
|
||||
render(<IssueFilters filters={activeFilters} onFiltersChange={mockOnFiltersChange} />);
|
||||
|
||||
// Open extended filters
|
||||
const filterButton = screen.getByRole('button', { name: /toggle extended filters/i });
|
||||
await user.click(filterButton);
|
||||
|
||||
// Clear filters button should be visible
|
||||
expect(screen.getByRole('button', { name: /clear filters/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('clears filters when clear button is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const activeFilters: IssueFiltersType = {
|
||||
...defaultFilters,
|
||||
status: 'open',
|
||||
search: 'test',
|
||||
};
|
||||
|
||||
render(<IssueFilters filters={activeFilters} onFiltersChange={mockOnFiltersChange} />);
|
||||
|
||||
// Open extended filters
|
||||
const filterButton = screen.getByRole('button', { name: /toggle extended filters/i });
|
||||
await user.click(filterButton);
|
||||
|
||||
// Click clear filters
|
||||
const clearButton = screen.getByRole('button', { name: /clear filters/i });
|
||||
await user.click(clearButton);
|
||||
|
||||
// Should call onFiltersChange with cleared filters
|
||||
expect(mockOnFiltersChange).toHaveBeenCalledWith({
|
||||
search: undefined,
|
||||
status: 'all',
|
||||
priority: 'all',
|
||||
sprint: 'all',
|
||||
assignee: 'all',
|
||||
labels: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<IssueFilters
|
||||
filters={defaultFilters}
|
||||
onFiltersChange={mockOnFiltersChange}
|
||||
className="custom-class"
|
||||
/>
|
||||
);
|
||||
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
266
frontend/tests/features/issues/components/IssueTable.test.tsx
Normal file
266
frontend/tests/features/issues/components/IssueTable.test.tsx
Normal file
@@ -0,0 +1,266 @@
|
||||
/**
|
||||
* IssueTable Component Tests
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { IssueTable } from '@/features/issues/components/IssueTable';
|
||||
import type { IssueSummary, IssueSort } from '@/features/issues/types';
|
||||
|
||||
const mockIssues: IssueSummary[] = [
|
||||
{
|
||||
id: 'issue-1',
|
||||
number: 42,
|
||||
title: 'Test Issue 1',
|
||||
description: 'Description 1',
|
||||
status: 'open',
|
||||
priority: 'high',
|
||||
labels: ['bug', 'frontend'],
|
||||
sprint: 'Sprint 1',
|
||||
assignee: { id: 'user-1', name: 'Test User', type: 'human' },
|
||||
created_at: '2025-01-01T00:00:00Z',
|
||||
updated_at: '2025-01-02T00:00:00Z',
|
||||
sync_status: 'synced',
|
||||
},
|
||||
{
|
||||
id: 'issue-2',
|
||||
number: 43,
|
||||
title: 'Test Issue 2',
|
||||
description: 'Description 2',
|
||||
status: 'in_progress',
|
||||
priority: 'medium',
|
||||
labels: ['feature'],
|
||||
sprint: null,
|
||||
assignee: null,
|
||||
created_at: '2025-01-02T00:00:00Z',
|
||||
updated_at: '2025-01-03T00:00:00Z',
|
||||
sync_status: 'pending',
|
||||
},
|
||||
];
|
||||
|
||||
describe('IssueTable', () => {
|
||||
const defaultSort: IssueSort = { field: 'number', direction: 'asc' };
|
||||
const mockOnSelectionChange = jest.fn();
|
||||
const mockOnIssueClick = jest.fn();
|
||||
const mockOnSortChange = jest.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
mockOnSelectionChange.mockClear();
|
||||
mockOnIssueClick.mockClear();
|
||||
mockOnSortChange.mockClear();
|
||||
});
|
||||
|
||||
it('renders issue rows', () => {
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Test Issue 1')).toBeInTheDocument();
|
||||
expect(screen.getByText('Test Issue 2')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays issue numbers', () => {
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('42')).toBeInTheDocument();
|
||||
expect(screen.getByText('43')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows labels for issues', () => {
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('bug')).toBeInTheDocument();
|
||||
expect(screen.getByText('frontend')).toBeInTheDocument();
|
||||
expect(screen.getByText('feature')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onIssueClick when row is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
const row = screen.getByTestId('issue-row-issue-1');
|
||||
await user.click(row);
|
||||
|
||||
expect(mockOnIssueClick).toHaveBeenCalledWith('issue-1');
|
||||
});
|
||||
|
||||
it('handles issue selection', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
// Find checkbox for first issue
|
||||
const checkbox = screen.getByRole('checkbox', { name: /select issue 42/i });
|
||||
await user.click(checkbox);
|
||||
|
||||
expect(mockOnSelectionChange).toHaveBeenCalledWith(['issue-1']);
|
||||
});
|
||||
|
||||
it('handles select all', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
// Find select all checkbox
|
||||
const selectAllCheckbox = screen.getByRole('checkbox', { name: /select all issues/i });
|
||||
await user.click(selectAllCheckbox);
|
||||
|
||||
expect(mockOnSelectionChange).toHaveBeenCalledWith(['issue-1', 'issue-2']);
|
||||
});
|
||||
|
||||
it('handles deselect all when all selected', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={['issue-1', 'issue-2']}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
// Find deselect all checkbox
|
||||
const selectAllCheckbox = screen.getByRole('checkbox', { name: /deselect all issues/i });
|
||||
await user.click(selectAllCheckbox);
|
||||
|
||||
expect(mockOnSelectionChange).toHaveBeenCalledWith([]);
|
||||
});
|
||||
|
||||
it('handles sorting by number', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
// Click the # column header
|
||||
const numberHeader = screen.getByRole('button', { name: /#/i });
|
||||
await user.click(numberHeader);
|
||||
|
||||
expect(mockOnSortChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles sorting by priority', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
// Click the Priority column header
|
||||
const priorityHeader = screen.getByRole('button', { name: /priority/i });
|
||||
await user.click(priorityHeader);
|
||||
|
||||
expect(mockOnSortChange).toHaveBeenCalledWith({ field: 'priority', direction: 'desc' });
|
||||
});
|
||||
|
||||
it('shows empty state when no issues', () => {
|
||||
render(
|
||||
<IssueTable
|
||||
issues={[]}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('No issues found')).toBeInTheDocument();
|
||||
expect(screen.getByText('Try adjusting your search or filters')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows unassigned text for issues without assignee', () => {
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Unassigned')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows backlog text for issues without sprint', () => {
|
||||
render(
|
||||
<IssueTable
|
||||
issues={mockIssues}
|
||||
selectedIssues={[]}
|
||||
onSelectionChange={mockOnSelectionChange}
|
||||
onIssueClick={mockOnIssueClick}
|
||||
sort={defaultSort}
|
||||
onSortChange={mockOnSortChange}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Backlog')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* PriorityBadge Component Tests
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { PriorityBadge } from '@/features/issues/components/PriorityBadge';
|
||||
import type { IssuePriority } from '@/features/issues/types';
|
||||
|
||||
describe('PriorityBadge', () => {
|
||||
const priorities: IssuePriority[] = ['high', 'medium', 'low'];
|
||||
|
||||
it.each(priorities)('renders %s priority correctly', (priority) => {
|
||||
render(<PriorityBadge priority={priority} />);
|
||||
|
||||
// The priority should be displayed as capitalized
|
||||
const capitalizedPriority = priority.charAt(0).toUpperCase() + priority.slice(1);
|
||||
expect(screen.getByText(capitalizedPriority)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<PriorityBadge priority="high" className="custom-class" />);
|
||||
|
||||
const badge = screen.getByText('High');
|
||||
expect(badge).toHaveClass('custom-class');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* StatusBadge Component Tests
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { StatusBadge } from '@/features/issues/components/StatusBadge';
|
||||
import type { IssueStatus } from '@/features/issues/types';
|
||||
|
||||
const statusLabels: Record<IssueStatus, string> = {
|
||||
open: 'Open',
|
||||
in_progress: 'In Progress',
|
||||
in_review: 'In Review',
|
||||
blocked: 'Blocked',
|
||||
done: 'Done',
|
||||
closed: 'Closed',
|
||||
};
|
||||
|
||||
describe('StatusBadge', () => {
|
||||
const statuses: IssueStatus[] = ['open', 'in_progress', 'in_review', 'blocked', 'done', 'closed'];
|
||||
|
||||
it.each(statuses)('renders %s status correctly', (status) => {
|
||||
render(<StatusBadge status={status} />);
|
||||
|
||||
// Check that the status text is present - use getAllByText since we have both visible and sr-only
|
||||
const elements = screen.getAllByText(statusLabels[status]);
|
||||
expect(elements.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('hides label when showLabel is false', () => {
|
||||
render(<StatusBadge status="open" showLabel={false} />);
|
||||
|
||||
// The sr-only text should still be present
|
||||
expect(screen.getByText('Open')).toHaveClass('sr-only');
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(<StatusBadge status="open" className="custom-class" />);
|
||||
|
||||
const wrapper = container.firstChild;
|
||||
expect(wrapper).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('renders with accessible label', () => {
|
||||
render(<StatusBadge status="open" showLabel={false} />);
|
||||
|
||||
// Should have sr-only text for screen readers
|
||||
expect(screen.getByText('Open')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* StatusWorkflow Component Tests
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { StatusWorkflow } from '@/features/issues/components/StatusWorkflow';
|
||||
|
||||
describe('StatusWorkflow', () => {
|
||||
const mockOnStatusChange = jest.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
mockOnStatusChange.mockClear();
|
||||
});
|
||||
|
||||
it('renders all status options', () => {
|
||||
render(
|
||||
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} />
|
||||
);
|
||||
|
||||
expect(screen.getByText('Open')).toBeInTheDocument();
|
||||
expect(screen.getByText('In Progress')).toBeInTheDocument();
|
||||
expect(screen.getByText('In Review')).toBeInTheDocument();
|
||||
expect(screen.getByText('Blocked')).toBeInTheDocument();
|
||||
expect(screen.getByText('Done')).toBeInTheDocument();
|
||||
expect(screen.getByText('Closed')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('highlights current status', () => {
|
||||
render(
|
||||
<StatusWorkflow currentStatus="in_progress" onStatusChange={mockOnStatusChange} />
|
||||
);
|
||||
|
||||
const inProgressButton = screen.getByRole('radio', { name: /in progress/i });
|
||||
expect(inProgressButton).toHaveAttribute('aria-checked', 'true');
|
||||
});
|
||||
|
||||
it('calls onStatusChange when status is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} />
|
||||
);
|
||||
|
||||
const inProgressButton = screen.getByRole('radio', { name: /in progress/i });
|
||||
await user.click(inProgressButton);
|
||||
|
||||
expect(mockOnStatusChange).toHaveBeenCalledWith('in_progress');
|
||||
});
|
||||
|
||||
it('disables status buttons when disabled prop is true', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} disabled />
|
||||
);
|
||||
|
||||
const inProgressButton = screen.getByRole('radio', { name: /in progress/i });
|
||||
expect(inProgressButton).toBeDisabled();
|
||||
|
||||
await user.click(inProgressButton);
|
||||
expect(mockOnStatusChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<StatusWorkflow
|
||||
currentStatus="open"
|
||||
onStatusChange={mockOnStatusChange}
|
||||
className="custom-class"
|
||||
/>
|
||||
);
|
||||
|
||||
expect(container.firstChild).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('has proper radiogroup role', () => {
|
||||
render(
|
||||
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} />
|
||||
);
|
||||
|
||||
expect(screen.getByRole('radiogroup', { name: /issue status/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* SyncStatusIndicator Component Tests
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { SyncStatusIndicator } from '@/features/issues/components/SyncStatusIndicator';
|
||||
import type { SyncStatus } from '@/features/issues/types';
|
||||
|
||||
describe('SyncStatusIndicator', () => {
|
||||
const statuses: SyncStatus[] = ['synced', 'pending', 'conflict', 'error'];
|
||||
|
||||
it.each(statuses)('renders %s status correctly', (status) => {
|
||||
render(<SyncStatusIndicator status={status} />);
|
||||
|
||||
// Should have accessible label containing "Sync status"
|
||||
const element = screen.getByRole('status');
|
||||
expect(element).toHaveAttribute('aria-label', expect.stringContaining('Sync status'));
|
||||
});
|
||||
|
||||
it('shows label when showLabel is true', () => {
|
||||
render(<SyncStatusIndicator status="synced" showLabel />);
|
||||
|
||||
expect(screen.getByText('Synced')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides label by default', () => {
|
||||
render(<SyncStatusIndicator status="synced" />);
|
||||
|
||||
expect(screen.queryByText('Synced')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('applies custom className', () => {
|
||||
render(<SyncStatusIndicator status="synced" className="custom-class" />);
|
||||
|
||||
const element = screen.getByRole('status');
|
||||
expect(element).toHaveClass('custom-class');
|
||||
});
|
||||
|
||||
it('shows spinning icon for pending status', () => {
|
||||
const { container } = render(<SyncStatusIndicator status="pending" />);
|
||||
|
||||
const icon = container.querySelector('svg');
|
||||
expect(icon).toHaveClass('animate-spin');
|
||||
});
|
||||
});
|
||||
154
frontend/tests/lib/hooks/useDebounce.test.ts
Normal file
154
frontend/tests/lib/hooks/useDebounce.test.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
import { renderHook, act } from '@testing-library/react';
|
||||
import { useDebounce } from '@/lib/hooks/useDebounce';
|
||||
|
||||
describe('useDebounce', () => {
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('returns the initial value immediately', () => {
|
||||
const { result } = renderHook(() => useDebounce('initial', 500));
|
||||
expect(result.current).toBe('initial');
|
||||
});
|
||||
|
||||
it('updates the debounced value after the delay', () => {
|
||||
const { result, rerender } = renderHook(
|
||||
({ value, delay }) => useDebounce(value, delay),
|
||||
{ initialProps: { value: 'initial', delay: 500 } }
|
||||
);
|
||||
|
||||
// Change the value
|
||||
rerender({ value: 'updated', delay: 500 });
|
||||
|
||||
// Value should still be initial before delay
|
||||
expect(result.current).toBe('initial');
|
||||
|
||||
// Fast forward time
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
|
||||
// Value should now be updated
|
||||
expect(result.current).toBe('updated');
|
||||
});
|
||||
|
||||
it('does not update the value before the delay', () => {
|
||||
const { result, rerender } = renderHook(
|
||||
({ value, delay }) => useDebounce(value, delay),
|
||||
{ initialProps: { value: 'initial', delay: 500 } }
|
||||
);
|
||||
|
||||
rerender({ value: 'updated', delay: 500 });
|
||||
|
||||
// Only advance 300ms (not enough)
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(300);
|
||||
});
|
||||
|
||||
expect(result.current).toBe('initial');
|
||||
});
|
||||
|
||||
it('resets the timer when value changes rapidly', () => {
|
||||
const { result, rerender } = renderHook(
|
||||
({ value, delay }) => useDebounce(value, delay),
|
||||
{ initialProps: { value: 'initial', delay: 500 } }
|
||||
);
|
||||
|
||||
// First change
|
||||
rerender({ value: 'first', delay: 500 });
|
||||
|
||||
// Advance 300ms
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(300);
|
||||
});
|
||||
|
||||
// Second change (should reset timer)
|
||||
rerender({ value: 'second', delay: 500 });
|
||||
|
||||
// Advance another 300ms (total 600ms from first, but only 300ms from second)
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(300);
|
||||
});
|
||||
|
||||
// Value should still be initial (timer was reset)
|
||||
expect(result.current).toBe('initial');
|
||||
|
||||
// Advance the remaining 200ms
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(200);
|
||||
});
|
||||
|
||||
// Now should show 'second'
|
||||
expect(result.current).toBe('second');
|
||||
});
|
||||
|
||||
it('cleans up timeout on unmount', () => {
|
||||
const clearTimeoutSpy = jest.spyOn(global, 'clearTimeout');
|
||||
|
||||
const { unmount, rerender } = renderHook(
|
||||
({ value, delay }) => useDebounce(value, delay),
|
||||
{ initialProps: { value: 'initial', delay: 500 } }
|
||||
);
|
||||
|
||||
rerender({ value: 'updated', delay: 500 });
|
||||
unmount();
|
||||
|
||||
expect(clearTimeoutSpy).toHaveBeenCalled();
|
||||
clearTimeoutSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('works with different delay values', () => {
|
||||
const { result, rerender } = renderHook(
|
||||
({ value, delay }) => useDebounce(value, delay),
|
||||
{ initialProps: { value: 'initial', delay: 1000 } }
|
||||
);
|
||||
|
||||
rerender({ value: 'updated', delay: 1000 });
|
||||
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
|
||||
expect(result.current).toBe('initial');
|
||||
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
|
||||
expect(result.current).toBe('updated');
|
||||
});
|
||||
|
||||
it('works with different value types', () => {
|
||||
// Test with number
|
||||
const { result: numberResult } = renderHook(() => useDebounce(42, 500));
|
||||
expect(numberResult.current).toBe(42);
|
||||
|
||||
// Test with object
|
||||
const obj = { foo: 'bar' };
|
||||
const { result: objectResult } = renderHook(() => useDebounce(obj, 500));
|
||||
expect(objectResult.current).toEqual({ foo: 'bar' });
|
||||
|
||||
// Test with null
|
||||
const { result: nullResult } = renderHook(() => useDebounce(null, 500));
|
||||
expect(nullResult.current).toBeNull();
|
||||
});
|
||||
|
||||
it('handles zero delay', () => {
|
||||
const { result, rerender } = renderHook(
|
||||
({ value, delay }) => useDebounce(value, delay),
|
||||
{ initialProps: { value: 'initial', delay: 0 } }
|
||||
);
|
||||
|
||||
rerender({ value: 'updated', delay: 0 });
|
||||
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(0);
|
||||
});
|
||||
|
||||
expect(result.current).toBe('updated');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user