Openstatus
www.openstatus.dev
1"use client";
2
3import type { Table } from "@tanstack/react-table";
4import { X } from "lucide-react";
5
6import type { MonitorTag } from "@openstatus/db/src/schema";
7import { Button, Input } from "@openstatus/ui";
8
9import { DataTableFacetedFilter } from "../data-table-faceted-filter";
10
11interface DataTableToolbarProps<TData> {
12 table: Table<TData>;
13 tags?: MonitorTag[];
14}
15
16export function DataTableToolbar<TData>({
17 table,
18 tags,
19}: DataTableToolbarProps<TData>) {
20 const isFiltered = table.getState().columnFilters.length > 0;
21
22 return (
23 <div className="flex flex-wrap items-center justify-between gap-3">
24 <div className="flex flex-1 flex-wrap items-center gap-2">
25 <Input
26 placeholder="Filter names..."
27 value={(table.getColumn("name")?.getFilterValue() as string) ?? ""}
28 onChange={(event) =>
29 table.getColumn("name")?.setFilterValue(event.target.value)
30 }
31 className="h-8 w-[150px] lg:w-[250px]"
32 />
33 {table.getColumn("tags") && tags && (
34 <DataTableFacetedFilter
35 column={table.getColumn("tags")}
36 title="Tags"
37 options={tags?.map((tag) => ({
38 label: tag.name,
39 value: tag.name,
40 }))}
41 />
42 )}
43 {table.getColumn("public") && (
44 <DataTableFacetedFilter
45 column={table.getColumn("public")}
46 title="Visibility"
47 options={[
48 { label: "Public", value: true },
49 { label: "Private", value: false },
50 ]}
51 />
52 )}
53 {table.getColumn("active") && (
54 <DataTableFacetedFilter
55 column={table.getColumn("active")}
56 title="Active"
57 options={[
58 { label: "True", value: true },
59 { label: "False", value: false },
60 ]}
61 />
62 )}
63 {table.getColumn("jobType") && (
64 <DataTableFacetedFilter
65 column={table.getColumn("jobType")}
66 title="Type"
67 options={[
68 { label: "HTTP", value: "http" },
69 { label: "TCP", value: "tcp" },
70 ]}
71 />
72 )}
73 {isFiltered && (
74 <Button
75 variant="ghost"
76 onClick={() => table.resetColumnFilters()}
77 className="h-8 px-2 lg:px-3"
78 >
79 Reset
80 <X className="ml-2 h-4 w-4" />
81 </Button>
82 )}
83 </div>
84 <div className="flex items-center self-end rounded-lg border border-dashed bg-muted/50 px-3 py-2">
85 <p className="text-muted-foreground text-xs">
86 Quantiles and Uptime are aggregated data from the{" "}
87 <span className="text-foreground">last 24h</span>.
88 </p>
89 </div>
90 </div>
91 );
92}