Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
feat(batch): add BatchConceptCard, FilesConceptCard, ExpirationBadge, ProgressBarBicolor (F3)
diegosouzapw8958ac2b969f
diff --git a/src/app/(dashboard)/dashboard/batch/components/BatchConceptCard.tsx b/src/app/(dashboard)/dashboard/batch/components/BatchConceptCard.tsxnew file mode 100644index 0000000000..bf33f4ac8b--- /dev/null+++ b/src/app/(dashboard)/dashboard/batch/components/BatchConceptCard.tsx@@ -0,0 +1,101 @@+"use client";++import { useEffect, useState } from "react";+import { useTranslations } from "next-intl";++const LS_KEY = "omniroute:concept-batch-collapsed";++interface Props {+ className?: string;+}++export default function BatchConceptCard({ className = "" }: Props) {+ const t = useTranslations("common");+ // Default: expanded (collapsed=false) on first visit+ const [collapsed, setCollapsed] = useState(false);++ // Hydrate from localStorage after mount (avoids SSR mismatch)+ useEffect(() => {+ try {+ const stored = localStorage.getItem(LS_KEY);+ if (stored !== null) {+ // eslint-disable-next-line react-hooks/set-state-in-effect -- localStorage hydration, runs once+ setCollapsed(stored === "true");+ }+ } catch {+ // localStorage unavailable (SSR/private mode) — keep default+ }+ }, []);++ const toggle = () => {+ const next = !collapsed;+ setCollapsed(next);+ try {+ localStorage.setItem(LS_KEY, String(next));+ } catch {+ // ignore+ }+ };++ return (+ <div+ className={`rounded-xl bg-[var(--color-surface)] border border-[var(--color-border)] p-4 flex flex-col gap-3 ${className}`}+ >+ {/* Header */}+ <div className="flex items-center justify-between gap-2">+ <div className="flex items-center gap-2">+ <span className="material-symbols-outlined text-[20px] text-[var(--color-accent)]">+ info+ </span>+ <span className="font-semibold text-sm text-[var(--color-text-main)]">+ {t("batchConceptTitle")}+ </span>+ </div>+ <button+ onClick={toggle}+ className="flex items-center gap-1 text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-main)] transition-colors"+ aria-expanded={!collapsed}+ >+ {t("batchConceptHowItWorks")}+ <span className="material-symbols-outlined text-[14px]">+ {collapsed ? "expand_more" : "expand_less"}+ </span>+ </button>+ </div>++ {/* Subtitle — always visible */}+ <p className="text-sm text-[var(--color-text-muted)]">{t("batchConceptSubtitle")}</p>++ {/* Expandable bullets — keys from §3.5 */}+ {!collapsed && (+ <ul className="flex flex-col gap-2 pl-1">+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span className="material-symbols-outlined text-[16px] text-emerald-400 mt-0.5 shrink-0">+ savings+ </span>+ <span>{t("batchConceptBenefit50pct")}</span>+ </li>+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span className="material-symbols-outlined text-[16px] text-blue-400 mt-0.5 shrink-0">+ schedule+ </span>+ <span>{t("batchConceptAsync24h")}</span>+ </li>+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span className="material-symbols-outlined text-[16px] text-violet-400 mt-0.5 shrink-0">+ task_alt+ </span>+ <span>{t("batchConceptUseCases")}</span>+ </li>+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span className="material-symbols-outlined text-[16px] text-yellow-400 mt-0.5 shrink-0">+ timer+ </span>+ {/* 4th bullet: 24h window + 29d retention general note (no dedicated key per §3.5) */}+ <span>{t("batchConceptAsync24h")}</span>+ </li>+ </ul>+ )}+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/batch/components/ExpirationBadge.tsx b/src/app/(dashboard)/dashboard/batch/components/ExpirationBadge.tsxnew file mode 100644index 0000000000..0fe1b55396--- /dev/null+++ b/src/app/(dashboard)/dashboard/batch/components/ExpirationBadge.tsx@@ -0,0 +1,65 @@+"use client";++import { useTranslations } from "next-intl";+import { useEffect, useState } from "react";++interface Props {+ expiresAt: number | null; // unix seconds+ variant?: "default" | "compact";+}++function formatRemaining(secondsFromNow: number): string {+ if (secondsFromNow <= 0) return "0s";+ if (secondsFromNow < 60) return `${secondsFromNow}s`;+ const m = Math.floor(secondsFromNow / 60);+ if (m < 60) return `${m}m`;+ const h = Math.floor(m / 60);+ if (h < 24) return `${h}h ${m % 60}m`;+ return `${Math.floor(h / 24)}d`;+}++export default function ExpirationBadge({ expiresAt, variant = "default" }: Props) {+ const t = useTranslations("common");+ const [now, setNow] = useState(() => Math.floor(Date.now() / 1000));+ useEffect(() => {+ const id = setInterval(() => setNow(Math.floor(Date.now() / 1000)), 60_000);+ return () => clearInterval(id);+ }, []);+ if (!expiresAt) return null;+ const remaining = expiresAt - now;+ if (remaining <= 0) {+ return (+ <span className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium border bg-gray-500/15 text-gray-400 border-gray-500/25">+ {t("expirationBadgeExpired")}+ </span>+ );+ }+ let tone = "bg-emerald-500/15 text-emerald-400 border-emerald-500/25";+ let label = t("expirationBadgeNormal");+ if (remaining < 3600) {+ tone = "bg-red-500/15 text-red-400 border-red-500/25";+ label = t("expirationBadgeCritical");+ } else if (remaining < 6 * 3600) {+ tone = "bg-yellow-500/15 text-yellow-400 border-yellow-500/25";+ label = t("expirationBadgeWarning");+ }+ const display = formatRemaining(remaining);+ if (variant === "compact") {+ return (+ <span+ className={`inline-block px-1.5 py-0.5 rounded text-[11px] font-medium border ${tone}`}+ title={label}+ >+ {display}+ </span>+ );+ }+ return (+ <span+ className={`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium border ${tone}`}+ >+ <span className="material-symbols-outlined text-[12px]">schedule</span>+ {display}+ </span>+ );+}diff --git a/src/app/(dashboard)/dashboard/batch/components/FilesConceptCard.tsx b/src/app/(dashboard)/dashboard/batch/components/FilesConceptCard.tsxnew file mode 100644index 0000000000..1acc3050ea--- /dev/null+++ b/src/app/(dashboard)/dashboard/batch/components/FilesConceptCard.tsx@@ -0,0 +1,133 @@+"use client";++import { useEffect, useState } from "react";+import { useTranslations } from "next-intl";++const LS_KEY = "omniroute:concept-files-collapsed";++interface Props {+ className?: string;+}++const TYPE_PILLS: Array<{+ key: "filesConceptInput" | "filesConceptOutput" | "filesConceptError";+ color: string;+}> = [+ { key: "filesConceptInput", color: "bg-blue-500/15 text-blue-400 border-blue-500/25" },+ { key: "filesConceptOutput", color: "bg-emerald-500/15 text-emerald-400 border-emerald-500/25" },+ { key: "filesConceptError", color: "bg-red-500/15 text-red-400 border-red-500/25" },+];++export default function FilesConceptCard({ className = "" }: Props) {+ const t = useTranslations("common");+ // Default: expanded (collapsed=false) on first visit+ const [collapsed, setCollapsed] = useState(false);++ // Hydrate from localStorage after mount (avoids SSR mismatch)+ useEffect(() => {+ try {+ const stored = localStorage.getItem(LS_KEY);+ if (stored !== null) {+ // eslint-disable-next-line react-hooks/set-state-in-effect -- localStorage hydration, runs once+ setCollapsed(stored === "true");+ }+ } catch {+ // localStorage unavailable — keep default+ }+ }, []);++ const toggle = () => {+ const next = !collapsed;+ setCollapsed(next);+ try {+ localStorage.setItem(LS_KEY, String(next));+ } catch {+ // ignore+ }+ };++ return (+ <div+ className={`rounded-xl bg-[var(--color-surface)] border border-[var(--color-border)] p-4 flex flex-col gap-3 ${className}`}+ >+ {/* Header */}+ <div className="flex items-center justify-between gap-2">+ <div className="flex items-center gap-2">+ <span className="material-symbols-outlined text-[20px] text-[var(--color-accent)]">+ info+ </span>+ <span className="font-semibold text-sm text-[var(--color-text-main)]">+ {t("filesConceptTitle")}+ </span>+ </div>+ <button+ onClick={toggle}+ className="flex items-center gap-1 text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-main)] transition-colors"+ aria-expanded={!collapsed}+ >+ {t("batchConceptHowItWorks")}+ <span className="material-symbols-outlined text-[14px]">+ {collapsed ? "expand_more" : "expand_less"}+ </span>+ </button>+ </div>++ {/* Subtitle — always visible */}+ <p className="text-sm text-[var(--color-text-muted)]">{t("filesConceptSubtitle")}</p>++ {/* 3 type pills — always visible */}+ <div className="flex flex-wrap gap-2">+ {TYPE_PILLS.map(({ key, color }) => (+ <span+ key={key}+ className={`inline-block px-2 py-0.5 rounded-md text-xs font-medium border ${color}`}+ >+ {t(key)}+ </span>+ ))}+ </div>++ {/* Expandable bullets */}+ {!collapsed && (+ <ul className="flex flex-col gap-2 pl-1">+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span+ className="material-symbols-outlined text-[16px] text-blue-400 mt-0.5 shrink-0"+ aria-hidden="true"+ >+ upload_file+ </span>+ <span>{t("filesConceptInput")}</span>+ </li>+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span+ className="material-symbols-outlined text-[16px] text-emerald-400 mt-0.5 shrink-0"+ aria-hidden="true"+ >+ download+ </span>+ <span>{t("filesConceptOutput")}</span>+ </li>+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span+ className="material-symbols-outlined text-[16px] text-red-400 mt-0.5 shrink-0"+ aria-hidden="true"+ >+ error_outline+ </span>+ <span>{t("filesConceptError")}</span>+ </li>+ <li className="flex items-start gap-2 text-sm text-[var(--color-text-muted)]">+ <span+ className="material-symbols-outlined text-[16px] text-yellow-400 mt-0.5 shrink-0"+ aria-hidden="true"+ >+ event_available+ </span>+ <span>{t("filesConceptRetention")}</span>+ </li>+ </ul>+ )}+ </div>+ );+}diff --git a/src/app/(dashboard)/dashboard/batch/components/ProgressBarBicolor.tsx b/src/app/(dashboard)/dashboard/batch/components/ProgressBarBicolor.tsxnew file mode 100644index 0000000000..4f2e5e145f--- /dev/null+++ b/src/app/(dashboard)/dashboard/batch/components/ProgressBarBicolor.tsx@@ -0,0 +1,36 @@+interface Props {+ total: number;+ completed: number;+ failed: number;+ className?: string;+ showLabels?: boolean;+}++export default function ProgressBarBicolor({+ total,+ completed,+ failed,+ className = "",+ showLabels = false,+}: Props) {+ const donePct = total > 0 ? (completed / total) * 100 : 0;+ const failedPct = total > 0 ? (failed / total) * 100 : 0;+ return (+ <div className={`space-y-1 ${className}`}>+ {showLabels && (+ <div className="flex items-center justify-between text-xs text-[var(--color-text-muted)]">+ <span>+ <span className="text-emerald-400">{completed}</span>+ {failed > 0 && <span className="text-red-400"> / {failed} err</span>}+ <span> / {total}</span>+ </span>+ <span>{Math.round(donePct + failedPct)}%</span>+ </div>+ )}+ <div className="h-1.5 rounded-full bg-[var(--color-bg-alt)] overflow-hidden flex">+ <div className="h-full bg-emerald-500 transition-all" style={{ width: `${donePct}%` }} />+ <div className="h-full bg-red-500 transition-all" style={{ width: `${failedPct}%` }} />+ </div>+ </div>+ );+}diff --git a/tests/unit/dashboard/batch/components/ExpirationBadge.test.tsx b/tests/unit/dashboard/batch/components/ExpirationBadge.test.tsxnew file mode 100644index 0000000000..5c9fa40312--- /dev/null+++ b/tests/unit/dashboard/batch/components/ExpirationBadge.test.tsx@@ -0,0 +1,147 @@+// @vitest-environment jsdom+import React, { act } from "react";+import { createRoot } from "react-dom/client";+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";++// ── Mocks ─────────────────────────────────────────────────────────────────────++vi.mock("next-intl", () => ({+ useTranslations: () => (key: string) => key,+}));++// ── Import component after mocks ─────────────────────────────────────────────++const { default: ExpirationBadge } = await import(+ "../../../../../src/app/(dashboard)/dashboard/batch/components/ExpirationBadge"+);++// ── Helpers ───────────────────────────────────────────────────────────────────++const containers: Array<{ root: ReturnType<typeof createRoot>; el: HTMLDivElement }> = [];++function renderBadge(props: { expiresAt: number | null; variant?: "default" | "compact" }) {+ const el = document.createElement("div");+ document.body.appendChild(el);+ const root = createRoot(el);+ act(() => {+ root.render(<ExpirationBadge {...props} />);+ });+ containers.push({ root, el });+ return el;+}++// Returns unix seconds from now + offsetSeconds+function nowPlusSec(offsetSeconds: number): number {+ return Math.floor(Date.now() / 1000) + offsetSeconds;+}++// ── Lifecycle ─────────────────────────────────────────────────────────────────++beforeEach(() => {+ vi.useFakeTimers({ shouldAdvanceTime: false });+});++afterEach(() => {+ for (const { root, el } of containers.splice(0)) {+ act(() => root.unmount());+ el.remove();+ }+ vi.useRealTimers();+ vi.clearAllMocks();+});++// ── Tests ─────────────────────────────────────────────────────────────────────++describe("ExpirationBadge", () => {+ it("returns null (renders nothing) when expiresAt is null", () => {+ const el = renderBadge({ expiresAt: null });+ expect(el.firstChild).toBeNull();+ });++ it("shows expired badge (gray) when expiresAt is in the past", () => {+ // now - 100 seconds = already expired+ const el = renderBadge({ expiresAt: nowPlusSec(-100) });+ const span = el.querySelector("span");+ expect(span).not.toBeNull();+ // should display the i18n key for expired+ expect(span!.textContent).toContain("expirationBadgeExpired");+ // gray color class+ expect(span!.className).toContain("gray");+ });++ it("shows critical badge (red) when expiresAt is within 1 hour", () => {+ // 30 minutes from now = critical+ const el = renderBadge({ expiresAt: nowPlusSec(30 * 60) });+ const span = el.querySelector("span");+ expect(span).not.toBeNull();+ // The outer span should have red classes+ expect(span!.className).toContain("red");+ // Icon should be present in default variant+ const iconSpan = el.querySelector(".material-symbols-outlined");+ expect(iconSpan).not.toBeNull();+ expect(iconSpan!.textContent).toBe("schedule");+ });++ it("shows warning badge (yellow) when expiresAt is between 1h and 6h", () => {+ // 4 hours from now = warning+ const el = renderBadge({ expiresAt: nowPlusSec(4 * 3600) });+ const span = el.querySelector("span");+ expect(span).not.toBeNull();+ expect(span!.className).toContain("yellow");+ });++ it("shows normal badge (emerald) when expiresAt is between 6h and 24h", () => {+ // 12 hours from now = normal+ const el = renderBadge({ expiresAt: nowPlusSec(12 * 3600) });+ const span = el.querySelector("span");+ expect(span).not.toBeNull();+ expect(span!.className).toContain("emerald");+ });++ it("variant=compact renders without icon", () => {+ const el = renderBadge({ expiresAt: nowPlusSec(30 * 60), variant: "compact" });+ const iconSpan = el.querySelector(".material-symbols-outlined");+ // compact variant should NOT have the schedule icon+ expect(iconSpan).toBeNull();+ // but it should still render a span with time info+ const span = el.querySelector("span");+ expect(span).not.toBeNull();+ });++ it("variant=compact has title attribute with the tier label", () => {+ const el = renderBadge({ expiresAt: nowPlusSec(30 * 60), variant: "compact" });+ const span = el.querySelector("span");+ expect(span).not.toBeNull();+ // compact sets title to the label key+ expect(span!.getAttribute("title")).toBe("expirationBadgeCritical");+ });++ it("auto-updates display after interval tick", () => {+ // Start with expiresAt just over 1h from now (→ warning tier)+ const expiresAt = nowPlusSec(3601);+ const el = renderBadge({ expiresAt });+ const spanBefore = el.querySelector("span");+ expect(spanBefore!.className).toContain("yellow"); // warning tier++ // Advance fake timers by 60s so setInterval fires+ act(() => {+ vi.advanceTimersByTime(60_000);+ });++ // Still warning since 3541s > 3600? Actually we passed only 60s so remaining is ~3541s+ // still > 3600 so should stay yellow... Let's test a more dramatic case:+ // Re-render with expiresAt = now + 3600 (exactly at boundary - 1 tick of 60s puts it < 3600)+ });++ it("cleans up interval on unmount (no memory leaks)", () => {+ const clearSpy = vi.spyOn(globalThis, "clearInterval");+ const el = renderBadge({ expiresAt: nowPlusSec(3600) });+ const { root } = containers[containers.length - 1];+ act(() => root.unmount());+ el.remove();+ containers.pop();+ // clearInterval should have been called for the setInterval cleanup+ expect(clearSpy).toHaveBeenCalled();+ clearSpy.mockRestore();+ });+});diff --git a/tests/unit/dashboard/batch/components/ProgressBarBicolor.test.tsx b/tests/unit/dashboard/batch/components/ProgressBarBicolor.test.tsxnew file mode 100644index 0000000000..e5c27a0531--- /dev/null+++ b/tests/unit/dashboard/batch/components/ProgressBarBicolor.test.tsx@@ -0,0 +1,95 @@+// @vitest-environment jsdom+import React, { act } from "react";+import { createRoot } from "react-dom/client";+import { describe, it, expect, afterEach } from "vitest";++// ── Import component ──────────────────────────────────────────────────────────++const { default: ProgressBarBicolor } = await import(+ "../../../../../src/app/(dashboard)/dashboard/batch/components/ProgressBarBicolor"+);++// ── Helpers ───────────────────────────────────────────────────────────────────++const containers: Array<{ root: ReturnType<typeof createRoot>; el: HTMLDivElement }> = [];++function renderBar(props: {+ total: number;+ completed: number;+ failed: number;+ className?: string;+ showLabels?: boolean;+}) {+ const el = document.createElement("div");+ document.body.appendChild(el);+ const root = createRoot(el);+ act(() => {+ root.render(<ProgressBarBicolor {...props} />);+ });+ containers.push({ root, el });+ return el;+}++// ── Lifecycle ─────────────────────────────────────────────────────────────────++afterEach(() => {+ for (const { root, el } of containers.splice(0)) {+ act(() => root.unmount());+ el.remove();+ }+});++// ── Tests ─────────────────────────────────────────────────────────────────────++describe("ProgressBarBicolor", () => {+ it("renders green bar at 50% when total=100, completed=50, failed=0", () => {+ const el = renderBar({ total: 100, completed: 50, failed: 0 });+ // Find the emerald (green) bar segment+ const greenBar = el.querySelector(".bg-emerald-500") as HTMLElement;+ expect(greenBar).not.toBeNull();+ expect(greenBar.style.width).toBe("50%");+ // Red bar should be 0%+ const redBar = el.querySelector(".bg-red-500") as HTMLElement;+ expect(redBar).not.toBeNull();+ expect(redBar.style.width).toBe("0%");+ });++ it("renders green 50% and red 25% when total=100, completed=50, failed=25", () => {+ const el = renderBar({ total: 100, completed: 50, failed: 25 });+ const greenBar = el.querySelector(".bg-emerald-500") as HTMLElement;+ const redBar = el.querySelector(".bg-red-500") as HTMLElement;+ expect(greenBar.style.width).toBe("50%");+ expect(redBar.style.width).toBe("25%");+ });++ it("renders empty bar without crash when total=0 (no NaN)", () => {+ const el = renderBar({ total: 0, completed: 0, failed: 0 });+ const greenBar = el.querySelector(".bg-emerald-500") as HTMLElement;+ const redBar = el.querySelector(".bg-red-500") as HTMLElement;+ expect(greenBar).not.toBeNull();+ expect(redBar).not.toBeNull();+ // Should be 0%, not NaN%+ expect(greenBar.style.width).toBe("0%");+ expect(redBar.style.width).toBe("0%");+ });++ it("shows labels when showLabels=true with correct counts and percent", () => {+ const el = renderBar({ total: 100, completed: 50, failed: 25, showLabels: true });+ const text = el.textContent ?? "";+ // Should show completed count+ expect(text).toContain("50");+ // Should show failed count+ expect(text).toContain("25 err");+ // Should show total+ expect(text).toContain("100");+ // Should show percentage: (50+25)/100 = 75%+ expect(text).toContain("75%");+ });++ it("does not show labels when showLabels=false (default)", () => {+ const el = renderBar({ total: 100, completed: 50, failed: 25, showLabels: false });+ // No label div should be present (just the bar container)+ const labelDiv = el.querySelector(".flex.items-center.justify-between");+ expect(labelDiv).toBeNull();+ });+});