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

@ -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>