feat(dashboard): enhance dashboard overview and world stage components

- Implemented normalization for dashboard overview data to handle null or undefined values.
- Added ECharts map integration for visualizing node data on a world map.
- Introduced loading and error states for the map component.
- Updated UI components to support dark and light themes.
- Enhanced testing for dashboard overview to cover empty states and data fetching.
- Added type definitions for echarts-maps module.
- Updated package dependencies to include echarts-maps.
This commit is contained in:
ryan
2026-03-14 14:45:04 +08:00
parent 4bfad019d0
commit f1476610f6
8 changed files with 734 additions and 166 deletions
@@ -2,6 +2,38 @@ import { apiRequest } from '@/lib/api/client';
import type { DashboardOverview } from '@/features/dashboard/types';
export function getDashboardOverview() {
return apiRequest<DashboardOverview>('/dashboard/overview');
function arrayOrEmpty<T>(value: T[] | null | undefined) {
return Array.isArray(value) ? value : [];
}
function normalizeDashboardOverview(
overview: DashboardOverview | null | undefined,
): DashboardOverview | null {
if (!overview) {
return null;
}
return {
...overview,
nodes: arrayOrEmpty(overview.nodes),
active_alerts: arrayOrEmpty(overview.active_alerts),
distributions: {
...overview.distributions,
source_countries: arrayOrEmpty(overview.distributions?.source_countries),
status_codes: arrayOrEmpty(overview.distributions?.status_codes),
top_domains: arrayOrEmpty(overview.distributions?.top_domains),
},
trends: {
...overview.trends,
traffic_24h: arrayOrEmpty(overview.trends?.traffic_24h),
capacity_24h: arrayOrEmpty(overview.trends?.capacity_24h),
network_24h: arrayOrEmpty(overview.trends?.network_24h),
disk_io_24h: arrayOrEmpty(overview.trends?.disk_io_24h),
},
};
}
export async function getDashboardOverview() {
const overview = await apiRequest<DashboardOverview>('/dashboard/overview');
return normalizeDashboardOverview(overview);
}