Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Put dashboard keyword and backlink tabs inside the table card (#904)
Carter Smith0e32c24b16a2
diff --git a/src/client/components/ui/button.tsx b/src/client/components/ui/button.tsxindex 9e5bd872..2501bca6 100644--- a/src/client/components/ui/button.tsx+++ b/src/client/components/ui/button.tsx@@ -10,7 +10,7 @@ const buttonVariants = cva(variant: {default: "bg-primary text-primary-foreground hover:bg-primary/80",outline:- "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",+ "border-border bg-card shadow-xs hover:bg-foreground/5 hover:text-foreground aria-expanded:bg-foreground/5 aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:shadow-none dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",ghost:diff --git a/src/client/components/ui/tabs.tsx b/src/client/components/ui/tabs.tsxindex 00f7b424..adb581af 100644--- a/src/client/components/ui/tabs.tsx+++ b/src/client/components/ui/tabs.tsx@@ -27,7 +27,7 @@ const tabsListVariants = cva({variants: {variant: {- default: "bg-muted",+ default: "bg-foreground/6 dark:bg-muted",line: "gap-1 bg-transparent",},},@@ -59,7 +59,7 @@ function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {className={cn("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent",- "data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground",+ "data-active:bg-card data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",className,)}diff --git a/src/client/features/dashboard/DashboardBacklinks.tsx b/src/client/features/dashboard/DashboardBacklinks.tsxindex 82a01d6b..5cac753f 100644--- a/src/client/features/dashboard/DashboardBacklinks.tsx+++ b/src/client/features/dashboard/DashboardBacklinks.tsx@@ -1,13 +1,22 @@import { useQuery } from "@tanstack/react-query";-import { CardShell } from "@/client/components/CardShell";-import { QueryState } from "@/client/components/QueryState";+import { QueryError } from "@/client/components/QueryState";+import { DataTableTabs } from "@/client/components/table/DataTableToolbar";import type { ColumnDef } from "@tanstack/react-table";import { SortableHeader } from "@/client/components/table/SortableHeader";import { DashboardDataTable } from "./DashboardDataTable";-import { useState } from "react";-import { Tabs, TabsList, TabsTrigger } from "@/client/components/ui/tabs";+import { useState, type ComponentProps } from "react";+import { TabsTrigger } from "@/client/components/ui/tabs";import { getDashboardBacklinks } from "@/serverFunctions/dashboard";-import { Freshness, ExternalPage, DashboardInfo } from "./siteTabParts";+import { Freshness, ExternalPage } from "./siteTabParts";+const KINDS = ["new", "lost", "all"] as const;+type Kind = (typeof KINDS)[number];++const DESCRIPTIONS: Record<Kind, string> = {+ new: "Links to your website found in the past week. A link may be older than the date it was found.",+ lost: "Links that were found before but are no longer there. Last checked is when we last checked the link, not when it disappeared.",+ all: "Recently found links that still point to your website.",+};+export function DashboardBacklinks({projectId,domain,@@ -15,7 +24,7 @@ export function DashboardBacklinks({projectId: string;domain: string;}) {- const [kind, setKind] = useState<"new" | "lost" | "all">("new");+ const [kind, setKind] = useState<Kind>("new");const query = useQuery({queryKey: ["dashboardBacklinks", projectId, domain, kind],queryFn: () => getDashboardBacklinks({ data: { projectId, kind } }),@@ -23,72 +32,40 @@ export function DashboardBacklinks({retry: false,});return (- <div className="space-y-5">- <div className="flex flex-wrap items-center justify-between gap-3">- <div>- <h2 className="text-lg font-semibold">Your backlinks</h2>- </div>- <Tabs+ <DashboardBacklinkTable+ rows={query.data?.value ?? []}+ kind={kind}+ isLoading={query.isPending}+ error={+ query.isError ? (+ <QueryError+ error={query.error}+ fallback="Could not load backlinks"+ onRetry={() => void query.refetch()}+ isRetrying={query.isFetching}+ />+ ) : null+ }+ tabs={+ <DataTableTabsvalue={kind}onValueChange={(value) => {- if (value === "new" || value === "lost" || value === "all")- setKind(- value === "new" ? "new" : value === "lost" ? "lost" : "all",- );+ const next = KINDS.find((item) => item === value);+ if (next) setKind(next);}}+ description={+ <>+ {DESCRIPTIONS[kind]}+ {query.data ? <Freshness {...query.data} /> : null}+ </>+ }>- <TabsList>- <TabsTrigger value="new">New this week</TabsTrigger>- <TabsTrigger value="lost">Lost links</TabsTrigger>- <TabsTrigger value="all">Active links</TabsTrigger>- </TabsList>- </Tabs>- </div>- <QueryState query={query} errorFallback="Could not load backlinks">- {(data) => (- <CardShell- title={- kind === "new"- ? "Recently discovered backlinks"- : kind === "lost"- ? "Lost backlinks"- : "Active backlinks"- }- titleInfo={- <DashboardInfo label="About backlink data">- <p>- {kind === "new"- ? "Links to your website found in the past week. A link may be older than the date it was found."- : kind === "lost"- ? "Links that were found before but are no longer there. Last checked is when we last checked the link, not when it disappeared."- : "Recently found links that still point to your website."}- </p>- <p className="mt-2">- Filters narrow the links shown in this table.- </p>- </DashboardInfo>- }- >- <Freshness {...data} />- {data.value.length ? (- <DashboardBacklinkTable- key={kind}- rows={data.value}- kind={kind}- />- ) : (- <p className="py-8 text-sm text-muted-foreground">- {kind === "new"- ? "No new backlinks this week."- : kind === "lost"- ? "No lost backlinks found."- : "No active backlinks found yet."}- </p>- )}- </CardShell>- )}- </QueryState>- </div>+ <TabsTrigger value="new">New this week</TabsTrigger>+ <TabsTrigger value="lost">Lost links</TabsTrigger>+ <TabsTrigger value="all">Active links</TabsTrigger>+ </DataTableTabs>+ }+ />);}@@ -98,10 +75,14 @@ type Backlink = Awaited<function DashboardBacklinkTable({rows,kind,+ ...tableProps}: {rows: Backlink[];- kind: "new" | "lost" | "all";-}) {+ kind: Kind;+} & Pick<+ ComponentProps<typeof DashboardDataTable>,+ "tabs" | "isLoading" | "error"+>) {const columns: ColumnDef<Backlink>[] = [{id: "urlFrom",@@ -172,7 +153,17 @@ function DashboardBacklinkTable({];return (<DashboardDataTable+ {...tableProps}+ resetKey={kind}rows={rows}+ empty={{+ title:+ kind === "new"+ ? "No new backlinks this week"+ : kind === "lost"+ ? "No lost backlinks found"+ : "No active backlinks found yet",+ }}columns={columns}filters={[{ id: "urlFrom", label: "Referring page", kind: "text" },diff --git a/src/client/features/dashboard/DashboardDataTable.tsx b/src/client/features/dashboard/DashboardDataTable.tsxindex 495aa3fa..a696f33b 100644--- a/src/client/features/dashboard/DashboardDataTable.tsx+++ b/src/client/features/dashboard/DashboardDataTable.tsx@@ -3,7 +3,12 @@ import {type SortingState,type ColumnDef,} from "@tanstack/react-table";-import { useState } from "react";+import {+ useEffect,+ useState,+ type ComponentProps,+ type ReactNode,+} from "react";import { DataTable, useDataTable } from "@/client/components/table/DataTable";import {DataTableToolbar,@@ -28,11 +33,23 @@ export function DashboardDataTable<T>({columns,filters,initialSorting,+ tabs,+ resetKey,+ isLoading,+ error,+ empty = { title: "No results yet" },}: {rows: T[];columns: ColumnDef<T>[];filters: Filter[];initialSorting?: SortingState;+ /** A `DataTableTabs` row that switches what the table shows. */+ tabs?: ReactNode;+ /** Changing it restores the initial sorting, filters and page, e.g. on a tab switch. */+ resetKey?: string;+ isLoading?: boolean;+ error?: ReactNode;+ empty?: ComponentProps<typeof DataTable>["empty"];}) {const [open, setOpen] = useState(false);const table = useDataTable({@@ -46,6 +63,14 @@ export function DashboardDataTable<T>({sorting: initialSorting,},});+ // Reset in place rather than remounting with `key`, which would drop+ // keyboard focus from the tabs rendered inside the table card.+ useEffect(() => {+ table.setSorting(initialSorting ?? []);+ table.resetColumnFilters();+ table.setPageIndex(0);+ // eslint-disable-next-line react-hooks/exhaustive-deps -- reset only when the key changes+ }, [resetKey]);const count = table.getState().columnFilters.length;const clear = () => table.resetColumnFilters();return (@@ -53,9 +78,12 @@ export function DashboardDataTable<T>({table={table}isFiltered={count > 0}onClearFilters={clear}- empty={{ title: "No results yet" }}+ isLoading={isLoading}+ error={error}+ empty={empty}toolbar={<>+ {tabs}<DataTableToolbar><DataTableFilterToggleopen={open}diff --git a/src/client/features/dashboard/DashboardKeywordTable.tsx b/src/client/features/dashboard/DashboardKeywordTable.tsxindex 78e88471..4f934bf3 100644--- a/src/client/features/dashboard/DashboardKeywordTable.tsx+++ b/src/client/features/dashboard/DashboardKeywordTable.tsx@@ -1,6 +1,7 @@import { ExternalPage } from "./siteTabParts";import type { ColumnDef } from "@tanstack/react-table";import { SortableHeader } from "@/client/components/table/SortableHeader";+import type { ComponentProps } from "react";import { DashboardDataTable } from "./DashboardDataTable";type Keyword = {@@ -49,11 +50,15 @@ export function DashboardKeywordTable({rows,showPages = false,sortBy = "impressions",+ ...tableProps}: {rows: Keyword[];showPages?: boolean;sortBy?: "impressions" | "clicks";-}) {+} & Pick<+ ComponentProps<typeof DashboardDataTable>,+ "tabs" | "resetKey" | "isLoading" | "error" | "empty"+>) {const pageColumn: ColumnDef<Keyword> = {accessorKey: "page",header: "Page",@@ -62,6 +67,7 @@ export function DashboardKeywordTable({};return (<DashboardDataTable+ {...tableProps}rows={rows}columns={showPages ? [columns[0], pageColumn, ...columns.slice(1)] : columnsdiff --git a/src/client/features/dashboard/DashboardKeywords.tsx b/src/client/features/dashboard/DashboardKeywords.tsxindex 0343996a..005568a2 100644--- a/src/client/features/dashboard/DashboardKeywords.tsx+++ b/src/client/features/dashboard/DashboardKeywords.tsx@@ -3,14 +3,26 @@ import { Button } from "@/client/components/ui/button";import { getSearchPerformanceReport } from "@/serverFunctions/searchPerformance";import { useState } from "react";import { useQuery } from "@tanstack/react-query";-import { Tabs, TabsList, TabsTrigger } from "@/client/components/ui/tabs";-import { CardShell } from "@/client/components/CardShell";-import { QueryState } from "@/client/components/QueryState";+import { TabsTrigger } from "@/client/components/ui/tabs";+import { DataTableTabs } from "@/client/components/table/DataTableToolbar";+import { QueryError } from "@/client/components/QueryState";import { GoogleConnectionCard } from "@/client/features/integrations/GoogleConnectionCard";-import { getDashboardKeywords } from "@/serverFunctions/dashboard";-import { DashboardNewQueries } from "./DashboardNewQueries";+import {+ getDashboardEmergingQueries,+ getDashboardKeywords,+} from "@/serverFunctions/dashboard";import { DashboardKeywordTable } from "./DashboardKeywordTable";-import { DashboardInfo, Freshness } from "./siteTabParts";+import { Freshness } from "./siteTabParts";++const SOURCES = ["new", "top", "striking"] as const;+type Source = (typeof SOURCES)[number];++const DESCRIPTIONS: Record<Source, string> = {+ new: "Searches where your website appeared in the latest week of Search Console data, but not in the previous four weeks.",+ top: "Searches bringing the most clicks to your website over the last 28 days.",+ striking:+ "Keywords at positions 5–20 over the last 28 days. Improving the listed page could help them move higher.",+};export function DashboardKeywords({projectId,@@ -21,7 +33,14 @@ export function DashboardKeywords({connected: boolean;siteUrl: string | null;}) {- const [source, setSource] = useState("new");+ const [source, setSource] = useState<Source>("new");+ const emerging = useQuery({+ queryKey: ["dashboardEmergingQueries", projectId, siteUrl],+ queryFn: () => getDashboardEmergingQueries({ data: { projectId } }),+ enabled: connected && source === "new",+ staleTime: 10 * 60_000,+ retry: false,+ });const keywords = useQuery({queryKey: ["dashboardGscKeywords", projectId, siteUrl],queryFn: () => getDashboardKeywords({ data: { projectId } }),@@ -42,126 +61,86 @@ export function DashboardKeywords({return (<GoogleConnectionCard provider="gsc" projectId={projectId} prominent />);++ const query =+ source === "new" ? emerging : source === "top" ? keywords : striking;+ const cached =+ source === "new" ? emerging.data : source === "top" ? keywords.data : null;+ const result =+ source === "striking"+ ? striking.data && {+ connected: striking.data.connected,+ rows: striking.data.connected ? striking.data.strikingDistance : [],+ }+ : cached?.value;+ if (result && !result.connected)+ return (+ <GoogleConnectionCard provider="gsc" projectId={projectId} prominent />+ );+return (- <div className="space-y-5">- <div className="flex flex-wrap items-center justify-between gap-3">- <h2 className="text-lg font-semibold">Your keywords</h2>- <Button- variant="outline"- nativeButton={false}- render={- <Link- to="/p/$projectId/search-performance"- params={{ projectId }}- />- }- >- View full GSC insights →- </Button>- </div>- <div className="overflow-x-auto">- <div className="flex w-max items-center gap-2">- <Tabs- value={source}- onValueChange={(value) => setSource(String(value))}- >- <TabsList>- <TabsTrigger value="new">New keywords</TabsTrigger>- <TabsTrigger value="top">Top keywords</TabsTrigger>- <TabsTrigger value="striking">Striking distance</TabsTrigger>- </TabsList>- </Tabs>- <DashboardInfo label="About keyword views">- <p>- <strong>New keywords</strong> are searches we started seeing- recently.- </p>- <p className="mt-2">- <strong>Top keywords</strong> shows the searches bringing the most- clicks to your website.- </p>- <p className="mt-2">- <strong>Striking distance</strong> shows keywords where your site- appears at positions 5–20, with room to move higher.- </p>- </DashboardInfo>- </div>- </div>- {source === "new" ? (- <DashboardNewQueries- projectId={projectId}- connected={connected}- siteUrl={siteUrl}- />- ) : source === "striking" ? (- <QueryState query={striking} errorFallback="Could not load keywords">- {(report) =>- !report.connected ? (- <GoogleConnectionCard- provider="gsc"- projectId={projectId}- prominent- />- ) : (- <CardShell- title="Striking distance"- titleInfo={- <DashboardInfo label="About striking distance">- Keywords where your website appears at positions 5–20 on- Google. Improving the listed page could help it move higher.- </DashboardInfo>- }- >- <p className="mb-4 text-sm text-muted-foreground">- Last 28 days- </p>- {report.strikingDistance.length ? (- <DashboardKeywordTable- rows={report.strikingDistance}- showPages- />- ) : (- <p className="py-8 text-sm text-muted-foreground">- No keywords at positions 5–20 in this period.- </p>- )}- </CardShell>- )- }- </QueryState>- ) : (- <QueryState query={keywords} errorFallback="Could not load keywords">- {(data) =>- !data.value.connected ? (- <GoogleConnectionCard- provider="gsc"- projectId={projectId}- prominent- />- ) : (- <CardShell- title="Top keywords"- titleInfo={- <DashboardInfo label="About top keywords">- Searches bringing the most clicks to your website over the- last 28 days, from Google Search Console.- </DashboardInfo>- }- >- <p className="mb-4 text-sm text-muted-foreground">- Last 28 days- </p>- <Freshness {...data} />- <DashboardKeywordTable- key="top"- rows={data.value.rows}- sortBy="clicks"+ <DashboardKeywordTable+ resetKey={source}+ rows={result?.rows ?? []}+ showPages={source === "striking"}+ sortBy={source === "top" ? "clicks" : "impressions"}+ isLoading={query.isPending}+ error={+ query.isError ? (+ <QueryError+ error={query.error}+ fallback="Could not load keywords"+ onRetry={() => void query.refetch()}+ isRetrying={query.isFetching}+ />+ ) : null+ }+ empty={+ source === "new"+ ? {+ title:+ emerging.data?.value.hasSearchData === false+ ? "No search data yet"+ : "No new keywords this week",+ }+ : source === "striking"+ ? { title: "No keywords at positions 5–20 in this period" }+ : { title: "No keywords yet" }+ }+ tabs={+ <DataTableTabs+ value={source}+ onValueChange={(value) => {+ const next = SOURCES.find((item) => item === value);+ if (next) setSource(next);+ }}+ actions={+ <Button+ variant="outline"+ size="sm"+ nativeButton={false}+ render={+ <Link+ to="/p/$projectId/search-performance"+ params={{ projectId }}/>- </CardShell>- )+ }+ >+ View full GSC insights →+ </Button>+ }+ description={+ <>+ {DESCRIPTIONS[source]}+ {cached ? <Freshness {...cached} /> : null}+ </>}- </QueryState>- )}- </div>+ >+ <TabsTrigger value="new">New keywords</TabsTrigger>+ <TabsTrigger value="top">Top keywords</TabsTrigger>+ <TabsTrigger value="striking">Striking distance</TabsTrigger>+ </DataTableTabs>+ }+ />);}diff --git a/src/client/features/dashboard/DashboardNewQueries.tsx b/src/client/features/dashboard/DashboardNewQueries.tsxindex ffb22b57..e5f39001 100644--- a/src/client/features/dashboard/DashboardNewQueries.tsx+++ b/src/client/features/dashboard/DashboardNewQueries.tsx@@ -1,4 +1,3 @@-import { DashboardKeywordTable } from "./DashboardKeywordTable";import { Link } from "@tanstack/react-router";import { useQuery } from "@tanstack/react-query";import { Search } from "lucide-react";@@ -21,12 +20,10 @@ export function DashboardNewQueries({projectId,connected,siteUrl,- compact = false,}: {projectId: string;connected: boolean;siteUrl: string | null;- compact?: boolean;}) {const query = useQuery({queryKey: ["dashboardEmergingQueries", projectId, siteUrl],@@ -35,10 +32,7 @@ export function DashboardNewQueries({staleTime: 10 * 60_000,retry: false,});- if (!connected)- return compact ? null : (- <GoogleConnectionCard provider="gsc" projectId={projectId} prominent />- );+ if (!connected) return null;return (<QueryState query={query} errorFallback="Could not load new keywords">{(data) =>@@ -61,46 +55,36 @@ export function DashboardNewQueries({</DashboardInfo>}action={- compact ? (- <Link- to="/p/$projectId"- params={{ projectId }}- search={{ tab: "keywords" }}- className={moreDetailsClass}- >- View all →- </Link>- ) : undefined+ <Link+ to="/p/$projectId"+ params={{ projectId }}+ search={{ tab: "keywords" }}+ className={moreDetailsClass}+ >+ View all →+ </Link>}><Freshness {...data} />{data.value.rows.length ? (- !compact ? (- <DashboardKeywordTable rows={data.value.rows} />- ) : (- <Table>- <TableHeader>- <TableRow>- <TableHead>Keyword</TableHead>- <TableHead>Impressions</TableHead>- <TableHead>Clicks</TableHead>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead>Keyword</TableHead>+ <TableHead>Impressions</TableHead>+ <TableHead>Clicks</TableHead>+ </TableRow>+ </TableHeader>+ <TableBody>+ {data.value.rows.slice(0, 5).map((row) => (+ <TableRow key={row.query}>+ <TableCell className="font-medium">{row.query}</TableCell>+ <TableCell>{row.impressions.toLocaleString()}</TableCell>+ <TableCell>{row.clicks}</TableCell></TableRow>- </TableHeader>- <TableBody>- {data.value.rows.slice(0, compact ? 5 : 25).map((row) => (- <TableRow key={row.query}>- <TableCell className="font-medium">- {row.query}- </TableCell>- <TableCell>- {row.impressions.toLocaleString()}- </TableCell>- <TableCell>{row.clicks}</TableCell>- </TableRow>- ))}- </TableBody>- </Table>- )+ ))}+ </TableBody>+ </Table>) : (<div className="flex flex-1 flex-col items-center justify-center gap-3 py-8 text-center"><Search className="size-7 text-muted-foreground" />diff --git a/src/client/features/dashboard/DashboardPage.tsx b/src/client/features/dashboard/DashboardPage.tsxindex 55858ae8..a34c230d 100644--- a/src/client/features/dashboard/DashboardPage.tsx+++ b/src/client/features/dashboard/DashboardPage.tsx@@ -101,7 +101,6 @@ export function DashboardPage({projectId={projectId}connected={gscConnected}siteUrl={activation.gsc.siteUrl}- compact/>),},diff --git a/src/client/features/search-performance/SearchPerformanceParts.tsx b/src/client/features/search-performance/SearchPerformanceParts.tsxindex 722593e9..5a802019 100644--- a/src/client/features/search-performance/SearchPerformanceParts.tsx+++ b/src/client/features/search-performance/SearchPerformanceParts.tsx@@ -155,13 +155,13 @@ export function TotalsTable({ report }: { report: Report }) {},];return (- <div className="w-full max-w-xl rounded-xl border border-border bg-card p-4">+ <div className="rounded-xl border border-border bg-card p-4"><Table><TableHeader><TableRow>- <TableHead>Metric</TableHead>- <TableHead className="text-right">Value</TableHead>- <TableHead className="text-right" title={deltaTitle}>+ <TableHead className="w-full">Metric</TableHead>+ <TableHead className="min-w-32 text-right">Value</TableHead>+ <TableHead className="min-w-32 text-right" title={deltaTitle}>Change</TableHead></TableRow>