Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
"use client";
import { useCallback, useState } from "react";
import { useRouter } from "next/navigation";
import { toast } from "sonner";
import {
FreshnessTable,
type FreshnessTableProps,
} from "@repowise-dev/ui/coverage/freshness-table";
import { toFriendlyMessage } from "@repowise-dev/ui/lib/errors";
import { GenerationProgressWrapper } from "@/components/jobs/generation-progress-wrapper";
import { regeneratePage } from "@/lib/api/pages";
import { useTranslations } from "next-intl";
export function FreshnessTableWithRegenerate({
pages,
repoId,
}: Pick<FreshnessTableProps, "pages"> & { repoId: string }) {
const t = useTranslations("coverage");
const router = useRouter();
// A single active job (a per-row regenerate) shown above the table. On
// completion we revalidate the (server-rendered) page list.
const [activeJobId, setActiveJobId] = useState<string | null>(null);
const busy = activeJobId != null;
// Per-row regenerate launches a tracked job with a toast and error handling.
const handleRegenerate = useCallback(
async (pageId: string) => {
if (busy) {
toast.info(t("jobRunning"));
return;
}
try {
const res = await regeneratePage(pageId, { cascade: "none", repoId });
setActiveJobId(res.job_id);
toast.info(t("regenStarted"));
} catch (e) {
toast.error(t("regenFailed"), {
description: toFriendlyMessage(e),
});
}
},
[busy, t],
);
return (
<div className="space-y-3">
{activeJobId && (
<GenerationProgressWrapper
jobId={activeJobId}
onDone={() => {
setActiveJobId(null);
router.refresh();
}}
/>
)}
<FreshnessTable pages={pages} onRegenerate={handleRegenerate} />
</div>
);
}