fix(frontend): address review feedback — lint, format, and bug fixes

- Remove unused Button import in PulseChips (fixes lint CI failure)
- Fix AutoPilotBridgeContext: use Next.js router + sessionStorage instead
  of window.location.href which destroyed React state before consumption
- Add defensive handling in formatTimeAgo for invalid/future dates
- Use cn() utility in LibraryAgentCard for className consistency
- Fix prettier formatting across AgentFilterMenu, SitrepList, useAgentStatus
This commit is contained in:
Bentlybro
2026-03-31 17:22:23 +00:00
parent 8277cce835
commit b73d05c23e
7 changed files with 47 additions and 36 deletions

View File

@@ -1,7 +1,6 @@
"use client";
import { Text } from "@/components/atoms/Text/Text";
import { Button } from "@/components/atoms/Button/Button";
import { ArrowRightIcon } from "@phosphor-icons/react";
import NextLink from "next/link";
import { StatusBadge } from "@/app/(platform)/library/components/StatusBadge/StatusBadge";

View File

@@ -24,9 +24,7 @@ export function AgentFilterMenu({ value, onChange, summary }: Props) {
return (
<div className="flex items-center" data-testid="agent-filter-dropdown">
<span className="hidden whitespace-nowrap text-sm sm:inline">
filter
</span>
<span className="hidden whitespace-nowrap text-sm sm:inline">filter</span>
<Select value={value} onValueChange={handleChange}>
<SelectTrigger className="ml-1 w-fit space-x-1 border-none px-0 text-sm underline underline-offset-4 shadow-none">
<FunnelIcon className="h-4 w-4 sm:hidden" />
@@ -35,9 +33,7 @@ export function AgentFilterMenu({ value, onChange, summary }: Props) {
<SelectContent>
<SelectGroup>
<SelectItem value="all">All Agents</SelectItem>
<SelectItem value="running">
Running ({summary.running})
</SelectItem>
<SelectItem value="running">Running ({summary.running})</SelectItem>
<SelectItem value="attention">
Needs Attention ({summary.error})
</SelectItem>
@@ -47,9 +43,7 @@ export function AgentFilterMenu({ value, onChange, summary }: Props) {
<SelectItem value="scheduled">
Scheduled ({summary.scheduled})
</SelectItem>
<SelectItem value="idle">
Idle / Stale ({summary.idle})
</SelectItem>
<SelectItem value="idle">Idle / Stale ({summary.idle})</SelectItem>
<SelectItem value="healthy">Healthy</SelectItem>
</SelectGroup>
</SelectContent>

View File

@@ -13,6 +13,7 @@ import Avatar, {
} from "@/components/atoms/Avatar/Avatar";
import { Link } from "@/components/atoms/Link/Link";
import { Progress } from "@/components/atoms/Progress/Progress";
import { cn } from "@/lib/utils";
import { AgentCardMenu } from "./components/AgentCardMenu";
import { FavoriteButton } from "./components/FavoriteButton";
import { useLibraryAgentCard } from "./useLibraryAgentCard";
@@ -61,11 +62,12 @@ export function LibraryAgentCard({ agent, draggable = true }: Props) {
layoutId={`agent-card-${id}`}
data-testid="library-agent-card"
data-agent-id={id}
className={`group relative inline-flex h-auto min-h-[10.625rem] w-full max-w-[25rem] flex-col items-start justify-start gap-2.5 rounded-medium border bg-white hover:shadow-md ${
className={cn(
"group relative inline-flex h-auto min-h-[10.625rem] w-full max-w-[25rem] flex-col items-start justify-start gap-2.5 rounded-medium border bg-white hover:shadow-md",
hasError
? "border-l-2 border-l-red-400 border-t-zinc-100 border-r-zinc-100 border-b-zinc-100"
: "border-zinc-100"
}`}
? "border-l-2 border-b-zinc-100 border-l-red-400 border-r-zinc-100 border-t-zinc-100"
: "border-zinc-100",
)}
transition={{
type: "spring",
damping: 25,
@@ -206,4 +208,3 @@ export function LibraryAgentCard({ agent, draggable = true }: Props) {
</div>
);
}

View File

@@ -36,11 +36,7 @@ export function SitrepList({ agentIDs, maxItems = 10 }: Props) {
</div>
<div className="space-y-1">
{items.map((item) => (
<SitrepItem
key={item.id}
item={item}
onAskAutoPilot={sendPrompt}
/>
<SitrepItem key={item.id} item={item} onAskAutoPilot={sendPrompt} />
))}
</div>
</div>

View File

@@ -3,7 +3,10 @@
* e.g. "3m ago", "2h ago", "5d ago".
*/
export function formatTimeAgo(isoDate: string): string {
const diff = Date.now() - new Date(isoDate).getTime();
const parsed = new Date(isoDate).getTime();
if (Number.isNaN(parsed)) return "unknown";
const diff = Date.now() - parsed;
if (diff < 0) return "just now";
const minutes = Math.floor(diff / 60000);
if (minutes < 60) return `${minutes}m ago`;
const hours = Math.floor(minutes / 60);

View File

@@ -12,7 +12,10 @@ import type {
* Derive health from status and recency.
* TODO: Replace with real computation once backend provides the data.
*/
function deriveHealth(status: AgentStatus, lastRunAt: string | null): AgentHealth {
function deriveHealth(
status: AgentStatus,
lastRunAt: string | null,
): AgentHealth {
if (status === "error") return "attention";
if (status === "idle" && lastRunAt) {
const daysSince =
@@ -37,7 +40,7 @@ function mockStatusForAgent(agentID: string): AgentStatusInfo {
"idle",
];
const status = statuses[hash % statuses.length];
const progress = status === "running" ? ((hash * 17) % 100) : null;
const progress = status === "running" ? (hash * 17) % 100 : null;
const totalRuns = (hash % 200) + 1;
const daysAgo = (hash % 30) + 1;
const lastRunAt = new Date(

View File

@@ -1,6 +1,9 @@
"use client";
import { createContext, useContext, useState } from "react";
import { createContext, useContext, useCallback, useState } from "react";
import { useRouter } from "next/navigation";
const STORAGE_KEY = "autopilot_pending_prompt";
interface AutoPilotBridgeState {
/** Pending prompt to be injected into AutoPilot chat. */
@@ -18,21 +21,33 @@ interface Props {
}
export function AutoPilotBridgeProvider({ children }: Props) {
const [pendingPrompt, setPendingPrompt] = useState<string | null>(null);
const router = useRouter();
function sendPrompt(prompt: string) {
setPendingPrompt(prompt);
// Navigate to the Home / Copilot tab.
// Using window.location is the simplest approach that works across the
// Next.js app router without coupling to a specific router instance.
window.location.href = "/";
}
// Hydrate from sessionStorage in case we just navigated here
const [pendingPrompt, setPendingPrompt] = useState<string | null>(() => {
if (typeof window === "undefined") return null;
return sessionStorage.getItem(STORAGE_KEY);
});
function consumePrompt(): string | null {
const prompt = pendingPrompt;
setPendingPrompt(null);
const sendPrompt = useCallback(
(prompt: string) => {
// Persist to sessionStorage so it survives client-side navigation
sessionStorage.setItem(STORAGE_KEY, prompt);
setPendingPrompt(prompt);
// Use Next.js router for client-side navigation (preserves React tree)
router.push("/");
},
[router],
);
const consumePrompt = useCallback((): string | null => {
const prompt = pendingPrompt ?? sessionStorage.getItem(STORAGE_KEY);
if (prompt) {
sessionStorage.removeItem(STORAGE_KEY);
setPendingPrompt(null);
}
return prompt;
}
}, [pendingPrompt]);
return (
<AutoPilotBridgeContext.Provider