FN-5894: share project data-boundary and status helpers
Centralize project loading and status-state handling across dashboard surfaces. - add a reusable DataBoundary component for loading, empty, error, and loaded states - extract shared project status config helpers for labels, colors, icons, and initializing detection - update project overview, cards, badges, and selector UI to use the shared helpers - add regression coverage for data-boundary behavior, project overview empty/loading transitions, and status config fallbacks Files changed: packages/dashboard/app/components/DataBoundary.tsx | 64 ++++++++++++++++++++++ packages/dashboard/app/components/ProjectCard.tsx | 48 ++-------------- .../app/components/ProjectHealthBadge.tsx | 45 +-------------- .../dashboard/app/components/ProjectOverview.tsx | 4 +- .../dashboard/app/components/ProjectSelector.tsx | 27 +-------- .../app/components/__tests__/DataBoundary.test.tsx | 62 +++++++++++++++++++++ .../components/__tests__/ProjectOverview.test.tsx | 25 +++++++++ .../__tests__/ProjectThemeTokens.test.tsx | 37 ++++--------- .../utils/__tests__/projectStatusConfig.test.ts | 53 ++++++++++++++++++ .../dashboard/app/utils/projectStatusConfig.ts | 50 +++++++++++++++++ packages/dashboard/vitest.config.ts | 2 + 11 files changed, 282 insertions(+), 135 deletions(-) Fusion-Task-Id: FN-5894 Fusion-Task-Lineage: 3626a4af-b62b-456d-82d7-cf47bbf55c21
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { memo, useCallback, useState } from "react";
|
||||
import { Play, Pause, AlertCircle, Loader2, Trash2, Folder, ArrowRight } from "lucide-react";
|
||||
import { Play, Pause, Trash2, Folder, ArrowRight } from "lucide-react";
|
||||
import "./ProjectCard.css";
|
||||
import type { RegisteredProject, ProjectHealth, ProjectStatus } from "@fusion/core";
|
||||
import type { RegisteredProject, ProjectHealth } from "@fusion/core";
|
||||
import type { ProjectNodeAvailability } from "../api";
|
||||
import { getProjectStatusConfig, isInitializingStatus } from "../utils/projectStatusConfig";
|
||||
|
||||
export interface ProjectCardProps {
|
||||
project: RegisteredProject;
|
||||
@@ -15,45 +16,6 @@ export interface ProjectCardProps {
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
type StatusConfig = { label: string; color: string; icon: typeof Play };
|
||||
|
||||
const STATUS_CONFIG: Record<ProjectStatus, StatusConfig> = {
|
||||
active: { label: "Active", color: "var(--color-success)", icon: Play },
|
||||
paused: { label: "Paused", color: "var(--color-warning)", icon: Pause },
|
||||
errored: { label: "Error", color: "var(--color-error)", icon: AlertCircle },
|
||||
initializing: { label: "Initializing", color: "var(--color-warning)", icon: Loader2 },
|
||||
};
|
||||
|
||||
const FALLBACK_STATUS_CONFIG: StatusConfig = {
|
||||
label: "Unknown",
|
||||
color: "var(--color-error)",
|
||||
icon: AlertCircle,
|
||||
};
|
||||
|
||||
function formatStatusLabel(status: string | null | undefined): string {
|
||||
if (!status) {
|
||||
return FALLBACK_STATUS_CONFIG.label;
|
||||
}
|
||||
|
||||
return status
|
||||
.split(/[-_\s]+/)
|
||||
.filter(Boolean)
|
||||
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
function getStatusConfig(status: string | null | undefined): StatusConfig {
|
||||
const config = STATUS_CONFIG[status as ProjectStatus];
|
||||
if (config) {
|
||||
return config;
|
||||
}
|
||||
|
||||
return {
|
||||
...FALLBACK_STATUS_CONFIG,
|
||||
label: formatStatusLabel(status),
|
||||
};
|
||||
}
|
||||
|
||||
function formatRelativeTime(timestamp: string | undefined): string {
|
||||
if (!timestamp) return "Never";
|
||||
|
||||
@@ -127,7 +89,7 @@ function ProjectCardInner({
|
||||
isLoading = false,
|
||||
}: ProjectCardProps) {
|
||||
const [removeArmed, setRemoveArmed] = useState(false);
|
||||
const statusConfig = getStatusConfig(project.status);
|
||||
const statusConfig = getProjectStatusConfig(project.status);
|
||||
const StatusIcon = statusConfig.icon;
|
||||
|
||||
const handleSelect = useCallback(() => {
|
||||
@@ -157,7 +119,7 @@ function ProjectCardInner({
|
||||
|
||||
const isPaused = project.status === "paused";
|
||||
const isErrored = project.status === "errored";
|
||||
const isInitializing = project.status === "initializing";
|
||||
const isInitializing = isInitializingStatus(project.status);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user