feat: scale instances, --reuse-values, values diff, UI redesign, hover animations

Backend (Phase 1):
- Add ScaleInstance endpoint (POST /clusters/{id}/instances/{id}/scale)
- Add GetInstanceValuesDiff endpoint (GET .../values-diff)
- Enable ReuseValues=true in Helm Upgrade for --reuse-values behavior
- Add GetValues/GetChartDefaultValues to HelmClient interface
- Add ScaleInstanceRequest/Response and InstanceValuesDiffResponse DTOs

Frontend (Phase 2):
- InstanceCard: +/- scale buttons with loading spinner
- ModifyModal: values diff view (current vs defaults), Use Defaults button
- ArtifactBrowserPage: collapsible sidebar, compact tag grid, search filter
- TagCard: "LATEST" badge, compact layout, responsive design
- InstanceCard: compact 3-column layout, fewer scrolls needed
- InstancesManagementPage: 3-column grid, compact view
- Global hover-lift and hover-glow CSS utilities
- SidebarNav: subtle hover transition on links
This commit is contained in:
Ivan087
2026-05-13 11:51:24 +08:00
parent 87eaaa564b
commit 28ecb2e636
16 changed files with 715 additions and 235 deletions

View File

@ -19,9 +19,12 @@ import {
AlertTriangle,
History,
HelpCircle,
Minus,
Plus,
Loader2,
} from "lucide-react";
import type { InstanceResponse, InstanceStatus } from "@/api";
import { INSTANCE_LAST_OPERATION, INSTANCE_STATUS } from "@/api";
import { INSTANCE_LAST_OPERATION, INSTANCE_STATUS, scaleInstance } from "@/api";
interface InstanceCardProps {
instance: InstanceResponse;
@ -29,6 +32,7 @@ interface InstanceCardProps {
onTerminate: (instance: InstanceResponse) => void;
onViewEntries: (instance: InstanceResponse) => void;
onViewDiagnostics: (instance: InstanceResponse) => void;
onScale?: (instance: InstanceResponse) => void;
}
type StatusVisual = {
@ -136,7 +140,9 @@ export const InstanceCard: React.FC<InstanceCardProps> = ({
onTerminate,
onViewEntries,
onViewDiagnostics,
onScale,
}) => {
const [scaling, setScaling] = React.useState(false);
const normalizedStatus = (instance.status ?? INSTANCE_STATUS.unknown) as InstanceStatus;
const statusInfo =
STATUS_INFO_MAP[normalizedStatus] ?? STATUS_INFO_MAP[INSTANCE_STATUS.unknown];
@ -163,120 +169,161 @@ export const InstanceCard: React.FC<InstanceCardProps> = ({
const lastError =
typeof instance.lastError === "string" ? instance.lastError.trim() : "";
// Extract replica count from values
const parsedValues = React.useMemo(() => {
if (!instance.values) return null;
try {
return typeof instance.values === "string"
? JSON.parse(instance.values)
: (instance.values as Record<string, any>);
} catch {
return null;
}
}, [instance.values]);
const currentReplicas = parsedValues?.replicaCount ?? parsedValues?.replicas ?? 1;
const handleScale = async (delta: number) => {
const newReplicas = Math.max(0, currentReplicas + delta);
if (newReplicas === currentReplicas) return;
if (!instance.clusterId || !instance.id) return;
setScaling(true);
try {
const result = await scaleInstance(instance.clusterId, instance.id, { replicas: newReplicas });
onScale?.(result.instance ?? instance);
} catch (err) {
console.error("[InstanceCard] Scale failed:", err);
} finally {
setScaling(false);
}
};
return (
<div className="group relative bg-gradient-to-br from-white via-white to-slate-50 border border-slate-200 rounded-xl hover:border-blue-500/50 hover:shadow-xl hover:shadow-blue-500/10 transition-all duration-300 overflow-hidden">
{/* Decorative gradient overlay */}
<div className="absolute top-0 right-0 w-64 h-64 bg-gradient-to-br from-blue-500/5 to-purple-500/5 rounded-full blur-3xl -z-0 opacity-0 group-hover:opacity-100 transition-opacity duration-500"></div>
{/* Header with enhanced design */}
<div className="relative px-6 py-5 border-b border-slate-200 bg-gradient-to-r from-slate-50 to-white">
<div className="flex items-start justify-between">
<div className="flex items-start gap-4 flex-1">
{/* Enhanced icon with glow effect */}
<div className="relative p-3 bg-gradient-to-br from-blue-500/20 to-cyan-500/20 rounded-xl border border-blue-500/30 shadow-lg shadow-blue-500/20 group-hover:shadow-blue-500/40 transition-shadow duration-300">
<Box className="w-7 h-7 text-blue-400" />
<div className="absolute inset-0 bg-blue-400/10 rounded-xl blur-sm"></div>
<div className="hover-lift group relative bg-white border border-slate-200 rounded-xl hover:border-blue-500/50 duration-200 overflow-hidden">
{/* Header - compact */}
<div className="relative px-4 py-3 border-b border-slate-200 bg-gradient-to-r from-slate-50 to-white">
<div className="flex items-start justify-between gap-3">
<div className="flex items-start gap-3 flex-1 min-w-0">
{/* Icon */}
<div className="flex-shrink-0 p-2 bg-gradient-to-br from-blue-500/20 to-cyan-500/20 rounded-lg border border-blue-500/30">
<Box className="w-5 h-5 text-blue-400" />
</div>
<div className="flex-1 min-w-0">
<h3 className="text-xl font-bold text-slate-950 truncate">
<h3 className="text-base font-bold text-slate-950 truncate">
{instanceName}
</h3>
<div className="flex items-center gap-2 mt-2">
<Package className="w-4 h-4 text-slate-500" />
<p className="text-sm text-slate-500 font-mono">
{repository}
</p>
<span className="text-slate-600"></span>
<span className="px-2 py-0.5 text-xs font-semibold text-cyan-400 bg-cyan-500/10 border border-cyan-500/30 rounded">
<div className="flex items-center gap-1.5 mt-1">
<Package className="w-3.5 h-3.5 text-slate-400 flex-shrink-0" />
<span className="text-sm text-slate-500 font-mono truncate">{repository}</span>
<span className="text-slate-300 flex-shrink-0">&#183;</span>
<span className="px-1.5 py-0.5 text-[11px] font-semibold text-cyan-400 bg-cyan-500/10 border border-cyan-500/30 rounded flex-shrink-0">
{version}
</span>
</div>
</div>
</div>
{/* Enhanced Status Badge with glow */}
{/* Status Badge - prominent but smaller */}
<div
className={`flex items-center gap-2 px-4 py-2 rounded-full border shadow-lg ${statusInfo.bg} ${statusInfo.glow} backdrop-blur-sm`}
className={`flex items-center gap-1.5 px-3 py-1 rounded-full border shadow-sm ${statusInfo.bg} flex-shrink-0`}
>
<StatusIcon className={`w-4 h-4 ${statusInfo.color}`} />
<span className={`text-sm font-semibold ${statusInfo.color} uppercase tracking-wide`}>
<StatusIcon className={`w-3.5 h-3.5 ${statusInfo.color}`} />
<span className={`text-xs font-semibold ${statusInfo.color} uppercase tracking-wide`}>
{statusLabel}
</span>
</div>
</div>
<div className="mt-4 flex flex-col gap-1 text-sm text-slate-700">
<span className="font-medium text-slate-700">{statusReason}</span>
{/* Status reason + last operation - compact inline */}
<div className="mt-2 flex items-center gap-2 text-xs text-slate-600">
<span className="truncate">{statusReason}</span>
{lastOperationLabel && (
<span className="text-xs uppercase tracking-wide text-slate-500">
Operation: {lastOperationLabel}
</span>
<>
<span className="text-slate-300 flex-shrink-0">|</span>
<span className="uppercase tracking-wide text-slate-400 whitespace-nowrap flex-shrink-0">
{lastOperationLabel}
</span>
</>
)}
</div>
</div>
{/* Enhanced Content Grid */}
<div className="relative px-6 py-5 space-y-4 bg-gradient-to-b from-white to-slate-50">
<div className="grid grid-cols-2 gap-4">
{/* Namespace */}
<div className="p-3 bg-white border border-slate-200 rounded-lg hover:border-purple-500/30 transition-colors">
<div className="flex items-center gap-2 mb-2">
<Layers className="w-4 h-4 text-purple-400" />
<p className="text-xs text-slate-500 uppercase font-semibold tracking-wider">Namespace</p>
{/* Content - compact 3-column layout */}
<div className="px-4 py-3 space-y-2">
{/* Row 1: Namespace | Revision | Launched */}
<div className="grid grid-cols-3 gap-3">
<div>
<div className="flex items-center gap-1 mb-0.5">
<Layers className="w-3 h-3 text-purple-400 flex-shrink-0" />
<p className="text-[11px] text-slate-500 uppercase font-semibold tracking-wider">Namespace</p>
</div>
<p className="text-sm font-bold text-slate-900">
{namespace}
</p>
<p className="text-sm font-medium text-slate-900">{namespace}</p>
</div>
{/* Revision */}
<div className="p-3 bg-white border border-slate-200 rounded-lg hover:border-green-500/30 transition-colors">
<div className="flex items-center gap-2 mb-2">
<GitBranch className="w-4 h-4 text-green-400" />
<p className="text-xs text-slate-500 uppercase font-semibold tracking-wider">Revision</p>
<div>
<div className="flex items-center gap-1 mb-0.5">
<GitBranch className="w-3 h-3 text-green-400 flex-shrink-0" />
<p className="text-[11px] text-slate-500 uppercase font-semibold tracking-wider">Revision</p>
</div>
<p className="text-sm font-bold text-slate-900">
{revision}
</p>
<p className="text-sm font-medium text-slate-900">{revision}</p>
</div>
{/* Repository - Full Width */}
<div className="col-span-2 p-3 bg-white border border-slate-200 rounded-lg hover:border-blue-500/30 transition-colors">
<div className="flex items-center gap-2 mb-2">
<Package className="w-4 h-4 text-blue-400" />
<p className="text-xs text-slate-500 uppercase font-semibold tracking-wider">Repository</p>
<div>
<div className="flex items-center gap-1 mb-0.5">
<Calendar className="w-3 h-3 text-amber-400 flex-shrink-0" />
<p className="text-[11px] text-slate-500 uppercase font-semibold tracking-wider">Launched</p>
</div>
<p className="text-sm font-mono text-slate-900 truncate" title={repository}>
{repository}
</p>
</div>
{/* Launched Date - Full Width */}
<div className="col-span-2 p-3 bg-white border border-slate-200 rounded-lg hover:border-amber-500/30 transition-colors">
<div className="flex items-center gap-2 mb-2">
<Calendar className="w-4 h-4 text-amber-400" />
<p className="text-xs text-slate-500 uppercase font-semibold tracking-wider">Launched</p>
</div>
<p className="text-sm font-bold text-slate-900">
{createdAtText}
</p>
<p className="text-sm font-medium text-slate-900">{createdAtText}</p>
</div>
</div>
{lastError && (
<div className="flex items-start gap-3 p-4 border border-rose-500/30 bg-rose-500/10 rounded-lg">
<div className="p-2 bg-rose-500/20 rounded-lg border border-rose-500/40">
<AlertTriangle className="w-5 h-5 text-rose-700" />
</div>
<div>
<p className="text-sm font-semibold text-rose-200">Last error</p>
<p className="text-sm text-rose-100/90">{lastError}</p>
<div className="flex items-start gap-2 p-2.5 border border-rose-500/30 bg-rose-500/10 rounded-lg">
<AlertTriangle className="w-4 h-4 text-rose-500 flex-shrink-0 mt-0.5" />
<div className="min-w-0">
<p className="text-xs font-semibold text-rose-700">Last error</p>
<p className="text-xs text-rose-600 truncate">{lastError}</p>
</div>
</div>
)}
</div>
{/* Scale Controls */}
{instance.status === "deployed" && (
<div className="flex items-center justify-between gap-2 px-6 py-3 bg-slate-50/50 border-t border-gray-100 dark:border-gray-700">
<span className="text-xs text-gray-500 dark:text-gray-400 font-medium">Replicas:</span>
<div className="flex items-center gap-1">
<button
onClick={() => handleScale(-1)}
disabled={scaling || currentReplicas <= 0}
className="inline-flex items-center justify-center w-8 h-8 rounded-lg border border-slate-200 bg-white text-slate-600 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50 disabled:opacity-40 disabled:cursor-not-allowed transition-all duration-150"
title="Scale down"
>
{scaling ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Minus className="w-4 h-4" />
)}
</button>
<span className="inline-flex items-center justify-center min-w-[2.5rem] px-2 py-1 text-sm font-bold text-slate-900 bg-white border border-slate-200 rounded-lg">
{currentReplicas}
</span>
<button
onClick={() => handleScale(1)}
disabled={scaling}
className="inline-flex items-center justify-center w-8 h-8 rounded-lg border border-slate-200 bg-white text-slate-600 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50 disabled:opacity-40 disabled:cursor-not-allowed transition-all duration-150"
title="Scale up"
>
{scaling ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Plus className="w-4 h-4" />
)}
</button>
</div>
</div>
)}
{/* Enhanced Actions Bar */}
<div className="relative px-6 py-4 bg-gradient-to-r from-slate-50 via-slate-50 to-white border-t border-slate-200 backdrop-blur-sm">
<div className="grid grid-cols-2 gap-2 md:grid-cols-2 xl:grid-cols-4">

View File

@ -7,7 +7,7 @@ import React, { useState, useEffect } from "react";
import { Settings } from "lucide-react";
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
import type { InstanceResponse, UpdateInstanceRequest } from "@/api";
import { getValuesSchema } from "@/api";
import { getValuesSchema, getInstanceValuesDiff } from "@/api";
import {
Modal,
Button,
@ -44,6 +44,15 @@ export const ModifyModal: React.FC<ModifyModalProps> = ({
const [inputMethod, setInputMethod] = useState<'form' | 'yaml'>('yaml');
const [formValues, setFormValues] = useState<Record<string, any>>({});
// Values Diff support
const [showDiff, setShowDiff] = useState(false);
const [loadingDiff, setLoadingDiff] = useState(false);
const [diffData, setDiffData] = useState<{
current: Record<string, any>;
defaults: Record<string, any>;
} | null>(null);
const [diffError, setDiffError] = useState<string | null>(null);
// Initialize with current values
useEffect(() => {
setTag(instance.version || "");
@ -65,6 +74,9 @@ export const ModifyModal: React.FC<ModifyModalProps> = ({
// Load values schema
loadValuesSchema();
// Load values diff
loadValuesDiff();
}, [instance]);
const loadValuesSchema = async () => {
@ -100,6 +112,61 @@ export const ModifyModal: React.FC<ModifyModalProps> = ({
}
};
const loadValuesDiff = async () => {
if (!instance.clusterId || !instance.id) return;
setLoadingDiff(true);
setDiffError(null);
setDiffData(null);
try {
const data = await getInstanceValuesDiff(instance.clusterId, instance.id);
if (data && data.current && data.defaults) {
setDiffData({ current: data.current, defaults: data.defaults });
}
} catch (err) {
console.error("[ModifyModal] Failed to load values diff:", err);
setDiffError("Failed to load values diff");
} finally {
setLoadingDiff(false);
}
};
const applyDefaults = () => {
if (!diffData?.defaults) return;
const defaultYaml = stringifyYaml(diffData.defaults);
setValuesYaml(defaultYaml);
setFormValues(diffData.defaults);
};
/**
* Render a values object as YAML lines, bolding keys that differ from defaults.
*/
const renderDiffValues = (
values: Record<string, any>,
compare: Record<string, any>,
): React.ReactNode => {
const yaml = stringifyYaml(values);
const lines = yaml.split("\n");
return lines.map((line, i) => {
// Extract the key name from a YAML line
const keyMatch = line.match(/^(\s*)([a-zA-Z_][\w-]*)\s*:/);
if (keyMatch) {
const key = keyMatch[2];
const keyChanged =
compare[key] !== undefined &&
JSON.stringify(values[key]) !== JSON.stringify(compare[key]);
if (keyChanged) {
return (
<span key={i} className="block">
{keyMatch[1]}<strong className="text-amber-600 dark:text-amber-400">{key}</strong>:{line.slice(keyMatch[0].length)}
</span>
);
}
}
return <span key={i} className="block">{line}</span>;
});
};
const handleFormValuesChange = (values: Record<string, any>) => {
setFormValues(values);
setValuesYaml(stringifyYaml(values));
@ -266,6 +333,80 @@ export const ModifyModal: React.FC<ModifyModalProps> = ({
)}
</div>
{/* Values Diff Section */}
{instance.clusterId && instance.id && (
<div className="border-t border-slate-200 pt-3">
<button
type="button"
onClick={() => {
if (!showDiff && !diffData) {
loadValuesDiff();
}
setShowDiff(!showDiff);
}}
className="flex items-center gap-2 text-sm font-medium text-indigo-600 hover:text-indigo-700 transition-colors"
>
<span>{showDiff ? "Hide" : "Show"} Values Diff</span>
<span className={`text-xs transition-transform ${showDiff ? "rotate-180" : ""}`}></span>
</button>
{showDiff && (
<div className="mt-3 space-y-3">
{loadingDiff && (
<LoadingState message="Loading values diff..." />
)}
{diffError && (
<ErrorState title="Diff Error" message={diffError} />
)}
{diffData && (
<>
<div className="grid grid-cols-2 gap-3">
{/* Current Values */}
<div>
<div className="flex items-center gap-2 mb-1">
<span className="text-xs font-semibold uppercase tracking-wider text-slate-500">
Current
</span>
<Badge variant="default" size="sm">deployed</Badge>
</div>
<pre className="text-xs font-mono bg-slate-50 border border-slate-200 rounded-lg p-3 max-h-64 overflow-auto whitespace-pre text-slate-700">
{renderDiffValues(diffData.current, diffData.defaults)}
</pre>
</div>
{/* Default Values */}
<div>
<div className="flex items-center gap-2 mb-1">
<span className="text-xs font-semibold uppercase tracking-wider text-slate-500">
Defaults
</span>
<Badge variant="info" size="sm">chart</Badge>
</div>
<pre className="text-xs font-mono bg-slate-50 border border-slate-200 rounded-lg p-3 max-h-64 overflow-auto whitespace-pre text-slate-500">
{renderDiffValues(diffData.defaults, diffData.current)}
</pre>
</div>
</div>
{/* Legend */}
<p className="text-xs text-slate-500">
<strong className="text-amber-600 dark:text-amber-400">Bold amber keys</strong> differ between current and default values.
</p>
{/* Use Defaults Button */}
<button
type="button"
onClick={applyDefaults}
className="inline-flex items-center gap-1.5 text-xs font-medium text-indigo-600 hover:text-indigo-700 bg-indigo-50 hover:bg-indigo-100 border border-indigo-200 rounded-lg px-3 py-1.5 transition-all"
title="Replace current values with chart defaults"
>
<Settings className="w-3.5 h-3.5" />
Use Defaults
</button>
</>
)}
</div>
)}
</div>
)}
<p className="text-xs text-slate-500">
Update applies the selected chart version and values override. Resource readiness is tracked from the instance list after submit.
</p>