The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add row selection
Kiran K14454623d24a
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsxindex a851b6b01f..3cc4760599 100644--- a/apps/web/ui/partners/payout-invoice-sheet.tsx+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx@@ -6,8 +6,10 @@ import {import usePayouts from "@/lib/swr/use-payouts";import useWorkspace from "@/lib/swr/use-workspace";import { X } from "@/ui/shared/icons";+import { Payout } from "@dub/prisma/client";import { Button, Sheet, Table, useRouterStuff, useTable } from "@dub/ui";import { cn, currencyFormatter, DICEBEAR_AVATAR_URL } from "@dub/utils";+import { Row } from "@tanstack/react-table";import { useAction } from "next-safe-action/hooks";import { useParams } from "next/navigation";import { Dispatch, Fragment, SetStateAction, useMemo, useState } from "react";@@ -20,6 +22,7 @@ interface PayoutInvoiceSheetProps {function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {const { id: workspaceId, slug } = useWorkspace();const { programId } = useParams<{ programId: string }>();+ const [selectedPayouts, setSelectedPayouts] = useState<Payout[]>([]);const {payouts,@@ -52,7 +55,7 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {(payout) =>payout.partner.payoutsEnabled && payout.amount >= MIN_PAYOUT_AMOUNT,),- [payouts],+ [ payouts],);const invoiceData = useMemo(() => {@@ -98,6 +101,27 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {const table = useTable({data: pendingPayouts || [],columns: [+ {+ id: "selection",+ header: ({ table }) => (+ <input+ type="checkbox"+ className="h-4 w-4 cursor-pointer rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"+ checked={table.getIsAllRowsSelected()}+ onChange={table.getToggleAllRowsSelectedHandler()}+ />+ ),+ cell: ({ row }) => (+ <input+ type="checkbox"+ className="h-4 w-4 cursor-pointer rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"+ checked={row.getIsSelected()}+ onChange={row.getToggleSelectedHandler()}+ />+ ),+ minSize: 10,+ size: 30,+ },{header: "Partner",cell: ({ row }) => (@@ -136,6 +160,9 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {error: payoutsError? "Failed to load payouts for this invoice.": undefined,+ onRowSelectionChange: (rows) => {+ setSelectedPayouts(rows.map((row) => row.original));+ },} as any);return (diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsxindex 2467bb39a6..0dbc52acd1 100644--- a/packages/ui/src/table/table.tsx+++ b/packages/ui/src/table/table.tsx@@ -8,6 +8,7 @@ import {getCoreRowModel,PaginationState,Row,+ RowSelectionState,Table as TableType,useReactTable,VisibilityState,@@ -54,6 +55,7 @@ type UseTableProps<T> = {columnPinning?: ColumnPinningState;resourceName?: (plural: boolean) => string;onRowClick?: (row: Row<T>, e: MouseEvent) => void;+ onRowSelectionChange?: (rows: Row<T>[]) => void;className?: string;containerClassName?: string;@@ -91,6 +93,8 @@ export function useTable<T extends any>(props.columnVisibility ?? {},);+ const [rowSelection, setRowSelection] = useState<RowSelectionState>({});+// Update internal columnVisibility when prop value changesuseEffect(() => {if (@@ -105,6 +109,13 @@ export function useTable<T extends any>(props.onColumnVisibilityChange?.(columnVisibility);}, [columnVisibility]);+ // Call onRowSelectionChange when internal rowSelection changes+ useEffect(() => {+ props.onRowSelectionChange?.(+ Object.keys(rowSelection).map((key) => table.getRow(key)),+ );+ }, [rowSelection]);+const table = useReactTable({data,rowCount,@@ -118,10 +129,12 @@ export function useTable<T extends any>(getCoreRowModel: getCoreRowModel(),onPaginationChange,onColumnVisibilityChange: (visibility) => setColumnVisibility(visibility),+ onRowSelectionChange: (selection) => setRowSelection(selection),state: {pagination: pagination,columnVisibility,columnPinning: { left: [], right: [], ...columnPinning },+ rowSelection,},manualPagination: true,autoResetPageIndex: false,