Skip to content

Open source alternative to Semrush and Ahrefs

Search Performance uses shadcn tables and controls (EVE-310) (#750)

Carter Smith699234d5f31e
diff --git a/src/client/components/ExportMenu.tsx b/src/client/components/ExportMenu.tsx
index f06aa826..15c21275 100644
--- a/src/client/components/ExportMenu.tsx
+++ b/src/client/components/ExportMenu.tsx
@@ -1,6 +1,5 @@
import { Fragment, type ReactNode } from "react";
import {
- ChevronDown,
Copy,
Download,
FileDown,
@@ -80,7 +79,6 @@ export function ExportMenu<A extends ExportAction>({
>
{busy ? null : <Download data-icon="inline-start" />}
Export
- <ChevronDown data-icon="inline-end" className="opacity-60" />
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
{scopes
diff --git a/src/client/components/table/TableBulkActionBar.tsx b/src/client/components/table/TableBulkActionBar.tsx
index a23507e7..b16dac97 100644
--- a/src/client/components/table/TableBulkActionBar.tsx
+++ b/src/client/components/table/TableBulkActionBar.tsx
@@ -97,7 +97,6 @@ export function TableBulkExportMenu({
>
{busy ? null : <Download data-icon="inline-start" />}
Export
- <ChevronDown data-icon="inline-end" className="opacity-60" />
</DropdownMenuTrigger>
<DropdownMenuContent side="top" align="end" className="w-52">
{actions.map((action, index) => (
diff --git a/src/client/components/ui/select.tsx b/src/client/components/ui/select.tsx
index 48f5fa2d..4910400e 100644
--- a/src/client/components/ui/select.tsx
+++ b/src/client/components/ui/select.tsx
@@ -89,7 +89,9 @@ function SelectContent({
{...props}
>
<SelectScrollUpButton />
- <SelectPrimitive.List>{children}</SelectPrimitive.List>
+ <SelectPrimitive.List className="p-1">
+ {children}
+ </SelectPrimitive.List>
<SelectScrollDownButton />
</SelectPrimitive.Popup>
</SelectPrimitive.Positioner>
diff --git a/src/client/features/search-performance/SearchPerformanceColumns.tsx b/src/client/features/search-performance/SearchPerformanceColumns.tsx
index caddcbc8..ff0940dc 100644
--- a/src/client/features/search-performance/SearchPerformanceColumns.tsx
+++ b/src/client/features/search-performance/SearchPerformanceColumns.tsx
@@ -111,7 +111,7 @@ export function buildStrikingColumns(
href={safeHttpUrl(getValue()) ?? undefined}
target="_blank"
rel="noreferrer"
- className="link link-hover block max-w-sm truncate"
+ className="block max-w-sm truncate text-primary underline-offset-4 hover:underline"
title={getValue()}
>
{getValue()}
diff --git a/src/client/features/search-performance/SearchPerformanceDimensionSection.tsx b/src/client/features/search-performance/SearchPerformanceDimensionSection.tsx
index 46f1f12b..ab434a9b 100644
--- a/src/client/features/search-performance/SearchPerformanceDimensionSection.tsx
+++ b/src/client/features/search-performance/SearchPerformanceDimensionSection.tsx
@@ -1,7 +1,7 @@
import type { UseQueryResult } from "@tanstack/react-query";
-import { Loader2 } from "lucide-react";
import { QueryError } from "@/client/components/QueryState";
import { TablePagination } from "@/client/components/table/TablePagination";
+import { Spinner } from "@/client/components/ui/spinner";
import { GoogleConnectionCard } from "@/client/features/integrations/GoogleConnectionCard";
import { DimensionTable } from "@/client/features/search-performance/SearchPerformanceParts";
import type { getSearchPerformanceTable } from "@/serverFunctions/searchPerformance";
@@ -16,6 +16,8 @@ export function DimensionSection({
pageSize,
onPageChange,
onPageSizeChange,
+ isFiltered,
+ onClearFilters,
}: {
projectId: string;
tableQuery: UseQueryResult<
@@ -26,11 +28,13 @@ export function DimensionSection({
pageSize: number;
onPageChange: (page: number) => void;
onPageSizeChange: (pageSize: number) => void;
+ isFiltered: boolean;
+ onClearFilters: () => void;
}) {
if (tableQuery.isPending) {
return (
- <div className="flex items-center gap-2 p-8 text-sm text-base-content/60">
- <Loader2 className="size-4 animate-spin" /> Loading…
+ <div className="flex items-center gap-2 p-8 text-sm text-muted-foreground">
+ <Spinner /> Loading…
</div>
);
}
@@ -58,22 +62,34 @@ export function DimensionSection({
);
}
+ const isPastEnd =
+ page > 1 && tableData.rows.length === 0 && !tableQuery.isPlaceholderData;
+
return (
<>
{error}
<div className="p-4">
- <DimensionTable rows={tableData.rows} keyLabel={keyLabel} />
+ <DimensionTable
+ rows={tableData.rows}
+ keyLabel={keyLabel}
+ isFiltered={isFiltered}
+ isPastEnd={isPastEnd}
+ onClearFilters={onClearFilters}
+ onFirstPage={() => onPageChange(1)}
+ />
</div>
- <TablePagination
- page={page}
- pageSize={pageSize}
- pageSizes={SEARCH_PERFORMANCE_PAGE_SIZES}
- totalCount={tableData.totalCount}
- hasNextPage={tableData.hasNextPage}
- isLoading={tableQuery.isFetching}
- onPageChange={onPageChange}
- onPageSizeChange={onPageSizeChange}
- />
+ {!isPastEnd && (
+ <TablePagination
+ page={page}
+ pageSize={pageSize}
+ pageSizes={SEARCH_PERFORMANCE_PAGE_SIZES}
+ totalCount={tableData.totalCount}
+ hasNextPage={tableData.hasNextPage}
+ isLoading={tableQuery.isFetching}
+ onPageChange={onPageChange}
+ onPageSizeChange={onPageSizeChange}
+ />
+ )}
</>
);
}
diff --git a/src/client/features/search-performance/SearchPerformanceLoadingState.tsx b/src/client/features/search-performance/SearchPerformanceLoadingState.tsx
index 32ddcbe1..469e9053 100644
--- a/src/client/features/search-performance/SearchPerformanceLoadingState.tsx
+++ b/src/client/features/search-performance/SearchPerformanceLoadingState.tsx
@@ -13,8 +13,8 @@ export function SearchPerformanceLoadingState() {
<div className="space-y-4" aria-busy>
<SkeletonStatGrid />
- <div className="overflow-hidden rounded-xl border border-base-300 bg-base-100">
- <div className="flex flex-col gap-3 border-b border-base-300 px-4 py-3 lg:flex-row lg:items-center lg:justify-between">
+ <div className="overflow-hidden rounded-xl border border-border bg-card">
+ <div className="flex flex-col gap-3 border-b border-border px-4 py-3 lg:flex-row lg:items-center lg:justify-between">
<div className="flex items-center gap-4">
<Skeleton className="h-8 w-40" />
<Skeleton className="h-8 w-20" />
diff --git a/src/client/features/search-performance/SearchPerformancePage.tsx b/src/client/features/search-performance/SearchPerformancePage.tsx
index bba788ec..b03e003b 100644
--- a/src/client/features/search-performance/SearchPerformancePage.tsx
+++ b/src/client/features/search-performance/SearchPerformancePage.tsx
@@ -5,10 +5,14 @@ import {
useQuery,
useQueryClient,
} from "@tanstack/react-query";
-import { Download, Loader2, Sheet, SlidersHorizontal } from "lucide-react";
+import { SlidersHorizontal } from "lucide-react";
import { toast } from "sonner";
import { QueryError } from "@/client/components/QueryState";
-import { TableExportMenu } from "@/client/components/table/TableBulkActionBar";
+import { ExportMenu } from "@/client/components/ExportMenu";
+import { Badge } from "@/client/components/ui/badge";
+import { Button } from "@/client/components/ui/button";
+import { Spinner } from "@/client/components/ui/spinner";
+import { Tabs, TabsList, TabsTrigger } from "@/client/components/ui/tabs";
import { GoogleConnectionCard } from "@/client/features/integrations/GoogleConnectionCard";
import { DimensionSection } from "@/client/features/search-performance/SearchPerformanceDimensionSection";
import { SearchPerformanceSelects } from "@/client/features/search-performance/SearchPerformanceSelects";
@@ -25,7 +29,6 @@ import {
exportDimensionRows,
exportStriking,
StrikingDistanceTable,
- TabButton,
TotalsCards,
type ExportTarget,
} from "@/client/features/search-performance/SearchPerformanceParts";
@@ -36,6 +39,7 @@ import {
} from "@/serverFunctions/searchPerformance";
import {
SEARCH_PERFORMANCE_DEFAULT_PAGE_SIZE,
+ SEARCH_PERFORMANCE_TABS,
type SearchPerformanceSearch,
type SearchPerformanceTab,
type SearchPerformanceTableDimension,
@@ -88,6 +92,7 @@ export function SearchPerformancePage({
[search.pageText, search.pageMatch, search.queryText, search.queryMatch],
);
const [showFilters, setShowFilters] = useState(false);
+ const [isExporting, setIsExporting] = useState(false);
const activeFilterCount =
Number(Boolean(textFilters.pageFilter)) +
Number(Boolean(textFilters.queryFilter)) +
@@ -149,21 +154,37 @@ export function SearchPerformancePage({
]);
const handleExport = async (target: ExportTarget) => {
- if (!report?.connected || reportQuery.isPlaceholderData) return;
+ if (!report?.connected || reportQuery.isPlaceholderData || isExporting)
+ return;
+ setIsExporting(true);
try {
if (tab === "striking") {
- exportStriking(report, target);
+ await exportStriking(report, target);
return;
}
const data = await exportSearchPerformanceTable({
data: { projectId, dimension, ...filterInput },
});
- exportDimensionRows(dimension, data.rows, report.range, target);
+ await exportDimensionRows(dimension, data.rows, report.range, target);
} catch (error) {
toast.error(getStandardErrorMessage(error, "Export failed"));
+ } finally {
+ setIsExporting(false);
}
};
+ const resetFilters = () =>
+ onSearchChange({
+ page: undefined,
+ pageText: undefined,
+ pageMatch: undefined,
+ queryText: undefined,
+ queryMatch: undefined,
+ country: undefined,
+ device: undefined,
+ range: undefined,
+ });
+
const reportError = (
<QueryError
error={reportQuery.error}
@@ -188,28 +209,17 @@ export function SearchPerformancePage({
queryMatch: filters.queryFilter?.operator,
});
}}
- onReset={() => {
- onSearchChange({
- page: undefined,
- pageText: undefined,
- pageMatch: undefined,
- queryText: undefined,
- queryMatch: undefined,
- country: undefined,
- device: undefined,
- range: undefined,
- });
- }}
+ onReset={resetFilters}
/>
);
return (
- <div className="px-4 py-4 pb-24 overflow-auto md:px-6 md:py-6 md:pb-8">
+ <div className="overflow-auto px-4 py-4 pb-24 md:px-6 md:py-6 md:pb-8">
<div className="mx-auto max-w-7xl space-y-4">
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
<div>
<h1 className="text-2xl font-semibold">Search Performance</h1>
- <p className="text-sm text-base-content/70">
+ <p className="text-sm text-muted-foreground">
See your site&apos;s clicks, impressions, CTR, and position from
Google Search Console.
</p>
@@ -218,7 +228,7 @@ export function SearchPerformancePage({
<Link
to="/p/$projectId/settings/integrations"
params={{ projectId }}
- className="link link-hover shrink-0 self-start text-sm font-medium text-base-content/60 transition-colors hover:text-base-content sm:mt-1"
+ className="shrink-0 self-start text-sm font-medium text-muted-foreground underline-offset-4 hover:text-foreground hover:underline sm:mt-1"
>
Change property
</Link>
@@ -244,72 +254,51 @@ export function SearchPerformancePage({
) : (
<TotalsCards report={report} />
)}
- <div className="overflow-hidden rounded-xl border border-base-300 bg-base-100">
- <div className="flex flex-col gap-3 border-b border-base-300 px-4 py-3 lg:flex-row lg:items-center lg:justify-between">
- <div role="tablist" className="tabs tabs-border w-fit">
- <TabButton
- active={tab === "striking"}
- onClick={() =>
- onSearchChange({ tab: "striking", page: undefined })
- }
- label={
- reportQuery.isPlaceholderData
- ? "Striking distance"
- : `Striking distance (${report.strikingDistance.length})`
- }
- />
- <TabButton
- active={tab === "queries"}
- onClick={() =>
- onSearchChange({ tab: "queries", page: undefined })
- }
- label="Queries"
- />
- <TabButton
- active={tab === "pages"}
- onClick={() =>
- onSearchChange({ tab: "pages", page: undefined })
- }
- label="Pages"
- />
- </div>
- <TableExportMenu
- buttonClassName="btn btn-ghost btn-sm gap-1"
- actions={[
- {
- label: "Export to Sheets",
- disabled: reportQuery.isPlaceholderData,
- icon: <Sheet className="size-4" />,
- onClick: () => void handleExport("sheets"),
- },
- {
- label: "Download CSV",
- disabled: reportQuery.isPlaceholderData,
- icon: <Download className="size-4" />,
- onClick: () => void handleExport("csv"),
- },
- ]}
+ <Tabs
+ value={tab}
+ onValueChange={(value) => {
+ const nextTab = SEARCH_PERFORMANCE_TABS.find(
+ (item) => item === value,
+ );
+ if (nextTab) onSearchChange({ tab: nextTab, page: undefined });
+ }}
+ className="overflow-hidden rounded-xl border border-border bg-card gap-0"
+ >
+ <div className="flex flex-col gap-3 border-b border-border px-4 py-3 lg:flex-row lg:items-center lg:justify-between">
+ <TabsList variant="line">
+ <TabsTrigger value="striking">
+ {reportQuery.isPlaceholderData
+ ? "Striking distance"
+ : `Striking distance (${report.strikingDistance.length})`}
+ </TabsTrigger>
+ <TabsTrigger value="queries">Queries</TabsTrigger>
+ <TabsTrigger value="pages">Pages</TabsTrigger>
+ </TabsList>
+ <ExportMenu
+ actions={["sheets", "csv"]}
+ onExport={(target) => void handleExport(target)}
+ busy={isExporting}
+ disabled={reportQuery.isPlaceholderData}
/>
</div>
- <div className="flex flex-wrap items-center gap-2 px-4 py-2 border-b border-base-300">
- <button
+ <div className="flex flex-wrap items-center gap-2 border-b border-border px-4 py-2">
+ <Button
type="button"
- className={`btn btn-ghost btn-sm gap-1.5 ${showFilters ? "btn-active" : ""}`}
+ variant={showFilters ? "secondary" : "ghost"}
+ size="sm"
aria-expanded={showFilters}
aria-controls="search-performance-filters"
onClick={() => setShowFilters((current) => !current)}
title="Toggle table filters"
>
- <SlidersHorizontal className="size-3.5" />
+ <SlidersHorizontal data-icon="inline-start" />
Filters
{activeFilterCount > 0 ? (
- <span className="badge badge-xs badge-primary border-0 text-primary-content">
- {activeFilterCount}
- </span>
+ <Badge size="sm">{activeFilterCount}</Badge>
) : null}
- </button>
+ </Button>
{reportQuery.isFetching && !reportQuery.isPending ? (
- <Loader2 className="size-4 animate-spin text-base-content/40" />
+ <Spinner className="size-4 text-muted-foreground" />
) : null}
<SearchPerformanceSelects
search={search}
@@ -327,6 +316,16 @@ export function SearchPerformancePage({
<StrikingDistanceTable
projectId={projectId}
rows={report.strikingDistance}
+ page={page}
+ pageSize={pageSize}
+ onPageChange={(nextPage) =>
+ onSearchChange({ page: nextPage })
+ }
+ onPageSizeChange={(size) =>
+ onSearchChange({ page: undefined, size })
+ }
+ isFiltered={activeFilterCount > 0}
+ onClearFilters={resetFilters}
/>
) : (
<DimensionSection
@@ -341,9 +340,11 @@ export function SearchPerformancePage({
onPageSizeChange={(size) =>
onSearchChange({ page: undefined, size })
}
+ isFiltered={activeFilterCount > 0}
+ onClearFilters={resetFilters}
/>
)}
- </div>
+ </Tabs>
</>
)}
</div>
diff --git a/src/client/features/search-performance/SearchPerformanceParts.tsx b/src/client/features/search-performance/SearchPerformanceParts.tsx
index 95cab97a..09e24d73 100644
--- a/src/client/features/search-performance/SearchPerformanceParts.tsx
+++ b/src/client/features/search-performance/SearchPerformanceParts.tsx
@@ -2,8 +2,8 @@ import { useMemo, useState } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { Copy, Loader2, Save } from "lucide-react";
import { toast } from "sonner";
-import { AppDataTable } from "@/client/components/table/AppDataTable";
import {
+ DataTable,
useDataTable,
useSelectionAnchor,
} from "@/client/components/table/DataTable";
@@ -12,6 +12,8 @@ import {
TableBulkActionButton,
} from "@/client/components/table/TableBulkActionBar";
import { TablePagination } from "@/client/components/table/TablePagination";
+import { Button } from "@/client/components/ui/button";
+import { Card } from "@/client/components/ui/card";
import {
buildDimensionColumns,
buildStrikingColumns,
@@ -74,16 +76,19 @@ function dimensionExportTable(
};
}
-function runExport(table: ExportTable, target: ExportTarget): void {
- void exportRows({
+function runExport(table: ExportTable, target: ExportTarget): Promise<void> {
+ return exportRows({
format: target,
feature: "search_performance",
...table,
});
}
-export function exportStriking(report: Report, target: ExportTarget): void {
- runExport(strikingExportTable(report), target);
+export function exportStriking(
+ report: Report,
+ target: ExportTarget,
+): Promise<void> {
+ return runExport(strikingExportTable(report), target);
}
/** Export the full queries/pages dataset (fetched separately, not the visible
@@ -93,31 +98,9 @@ export function exportDimensionRows(
rows: SearchPerformanceTableRow[],
range: Report["range"],
target: ExportTarget,
-): void {
+): Promise<void> {
const stamp = `${range.startDate}-to-${range.endDate}`;
- runExport(dimensionExportTable(dimension, rows, stamp), target);
-}
-
-export function TabButton({
- active,
- onClick,
- label,
-}: {
- active: boolean;
- onClick: () => void;
- label: string;
-}) {
- return (
- <button
- type="button"
- role="tab"
- aria-selected={active}
- className={`tab ${active ? "tab-active" : ""}`}
- onClick={onClick}
- >
- {label}
- </button>
- );
+ return runExport(dimensionExportTable(dimension, rows, stamp), target);
}
type Delta = { text: string; improved: boolean } | null;
@@ -184,31 +167,39 @@ function TotalCard({
deltaTitle: string;
}) {
return (
- <div className="rounded-lg border border-base-300 bg-base-100 p-4">
- <div className="text-xs uppercase tracking-wide text-base-content/60">
+ <Card className="gap-0 p-4">
+ <div className="text-xs uppercase tracking-wide text-muted-foreground">
{label}
</div>
<div className="mt-1 flex items-baseline gap-2">
<span className="text-2xl font-semibold">{value}</span>
{delta ? (
<span
- className={`text-xs ${delta.improved ? "text-success" : "text-error"}`}
+ className={`text-xs ${delta.improved ? "text-success" : "text-destructive"}`}
title={deltaTitle}
>
{delta.text}
</span>
) : null}
</div>
- </div>
+ </Card>
);
}
export function DimensionTable({
rows,
keyLabel,
+ isFiltered,
+ isPastEnd,
+ onClearFilters,
+ onFirstPage,
}: {
rows: SearchPerformanceTableRow[];
keyLabel: string;
+ isFiltered: boolean;
+ isPastEnd: boolean;
+ onClearFilters: () => void;
+ onFirstPage: () => void;
}) {
const columns = useMemo(() => buildDimensionColumns(keyLabel), [keyLabel]);
const table = useDataTable({
@@ -218,14 +209,25 @@ export function DimensionTable({
initialState: { sorting: [{ id: "clicks", desc: true }] },
});
return (
- <AppDataTable
+ <DataTable
table={table}
- className="table table-zebra table-sm"
- wrapperClassName="overflow-x-auto"
+ isFiltered={isFiltered && !isPastEnd}
+ onClearFilters={onClearFilters}
empty={
- <p className="p-6 text-sm text-base-content/60">
- No data for this period yet. Search Console data trails by a few days.
- </p>
+ isPastEnd
+ ? {
+ title: "No rows on this page",
+ description: "This page is past the end of the results.",
+ action: (
+ <Button variant="outline" size="sm" onClick={onFirstPage}>
+ Go to first page
+ </Button>
+ ),
+ }
+ : {
+ title: "No Search Console data yet",
+ description: "Search Console data can take a few days to appear.",
+ }
}
/>
);
@@ -234,9 +236,21 @@ export function DimensionTable({
export function StrikingDistanceTable({
projectId,
rows,
+ page,
+ pageSize,
+ onPageChange,
+ onPageSizeChange,
+ isFiltered,
+ onClearFilters,
}: {
projectId: string;
rows: Report["strikingDistance"];
+ page: number;
+ pageSize: number;
+ onPageChange: (page: number) => void;
+ onPageSizeChange: (size: number) => void;
+ isFiltered: boolean;
+ onClearFilters: () => void;
}) {
const queryClient = useQueryClient();
const anchorRef = useSelectionAnchor();
@@ -248,18 +262,15 @@ export function StrikingDistanceTable({
withSorting: true,
withPagination: true,
enableRowSelection: true,
- state: { rowSelection },
+ state: { rowSelection, pagination: { pageIndex: page - 1, pageSize } },
onRowSelectionChange: setRowSelection,
// The server collapses each query to its top page, so queries are unique.
getRowId: (row) => row.query,
initialState: {
sorting: [{ id: "impressions", desc: true }],
- // All rows are already loaded; paginate client-side to keep the table
- // short. 50/page by default.
- pagination: { pageIndex: 0, pageSize: 50 },
},
});
- const pagination = table.getState().pagination;
+ const isPastEnd = page > 1 && table.getRowModel().rows.length === 0;
const selectedQueries = table
.getSelectedRowModel()
@@ -299,39 +310,52 @@ export function StrikingDistanceTable({
},
});
- if (rows.length === 0) {
- return (
- <p className="p-6 text-sm text-base-content/60">
- No striking-distance queries in this period. These are queries ranking
- at positions 5 to 20, where an improvement is most likely to move
- traffic.
- </p>
- );
- }
-
return (
<>
<div className="p-4">
- <p className="mb-3 text-sm text-base-content/60">
+ <p className="mb-3 text-sm text-muted-foreground">
Queries ranking at positions 5 to 20, sorted by impressions. Improve
the listed page to move them into the top results.
</p>
- <AppDataTable
+ <DataTable
table={table}
- className="table table-zebra table-sm"
- wrapperClassName="overflow-x-auto"
+ isFiltered={isFiltered && !isPastEnd}
+ onClearFilters={onClearFilters}
+ empty={
+ isPastEnd
+ ? {
+ title: "No rows on this page",
+ description: "This page is past the end of the results.",
+ action: (
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={() => onPageChange(1)}
+ >
+ Go to first page
+ </Button>
+ ),
+ }
+ : {
+ title: "No striking-distance queries",
+ description:
+ "Queries ranking at positions 5 to 20 will appear here.",
+ }
+ }
/>
</div>
- <TablePagination
- page={pagination.pageIndex + 1}
- pageSize={pagination.pageSize}
- pageSizes={SEARCH_PERFORMANCE_PAGE_SIZES}
- totalCount={rows.length}
- hasNextPage={table.getCanNextPage()}
- isLoading={false}
- onPageChange={(nextPage) => table.setPageIndex(nextPage - 1)}
- onPageSizeChange={(nextSize) => table.setPageSize(nextSize)}
- />
+ {!isPastEnd && rows.length > 0 && (
+ <TablePagination
+ page={page}
+ pageSize={pageSize}
+ pageSizes={SEARCH_PERFORMANCE_PAGE_SIZES}
+ totalCount={rows.length}
+ hasNextPage={table.getCanNextPage()}
+ isLoading={false}
+ onPageChange={onPageChange}
+ onPageSizeChange={onPageSizeChange}
+ />
+ )}
<TableBulkActionBar
selectedCount={selectedQueries.length}
selectedLabel={selectedQueries.length === 1 ? "query" : "queries"}
diff --git a/src/client/features/search-performance/SearchPerformanceSelects.tsx b/src/client/features/search-performance/SearchPerformanceSelects.tsx
index 827a2460..1086f807 100644
--- a/src/client/features/search-performance/SearchPerformanceSelects.tsx
+++ b/src/client/features/search-performance/SearchPerformanceSelects.tsx
@@ -5,6 +5,13 @@ import {
type SearchPerformanceDevice,
type SearchPerformanceSearch,
} from "@/types/schemas/search-performance";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/client/components/ui/select";
const RANGE_LABELS: Record<SearchPerformanceDateRange, string> = {
last_7_days: "Last 7 days",
@@ -28,6 +35,7 @@ const DEVICE_OPTIONS = GSC_DEVICES.map((value) => ({
// Sentinel for "no filter" in the selects; never written to the URL.
const ALL = "ALL";
+const DEVICE_ITEMS = [{ value: ALL, label: "All devices" }, ...DEVICE_OPTIONS];
function isDateRange(value: string): value is SearchPerformanceDateRange {
return SEARCH_PERFORMANCE_RANGES.some((option) => option === value);
@@ -50,69 +58,85 @@ export function SearchPerformanceSelects({
const device = search.device ?? ALL;
const country = search.country ?? ALL;
const range = search.range ?? "last_28_days";
+ const countryItems = [
+ { value: ALL, label: "All countries" },
+ ...(country !== ALL && !countries.some((row) => row.key === country)
+ ? [{ value: country, label: country.toUpperCase() }]
+ : []),
+ ...countries.map((row) => ({
+ value: row.key,
+ label: row.key.toUpperCase(),
+ })),
+ ];
return (
<div className="ml-auto flex flex-wrap items-center justify-end gap-2">
- <select
- className="select select-bordered select-sm w-36"
+ <Select
+ items={DEVICE_ITEMS}
value={device}
- onChange={(event) =>
+ onValueChange={(value) => {
+ if (value == null) return;
onSearchChange({
page: undefined,
- device: isDevice(event.target.value)
- ? event.target.value
- : undefined,
- })
- }
- aria-label="Device filter"
+ device: isDevice(value) ? value : undefined,
+ });
+ }}
>
- <option value={ALL}>All devices</option>
- {DEVICE_OPTIONS.map((option) => (
- <option key={option.value} value={option.value}>
- {option.label}
- </option>
- ))}
- </select>
- <select
- className="select select-bordered select-sm w-36"
+ <SelectTrigger size="sm" className="w-36" aria-label="Device filter">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {DEVICE_ITEMS.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <Select
+ items={countryItems}
value={country}
- onChange={(event) =>
+ onValueChange={(value) => {
+ if (value == null) return;
onSearchChange({
page: undefined,
- country:
- event.target.value === ALL ? undefined : event.target.value,
- })
- }
- aria-label="Country filter"
+ country: value === ALL ? undefined : value,
+ });
+ }}
>
- <option value={ALL}>All countries</option>
- {country !== ALL && !countries.some((row) => row.key === country) ? (
- <option value={country}>{country.toUpperCase()}</option>
- ) : null}
- {countries.map((row) => (
- <option key={row.key} value={row.key}>
- {row.key.toUpperCase()}
- </option>
- ))}
- </select>
- <select
- className="select select-bordered select-sm w-36"
+ <SelectTrigger size="sm" className="w-36" aria-label="Country filter">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {countryItems.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <Select
+ items={RANGE_OPTIONS}
value={range}
- onChange={(event) => {
- if (isDateRange(event.target.value)) {
+ onValueChange={(value) => {
+ if (value != null && isDateRange(value)) {
onSearchChange({
page: undefined,
- range: event.target.value,
+ range: value,
});
}
}}
- aria-label="Date range"
>
- {RANGE_OPTIONS.map((option) => (
- <option key={option.value} value={option.value}>
- {option.label}
- </option>
- ))}
- </select>
+ <SelectTrigger size="sm" className="w-36" aria-label="Date range">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {RANGE_OPTIONS.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
</div>
);
}
diff --git a/src/client/features/search-performance/SearchPerformanceTextFilters.tsx b/src/client/features/search-performance/SearchPerformanceTextFilters.tsx
index 7ab86d2a..6e62d98f 100644
--- a/src/client/features/search-performance/SearchPerformanceTextFilters.tsx
+++ b/src/client/features/search-performance/SearchPerformanceTextFilters.tsx
@@ -1,8 +1,23 @@
import { useState } from "react";
import { RotateCcw } from "lucide-react";
import type { z } from "zod";
+import { Badge } from "@/client/components/ui/badge";
+import { Button } from "@/client/components/ui/button";
+import { Input } from "@/client/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/client/components/ui/select";
import type { searchPerformanceInputSchema } from "@/types/schemas/search-performance";
+const MATCH_ITEMS = [
+ { value: "contains", label: "Contains" },
+ { value: "equals", label: "Exactly matches" },
+];
+
export type TextFilters = Pick<
z.infer<typeof searchPerformanceInputSchema>,
"pageFilter" | "queryFilter"
@@ -45,7 +60,7 @@ export function SearchPerformanceTextFilters({
return (
<form
id="search-performance-filters"
- className="border-b border-base-300 bg-gradient-to-b from-base-100 to-base-200/30 px-4 py-3 space-y-3"
+ className="space-y-3 border-b border-border bg-muted/20 px-4 py-3"
onSubmit={(event) => {
event.preventDefault();
setPage(page.trim());
@@ -66,19 +81,18 @@ export function SearchPerformanceTextFilters({
<div className="flex items-center gap-2">
<p className="text-sm font-semibold">Refine table results</p>
{activeFilterCount > 0 ? (
- <span className="badge badge-xs badge-primary border-0 text-primary-content">
- {activeFilterCount} active
- </span>
+ <Badge size="sm">{activeFilterCount} active</Badge>
) : null}
{dirtyCount > 0 ? (
- <span className="badge badge-xs badge-warning border-0">
+ <Badge variant="warning" size="sm">
{dirtyCount} unapplied
- </span>
+ </Badge>
) : null}
</div>
- <button
+ <Button
type="button"
- className="btn btn-xs btn-ghost gap-1"
+ variant="ghost"
+ size="xs"
disabled={activeFilterCount === 0 && dirtyCount === 0}
onClick={() => {
setPage("");
@@ -88,31 +102,40 @@ export function SearchPerformanceTextFilters({
onReset();
}}
>
- <RotateCcw className="size-3" />
+ <RotateCcw data-icon="inline-start" />
Clear all
- </button>
+ </Button>
</div>
<div className="grid gap-3 md:grid-cols-2">
<div className="space-y-1.5">
- <span className="text-[11px] font-semibold uppercase tracking-wide text-base-content/60">
+ <span className="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground">
Page URL
</span>
<div className="flex flex-col gap-2 sm:flex-row">
- <select
- aria-label="Page match"
- className="select select-bordered select-sm bg-base-100 w-full sm:w-44 sm:shrink-0"
+ <Select
+ items={MATCH_ITEMS}
value={pageOperator}
- onChange={(event) =>
- setPageOperator(
- event.target.value === "equals" ? "equals" : "contains",
- )
+ onValueChange={(operator) =>
+ setPageOperator(operator === "equals" ? "equals" : "contains")
}
>
- <option value="contains">Contains</option>
- <option value="equals">Exactly matches</option>
- </select>
- <input
- className="input input-bordered input-sm bg-base-100 w-full min-w-0 sm:flex-1"
+ <SelectTrigger
+ size="sm"
+ className="w-full sm:w-44 sm:shrink-0"
+ aria-label="Page match"
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {MATCH_ITEMS.map((item) => (
+ <SelectItem key={item.value} value={item.value}>
+ {item.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <Input
+ className="h-7 w-full min-w-0 sm:flex-1"
aria-label="Page URL filter"
value={page}
maxLength={4096}
@@ -122,25 +145,34 @@ export function SearchPerformanceTextFilters({
</div>
</div>
<div className="space-y-1.5">
- <span className="text-[11px] font-semibold uppercase tracking-wide text-base-content/60">
+ <span className="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground">
Query
</span>
<div className="flex flex-col gap-2 sm:flex-row">
- <select
- aria-label="Query match"
- className="select select-bordered select-sm bg-base-100 w-full sm:w-44 sm:shrink-0"
+ <Select
+ items={MATCH_ITEMS}
value={queryOperator}
- onChange={(event) =>
- setQueryOperator(
- event.target.value === "equals" ? "equals" : "contains",
- )
+ onValueChange={(operator) =>
+ setQueryOperator(operator === "equals" ? "equals" : "contains")
}
>
- <option value="contains">Contains</option>
- <option value="equals">Exactly matches</option>
- </select>
- <input
- className="input input-bordered input-sm bg-base-100 w-full min-w-0 sm:flex-1"
+ <SelectTrigger
+ size="sm"
+ className="w-full sm:w-44 sm:shrink-0"
+ aria-label="Query match"
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {MATCH_ITEMS.map((item) => (
+ <SelectItem key={item.value} value={item.value}>
+ {item.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <Input
+ className="h-7 w-full min-w-0 sm:flex-1"
aria-label="Query filter"
value={query}
maxLength={4096}
@@ -150,32 +182,29 @@ export function SearchPerformanceTextFilters({
</div>
</div>
</div>
- <p className="text-xs text-base-content/70">
+ <p className="text-xs text-muted-foreground">
All filters must match. Contains ignores case and matches text anywhere,
including a subfolder. Exactly matches compares the full URL or query,
including case.
</p>
<div className="flex items-center justify-end gap-2 pt-1">
- <button
+ <Button
type="button"
- className="btn btn-sm btn-ghost"
+ variant="ghost"
+ size="sm"
onClick={cancel}
disabled={dirtyCount === 0}
>
Cancel
- </button>
- <button
- className="btn btn-primary btn-sm"
- type="submit"
- disabled={dirtyCount === 0}
- >
+ </Button>
+ <Button size="sm" type="submit" disabled={dirtyCount === 0}>
Apply filters
{dirtyCount > 0 ? (
- <span className="badge badge-xs ml-1 border-0 bg-primary-content/20">
+ <Badge variant="secondary" size="sm" className="ml-1">
{dirtyCount}
- </span>
+ </Badge>
) : null}
- </button>
+ </Button>
</div>
</form>
);