Skip to content

Commit 8d37e7b

Browse files
vsilentCopilot
andcommitted
web: fix dashboard import paths and TypeScript build errors
- Correct component imports from ../../services|types to ../services|types - Fix react-bootstrap Alert alias in ContainerList - Add explicit typed mappings for alert/container badge variants - Type websocket stats callback payload - Import fireEvent in ThreatMap tests - Improve WebSocket test mock shape to satisfy TS - Expose ApiService.api for existing tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a9757d4 commit 8d37e7b

7 files changed

Lines changed: 33 additions & 23 deletions

File tree

web/src/components/AlertPanel.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useEffect, useState } from 'react';
22
import { Card, Button, Form, Table, Badge, Modal, Spinner, Alert as BootstrapAlert, Pagination } from 'react-bootstrap';
3-
import apiService from '../../services/api';
4-
import webSocketService from '../../services/websocket';
5-
import { Alert, AlertSeverity, AlertStatus, AlertFilter, AlertStats } from '../../types/alerts';
3+
import apiService from '../services/api';
4+
import webSocketService from '../services/websocket';
5+
import { Alert, AlertSeverity, AlertStatus, AlertFilter, AlertStats } from '../types/alerts';
66
import './AlertPanel.css';
77

88
const ITEMS_PER_PAGE = 10;
@@ -121,7 +121,7 @@ const AlertPanel: React.FC = () => {
121121
};
122122

123123
const getSeverityBadge = (severity: AlertSeverity) => {
124-
const variants = {
124+
const variants: Record<AlertSeverity, string> = {
125125
Info: 'info',
126126
Low: 'success',
127127
Medium: 'warning',
@@ -132,7 +132,7 @@ const AlertPanel: React.FC = () => {
132132
};
133133

134134
const getStatusBadge = (status: AlertStatus) => {
135-
const variants = {
135+
const variants: Record<AlertStatus, string> = {
136136
New: 'primary',
137137
Acknowledged: 'warning',
138138
Resolved: 'success',

web/src/components/ContainerList.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState } from 'react';
2-
import { Card, Button, Form, Badge, Modal, Spinner, BootstrapAlert } from 'react-bootstrap';
3-
import apiService from '../../services/api';
4-
import { Container, ContainerStatus } from '../../types/containers';
2+
import { Card, Button, Form, Badge, Modal, Spinner, Alert as BootstrapAlert } from 'react-bootstrap';
3+
import apiService from '../services/api';
4+
import { Container, ContainerStatus } from '../types/containers';
55
import './ContainerList.css';
66

77
const ContainerList: React.FC = () => {
@@ -21,7 +21,7 @@ const ContainerList: React.FC = () => {
2121
try {
2222
setLoading(true);
2323
const data = await apiService.getContainers();
24-
setContainers(filterStatus ? data.filter(c => c.status === filterStatus) : data);
24+
setContainers(filterStatus ? data.filter((c: Container) => c.status === filterStatus) : data);
2525
} catch (err) {
2626
console.error('Error loading containers:', err);
2727
} finally {
@@ -53,7 +53,7 @@ const ContainerList: React.FC = () => {
5353
};
5454

5555
const getStatusBadge = (status: ContainerStatus) => {
56-
const variants = {
56+
const variants: Record<ContainerStatus, string> = {
5757
Running: 'success',
5858
Stopped: 'secondary',
5959
Paused: 'warning',

web/src/components/Dashboard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useEffect, useState } from 'react';
22
import { Container, Row, Col, Card, Spinner, Alert as BootstrapAlert } from 'react-bootstrap';
3-
import apiService from '../../services/api';
4-
import webSocketService from '../../services/websocket';
5-
import { SecurityStatus } from '../../types/security';
3+
import apiService from '../services/api';
4+
import webSocketService from '../services/websocket';
5+
import { SecurityStatus } from '../types/security';
66
import SecurityScore from './SecurityScore';
77
import AlertPanel from './AlertPanel';
88
import ContainerList from './ContainerList';
@@ -42,7 +42,7 @@ const Dashboard: React.FC = () => {
4242
await webSocketService.connect();
4343

4444
// Subscribe to real-time updates
45-
webSocketService.subscribe('stats:updated', (data) => {
45+
webSocketService.subscribe('stats:updated', (data: Partial<SecurityStatus>) => {
4646
setSecurityStatus(prev => prev ? { ...prev, ...data } : null);
4747
});
4848

web/src/components/ThreatMap.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useEffect, useState } from 'react';
22
import { Card, Form, Spinner } from 'react-bootstrap';
33
import { BarChart, Bar, PieChart, Pie, LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, Cell } from 'recharts';
4-
import apiService from '../../services/api';
5-
import { Threat, ThreatStatistics } from '../../types/security';
4+
import apiService from '../services/api';
5+
import { Threat, ThreatStatistics } from '../types/security';
66
import './ThreatMap.css';
77

88
const COLORS = ['#e74c3c', '#e67e22', '#f39c12', '#3498db', '#27ae60'];

web/src/components/__tests__/ThreatMap.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render, screen, waitFor } from '@testing-library/react';
2+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
33
import ThreatMap from '../ThreatMap';
44
import apiService from '../../services/api';
55

web/src/services/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Container, QuarantineRequest } from '../types/containers';
66
const API_BASE_URL = process.env.REACT_APP_API_URL || 'http://localhost:5000/api';
77

88
class ApiService {
9-
private api: AxiosInstance;
9+
public api: AxiosInstance;
1010

1111
constructor() {
1212
this.api = axios.create({

web/src/setupTests.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import '@testing-library/jest-dom';
22

33
// Mock WebSocket
4-
global.WebSocket = class MockWebSocket {
5-
constructor(url: string) {
6-
this.url = url;
7-
}
4+
class MockWebSocket {
5+
static CONNECTING = 0;
6+
static OPEN = 1;
7+
static CLOSING = 2;
8+
static CLOSED = 3;
9+
10+
url: string;
11+
readyState = MockWebSocket.OPEN;
812
send = jest.fn();
913
close = jest.fn();
1014
addEventListener = jest.fn();
1115
removeEventListener = jest.fn();
12-
};
16+
17+
constructor(url: string) {
18+
this.url = url;
19+
}
20+
}
21+
22+
global.WebSocket = MockWebSocket as unknown as typeof WebSocket;
1323

1424
// Mock fetch
1525
global.fetch = jest.fn();

0 commit comments

Comments
 (0)