The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add linking w/ prefetch
Tim Wilson8c6f85404951
diff --git a/apps/web/ui/customers/customer-table/customer-table.tsx b/apps/web/ui/customers/customer-table/customer-table.tsxindex d0174ce555..855f78160f 100644--- a/apps/web/ui/customers/customer-table/customer-table.tsx+++ b/apps/web/ui/customers/customer-table/customer-table.tsx@@ -28,6 +28,7 @@ import {fetcher,formatDate,getPrettyUrl,+ isClickOnInteractiveChild,} from "@dub/utils";import { Row } from "@tanstack/react-table";import { Command } from "cmdk";@@ -43,6 +44,8 @@ export function CustomerTable() {const { id: workspaceId, slug: workspaceSlug } = useWorkspace();const { queryParams, searchParams, getQueryString } = useRouterStuff();+ const router = useRouter();+const sortBy = searchParams.get("sortBy") || "createdAt";const sortOrder = searchParams.get("sortOrder") === "asc" ? "asc" : "desc";@@ -196,7 +199,22 @@ export function CustomerTable() {const { table, ...tableProps } = useTable({data: customers || [],columns,- onRowClick: (row) => {},+ rowProps: (row) => {+ const href = `/${workspaceSlug}/customers/${row.original.id}`;+ return {+ className: "cursor-pointer select-none",+ onMouseEnter: () => router.prefetch(href),+ onClick: (e) => {+ if (isClickOnInteractiveChild(e)) return;+ if (e.metaKey || e.ctrlKey) window.open(href, "_blank");+ else router.push(href);+ },+ onAuxClick: (e) => {+ if (isClickOnInteractiveChild(e)) return;+ window.open(href, "_blank");+ },+ };+ },pagination,onPaginationChange: setPagination,columnVisibility,@@ -215,7 +233,8 @@ export function CustomerTable() {}),columnPinning: { right: ["menu"] },thClassName: "border-l-0",- tdClassName: "border-l-0",+ tdClassName:+ "border-l-0 group-hover/row:bg-bg-muted transition-colors duration-75",resourceName: (p) => `customer${p ? "s" : ""}`,rowCount: customersCount || 0,loading: isLoading,diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsxindex b9e984716d..cb45d23999 100644--- a/packages/ui/src/table/table.tsx+++ b/packages/ui/src/table/table.tsx@@ -18,6 +18,7 @@ import { AnimatePresence, motion } from "framer-motion";import {CSSProperties,Dispatch,+ HTMLAttributes,memo,MouseEvent,PropsWithChildren,@@ -68,6 +69,9 @@ type BaseTableProps<T> = {columnPinning?: ColumnPinningState;resourceName?: (plural: boolean) => string;onRowClick?: (row: Row<T>, e: MouseEvent) => void;+ rowProps?:+ | HTMLAttributes<HTMLTableRowElement>+ | ((row: Row<T>) => HTMLAttributes<HTMLTableRowElement>);enableColumnResizing?: boolean;columnResizeMode?: ColumnResizeMode;@@ -196,16 +200,20 @@ const ResizableTableRow = memo(function ResizableTableRow<T>({row,onRowClick,+ rowProps,cellRight,tdClassName,table,}: {row: Row<T>;onRowClick?: (row: Row<T>, e: MouseEvent) => void;+ rowProps?: HTMLAttributes<HTMLTableRowElement>;cellRight?: (cell: Cell<T, any>) => ReactNode;tdClassName?: string | ((columnId: string) => string);table: TableType<T>;}) {+ const { className, ...rest } = rowProps || {};+return (<trkey={row.id}@@ -216,6 +224,7 @@ const ResizableTableRow = memo(table.getRowModel().rows.length > 8 &&row.index === table.getRowModel().rows.length - 1 &&"[&_td]:border-b-0",+ className,)}onClick={onRowClick@@ -226,6 +235,7 @@ const ResizableTableRow = memo(}: undefined}+ {...rest}>{row.getVisibleCells().map((cell) => (<td@@ -269,6 +279,7 @@ const ResizableTableRow = memo() as <T>(props: {row: Row<T>;onRowClick?: (row: Row<T>, e: MouseEvent) => void;+ rowProps?: HTMLAttributes<HTMLTableRowElement>;cellRight?: (cell: Cell<T, any>) => ReactNode;tdClassName?: string | ((columnId: string) => string);table: TableType<T>;@@ -294,6 +305,7 @@ export function Table<T>({pagination,resourceName,onRowClick,+ rowProps,rowCount,children,enableColumnResizing = false,@@ -419,8 +431,12 @@ export function Table<T>({))}</thead><tbody>- {table.getRowModel().rows.map((row) =>- enableColumnResizing ? (+ {table.getRowModel().rows.map((row) => {+ const props =+ typeof rowProps === "function" ? rowProps(row) : rowProps;+ const { className, ...rest } = props || {};++ return enableColumnResizing ? (<ResizableTableRowkey={`${row.id}-${table.getVisibleLeafColumns()@@ -428,6 +444,7 @@ export function Table<T>({.join(",")}`}row={row}onRowClick={onRowClick}+ rowProps={props}cellRight={cellRight}tdClassName={tdClassName}table={table}@@ -441,6 +458,7 @@ export function Table<T>({table.getRowModel().rows.length > 8 &&row.index === table.getRowModel().rows.length - 1 &&"[&_td]:border-b-0",+ className,)}onClick={onRowClick@@ -450,6 +468,7 @@ export function Table<T>({}: undefined}+ {...rest}>{row.getVisibleCells().map((cell) => (<td@@ -484,8 +503,8 @@ export function Table<T>({</td>))}</tr>- ),- )}+ );+ })}</tbody></table>{children}