Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

WIP bulk actions

Tim Wilson64edae14fd93
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx
index 6e7cc29824..b97ec340d4 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx
@@ -25,6 +25,7 @@ import { Row } from "@tanstack/react-table";
import { Command } from "cmdk";
import Link from "next/link";
import { useEffect, useMemo, useState } from "react";
+import { toast } from "sonner";
import useSWR from "swr";
import { useColumnVisibility } from "./use-column-visibility";
@@ -263,6 +264,22 @@ export function ProgramPartnersApplicationsPageClient() {
onRowSelectionChange: (rows) => {
console.log(rows);
},
+ selectionControls: (table) => (
+ <>
+ <Button
+ variant="primary"
+ text="Approve"
+ className="h-7 w-fit rounded-lg px-2.5"
+ onClick={() => toast.info("WIP")}
+ />
+ <Button
+ variant="secondary"
+ text="Reject"
+ className="h-7 w-fit rounded-lg px-2.5"
+ onClick={() => toast.info("WIP")}
+ />
+ </>
+ ),
thClassName: "border-l-0",
tdClassName: "border-l-0",
diff --git a/packages/ui/src/table/selection-toolbar.tsx b/packages/ui/src/table/selection-toolbar.tsx
new file mode 100644
index 0000000000..060361540c
--- /dev/null
+++ b/packages/ui/src/table/selection-toolbar.tsx
@@ -0,0 +1,48 @@
+import { cn } from "@dub/utils";
+import { Table } from "@tanstack/react-table";
+import { ReactNode, useEffect, useState } from "react";
+
+export function SelectionToolbar<T>({
+ table,
+ controls,
+}: {
+ table: Table<T>;
+ controls?: (table: Table<T>) => ReactNode;
+}) {
+ const selectedCount = table.getSelectedRowModel().rows.length;
+ const [lastSelectedCount, setLastSelectedCount] = useState(0);
+
+ useEffect(() => {
+ if (selectedCount !== 0) setLastSelectedCount(selectedCount);
+ }, [selectedCount]);
+
+ return (
+ <tr
+ className={cn("size-0")}
+ {...{
+ inert: table.getSelectedRowModel().rows.length ? undefined : "",
+ }}
+ >
+ <td colSpan={table.getHeaderGroups().length} className="contents size-0">
+ <div
+ className={cn(
+ "pointer-events-none absolute bottom-px left-11 right-0 top-0 bg-white opacity-0 duration-150",
+ selectedCount && "pointer-events-auto opacity-100",
+ )}
+ >
+ <div
+ className={cn(
+ "flex size-full -translate-x-1 items-center gap-2 transition-transform duration-150",
+ selectedCount && "translate-x-0",
+ )}
+ >
+ <span className="text-content-emphasis mr-2 text-sm font-medium">
+ {lastSelectedCount} selected
+ </span>
+ {controls?.(table)}
+ </div>
+ </div>
+ </td>
+ </tr>
+ );
+}
diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsx
index 6c9281251f..9e01a3e3d9 100644
--- a/packages/ui/src/table/table.tsx
+++ b/packages/ui/src/table/table.tsx
@@ -21,6 +21,7 @@ import {
import { Button } from "../button";
import { Checkbox } from "../checkbox";
import { LoadingSpinner, SortOrder } from "../icons";
+import { SelectionToolbar } from "./selection-toolbar";
import { TableProps, UseTableProps } from "./types";
const tableCellClassName = (columnId: string, clickable?: boolean) =>
@@ -98,13 +99,13 @@ export function useTable<T extends any>(
{
id: "select",
enableHiding: false,
- minSize: 32,
- size: 32,
- maxSize: 32,
+ minSize: 30,
+ size: 30,
+ maxSize: 30,
header: ({ table }: { table: TableType<T> }) => (
<div className="flex size-full items-center justify-center">
<Checkbox
- className="border-border-default size-4 rounded"
+ className="border-border-default size-4 rounded data-[state=checked]:bg-black"
checked={
table.getIsAllRowsSelected()
? true
@@ -120,7 +121,7 @@ export function useTable<T extends any>(
cell: ({ row }: { row: Row<T> }) => (
<div className="flex size-full items-center justify-center">
<Checkbox
- className="border-border-default size-4 rounded"
+ className="border-border-default size-4 rounded data-[state=checked]:bg-black"
checked={row.getIsSelected()}
onCheckedChange={row.getToggleSelectedHandler()}
title="Select"
@@ -274,6 +275,8 @@ export function Table<T>({
pagination,
resourceName,
onRowClick,
+ onRowSelectionChange,
+ selectionControls,
rowProps,
rowCount,
children,
@@ -319,7 +322,7 @@ export function Table<T>({
minWidth: tableWidth,
}}
>
- <thead>
+ <thead className="relative">
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => {
@@ -401,6 +404,9 @@ export function Table<T>({
})}
</tr>
))}
+ {onRowSelectionChange && (
+ <SelectionToolbar table={table} controls={selectionControls} />
+ )}
</thead>
<tbody>
{table.getRowModel().rows.map((row) => {
diff --git a/packages/ui/src/table/types.ts b/packages/ui/src/table/types.ts
index 723f0c9431..ddc8df591d 100644
--- a/packages/ui/src/table/types.ts
+++ b/packages/ui/src/table/types.ts
@@ -51,6 +51,7 @@ type BaseTableProps<T> = {
getRowId?: (row: T) => string;
onRowSelectionChange?: (rows: Row<T>[]) => void;
selectedRows?: RowSelectionState;
+ selectionControls?: (table: TableType<T>) => ReactNode;
// Misc. row props
onRowClick?: (row: Row<T>, e: MouseEvent) => void;