Openstatus www.openstatus.dev
at main 58 lines 1.7 kB view raw
1"use client"; 2 3import type { Table } from "@tanstack/react-table"; 4import { X } from "lucide-react"; 5 6import { Button } from "@/components/ui/button"; 7import { Input } from "@/components/ui/input"; 8 9import { DataTableFacetedFilter } from "@/components/ui/data-table/data-table-faceted-filter"; 10import type { RouterOutputs } from "@openstatus/api"; 11 12type Monitor = RouterOutputs["monitor"]["list"][number]; 13type MonitorTag = RouterOutputs["monitorTag"]["list"][number]; 14 15export interface MonitorDataTableToolbarProps { 16 table: Table<Monitor>; 17 tags: MonitorTag[]; 18} 19 20export function MonitorDataTableToolbar({ 21 table, 22 tags, 23}: MonitorDataTableToolbarProps) { 24 const isFiltered = table.getState().columnFilters.length > 0; 25 26 return ( 27 <div className="flex items-center justify-between"> 28 <div className="flex flex-1 flex-wrap items-center space-x-2"> 29 <Input 30 placeholder="Filter by name, url, type..." 31 value={(table.getState().globalFilter as string) ?? ""} 32 onChange={(event) => table.setGlobalFilter(event.target.value)} 33 className="h-8 w-[150px] lg:w-[250px]" 34 /> 35 {table.getColumn("tags") && ( 36 <DataTableFacetedFilter 37 column={table.getColumn("tags")} 38 title="Tags" 39 options={tags.map((tag) => ({ 40 label: tag.name, 41 value: tag.id, 42 }))} 43 /> 44 )} 45 {isFiltered && ( 46 <Button 47 variant="ghost" 48 onClick={() => table.resetColumnFilters()} 49 className="h-8 px-2 lg:px-3" 50 > 51 Reset 52 <X /> 53 </Button> 54 )} 55 </div> 56 </div> 57 ); 58}