refactor: update agent API schemas, standardize UI text styling, and enhance settlement credit ledger components
This commit is contained in:
@@ -4,10 +4,8 @@ import { ChevronRight, Search } from "lucide-react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { AdminStatusBadge } from "@/components/admin/admin-status-badge";
|
||||
import { AdminNoResourceState, AdminTableNoResourceRow } from "@/components/admin/admin-no-resource-state";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { resolveRoleStatusTone } from "@/lib/admin-status-tone";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { formatAdminCreditMajorDecimal } from "@/lib/money";
|
||||
import type { AgentNodeRow } from "@/types/api/admin-agent";
|
||||
@@ -66,10 +64,6 @@ function collectExpandableIds(nodes: AgentNodeRow[], into: Set<number>): void {
|
||||
}
|
||||
}
|
||||
|
||||
function unwrapSiteRoots(nodes: AgentNodeRow[]): AgentNodeRow[] {
|
||||
return nodes.flatMap((node) => (node.is_root ? (node.children ?? []) : [node]));
|
||||
}
|
||||
|
||||
export type AgentLineSidebarProps = {
|
||||
siteLabel: string | null;
|
||||
/** API 返回的嵌套树(含 children) */
|
||||
@@ -110,8 +104,8 @@ function TreeRow({
|
||||
<li>
|
||||
<div
|
||||
className={cn(
|
||||
"flex w-full items-start gap-0.5 rounded-lg py-1.5 pr-2 transition-colors",
|
||||
active ? "bg-primary/12 ring-1 ring-primary/30 shadow-sm" : "hover:bg-background/80",
|
||||
"flex w-full items-start gap-0.5 rounded-md py-1 pr-2 transition-colors",
|
||||
active ? "bg-primary/10 ring-1 ring-primary/25" : "hover:bg-background/80",
|
||||
)}
|
||||
style={{ paddingLeft: `${6 + indent}px` }}
|
||||
>
|
||||
@@ -120,7 +114,7 @@ function TreeRow({
|
||||
type="button"
|
||||
aria-expanded={expanded}
|
||||
aria-label={expanded ? t("lineUi.collapse", { defaultValue: "收起" }) : t("lineUi.expand", { defaultValue: "展开" })}
|
||||
className="mt-1 flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted"
|
||||
className="mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onToggleExpand(node.id);
|
||||
@@ -132,7 +126,7 @@ function TreeRow({
|
||||
/>
|
||||
</button>
|
||||
) : (
|
||||
<span className="mt-1 inline-block size-6 shrink-0" aria-hidden />
|
||||
<span className="mt-0.5 inline-block size-5 shrink-0" aria-hidden />
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
@@ -141,18 +135,8 @@ function TreeRow({
|
||||
className="min-w-0 flex-1 px-1 py-0.5 text-left"
|
||||
onClick={() => onSelect(node)}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="truncate text-sm font-medium">{node.name}</span>
|
||||
<AdminStatusBadge
|
||||
tone={resolveRoleStatusTone(node.status)}
|
||||
className="shrink-0 px-1.5 py-0 text-[10px]"
|
||||
>
|
||||
{node.status === 1
|
||||
? t("common:status.enabled", { defaultValue: "启用" })
|
||||
: t("common:status.disabled", { defaultValue: "停用" })}
|
||||
</AdminStatusBadge>
|
||||
</div>
|
||||
<p className="mt-0.5 truncate font-mono text-[11px] text-muted-foreground">
|
||||
<div className="truncate text-sm font-medium leading-5">{node.name}</div>
|
||||
<p className="truncate text-xs leading-5 text-muted-foreground">
|
||||
{node.username ?? node.code}
|
||||
</p>
|
||||
</button>
|
||||
@@ -192,9 +176,7 @@ export function AgentLineSidebar({
|
||||
const normalizedKeyword = keyword.trim().toLowerCase();
|
||||
|
||||
const displayForest = useMemo(() => {
|
||||
const pruned = pruneTreeForSearch(tree, normalizedKeyword, parentNameMap);
|
||||
|
||||
return unwrapSiteRoots(pruned);
|
||||
return pruneTreeForSearch(tree, normalizedKeyword, parentNameMap);
|
||||
}, [normalizedKeyword, parentNameMap, tree]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user