Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Show top competitors in the prompt brand table and drop the stats card (EVE-396) (#861)
Carter Smith5c36392f32c5
diff --git a/src/client/features/ai-visibility/PromptAnalysis.tsx b/src/client/features/ai-visibility/PromptAnalysis.tsxindex e8439b54..1dae5a4f 100644--- a/src/client/features/ai-visibility/PromptAnalysis.tsx+++ b/src/client/features/ai-visibility/PromptAnalysis.tsx@@ -2,10 +2,7 @@ import { useState } from "react";import { sort } from "remeda";import { Button } from "@/client/components/ui/button";import type { AiPrompt } from "@/shared/ai-visibility";-import {- aiAnswerCoverage,- summarizeAiBrands,-} from "@/shared/ai-visibility-results";+import { summarizeAiBrands } from "@/shared/ai-visibility-results";import type { getAiVisibilityResults } from "@/serverFunctions/ai-visibility";import { PromptAnswers } from "./PromptAnswers";import {@@ -52,15 +49,13 @@ export function PromptAnalysis({observation.answerStatus === "answered",) ??executions[0];- const rows = executions.map(({ observation }) => observation);- const results = {- summaries: summarizeAiBrands(rows),- coverage: aiAnswerCoverage(rows),- };+ const summaries = summarizeAiBrands(+ executions.map(({ observation }) => observation),+ );return (<div className="space-y-4"><PromptDateRange value={period} onChange={setPeriod} />- <PromptSummary results={results} />+ <PromptSummary summaries={summaries} />{selected ? (<><PromptExecutionsdiff --git a/src/client/features/ai-visibility/PromptSummary.tsx b/src/client/features/ai-visibility/PromptSummary.tsxindex 0977f837..cc0e0903 100644--- a/src/client/features/ai-visibility/PromptSummary.tsx+++ b/src/client/features/ai-visibility/PromptSummary.tsx@@ -1,5 +1,7 @@-import { StatTile } from "@/client/components/StatTile";+import { useState } from "react";+import { sort } from "remeda";import { Badge } from "@/client/components/ui/badge";+import { Button } from "@/client/components/ui/button";import {Table,TableBody,@@ -8,91 +10,97 @@ import {TableHeader,TableRow,} from "@/client/components/ui/table";-import type { AiResults } from "@/shared/ai-visibility";+import type { AiBrandSummary } from "@/shared/ai-visibility";import { DomainFavicon } from "./DomainFavicon";import { aiRate } from "./shared";-export function PromptSummary({- results,-}: {- results: Pick<AiResults, "summaries" | "coverage">;-}) {- const own = results.summaries.find((brand) => brand.own);+// Your brand plus the top three competitors.+const VISIBLE_BRANDS = 4;++export function PromptSummary({ summaries }: { summaries: AiBrandSummary[] }) {+ const [expanded, setExpanded] = useState(false);+ // Most-mentioned competitors first, so the collapsed table shows the ones that matter.+ const ranked = sort(+ summaries,+ (a, b) =>+ Number(b.own) - Number(a.own) ||+ b.mentions - a.mentions ||+ b.citations - a.citations,+ );+ const visible = expanded ? ranked : ranked.slice(0, VISIBLE_BRANDS);+ const hiddenCount = ranked.length - visible.length;return (- <div className="grid gap-4 xl:grid-cols-2">- <div className="grid grid-cols-3 items-center gap-4 rounded-lg border bg-card p-5 border-border">- <StatTile- label="Brand mentions"- value={aiRate(own?.mentions ?? 0, own?.answers ?? 0)}- hint={`${own?.mentions ?? 0} of ${own?.answers ?? 0} answers`}- />- <StatTile- label="Owned citations"- value={aiRate(own?.citations ?? 0, own?.answers ?? 0)}- hint={`${own?.citations ?? 0} of ${own?.answers ?? 0} answers`}- />- <StatTile label="Answers" value={String(results.coverage.completed)} />- </div>- <div className="overflow-hidden rounded-lg border bg-card border-border">- <h2 className="border-b px-4 py-2 text-sm font-medium border-border">- Brand comparison- </h2>- <Table>- <TableHeader>+ <div className="overflow-hidden rounded-lg border bg-card border-border">+ <h2 className="border-b px-4 py-2 text-sm font-medium border-border">+ Brand comparison+ </h2>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead>Brand</TableHead>+ <TableHead>Mentioned</TableHead>+ <TableHead>Cited</TableHead>+ </TableRow>+ </TableHeader>+ <TableBody>+ {visible.map((brand) => (+ <TableRow key={brand.domain}>+ <TableCell>+ <span className="flex items-center gap-2">+ <DomainFavicon domain={brand.domain} />+ {brand.name}+ {brand.own && (+ <Badge variant="secondary" size="sm">+ You+ </Badge>+ )}+ </span>+ </TableCell>+ <TableCell+ className="tabular-nums"+ title={`${brand.mentions} of ${brand.answers} answers`}+ >+ {aiRate(brand.mentions, brand.answers)}+ {brand.answers > 0 && (+ <p className="text-xs text-muted-foreground">+ {brand.mentions} of {brand.answers}+ </p>+ )}+ </TableCell>+ <TableCell+ className="tabular-nums"+ title={`${brand.citations} of ${brand.answers} answers`}+ >+ {aiRate(brand.citations, brand.answers)}+ {brand.answers > 0 && (+ <p className="text-xs text-muted-foreground">+ {brand.citations} of {brand.answers}+ </p>+ )}+ </TableCell>+ </TableRow>+ ))}+ {!summaries.length && (<TableRow>- <TableHead>Brand</TableHead>- <TableHead>Mentioned</TableHead>- <TableHead>Cited</TableHead>+ <TableCell colSpan={3} className="py-4 text-muted-foreground">+ No brand evidence is available for this period yet.+ </TableCell></TableRow>- </TableHeader>- <TableBody>- {results.summaries.map((brand) => (- <TableRow key={brand.domain}>- <TableCell>- <span className="flex items-center gap-2">- <DomainFavicon domain={brand.domain} />- {brand.name}- {brand.own && (- <Badge variant="secondary" size="sm">- You- </Badge>- )}- </span>- </TableCell>- <TableCell- className="tabular-nums"- title={`${brand.mentions} of ${brand.answers} answers`}- >- {aiRate(brand.mentions, brand.answers)}- {brand.answers > 0 && (- <p className="text-xs text-muted-foreground">- {brand.mentions} of {brand.answers}- </p>- )}- </TableCell>- <TableCell- className="tabular-nums"- title={`${brand.citations} of ${brand.answers} answers`}- >- {aiRate(brand.citations, brand.answers)}- {brand.answers > 0 && (- <p className="text-xs text-muted-foreground">- {brand.citations} of {brand.answers}- </p>- )}- </TableCell>- </TableRow>- ))}- {!results.summaries.length && (- <TableRow>- <TableCell colSpan={3} className="py-4 text-muted-foreground">- No brand evidence is available for this period yet.- </TableCell>- </TableRow>- )}- </TableBody>- </Table>- </div>+ )}+ </TableBody>+ </Table>+ {hiddenCount > 0 && (+ <div className="border-t px-4 py-2 border-border">+ <Button+ variant="link"+ size="xs"+ className="h-auto px-0 text-muted-foreground hover:text-foreground"+ onClick={() => setExpanded(true)}+ >+ Show {hiddenCount} more+ </Button>+ </div>+ )}</div>);}