From 614f726062a46576dba4d8d07dc718373057c94f Mon Sep 17 00:00:00 2001 From: rzmk Date: Tue, 20 Feb 2024 09:34:07 -0500 Subject: [PATCH] feat: add dropdown for selecting column to search by --- src-tauri/Cargo.lock | 6 +-- src-tauri/Cargo.toml | 6 +-- src/components/DT/columns.tsx | 3 ++ src/components/DT/data-table.tsx | 86 +++++++++++++++++++++++++------- 4 files changed, 76 insertions(+), 25 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 40d4038..3f4e672 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3842,7 +3842,7 @@ dependencies = [ [[package]] name = "tauri-plugin-dialog" version = "2.0.0-beta.0" -source = "git+https://github.com/tauri-apps/plugins-workspace.git?rev=a31ef8e67e25d233cf463efb65428d7e0893e404#a31ef8e67e25d233cf463efb65428d7e0893e404" +source = "git+https://github.com/tauri-apps/plugins-workspace.git?branch=chore/tauri-beta-3#4709c343bcc0342b20d241ad16a1fe405ce7e182" dependencies = [ "glib 0.16.9", "log", @@ -3859,7 +3859,7 @@ dependencies = [ [[package]] name = "tauri-plugin-fs" version = "2.0.0-beta.0" -source = "git+https://github.com/tauri-apps/plugins-workspace.git?rev=a31ef8e67e25d233cf463efb65428d7e0893e404#a31ef8e67e25d233cf463efb65428d7e0893e404" +source = "git+https://github.com/tauri-apps/plugins-workspace.git?branch=chore/tauri-beta-3#4709c343bcc0342b20d241ad16a1fe405ce7e182" dependencies = [ "anyhow", "glob", @@ -3877,7 +3877,7 @@ dependencies = [ [[package]] name = "tauri-plugin-shell" version = "2.0.0-beta.0" -source = "git+https://github.com/tauri-apps/plugins-workspace.git?rev=a31ef8e67e25d233cf463efb65428d7e0893e404#a31ef8e67e25d233cf463efb65428d7e0893e404" +source = "git+https://github.com/tauri-apps/plugins-workspace.git?branch=chore/tauri-beta-3#4709c343bcc0342b20d241ad16a1fe405ce7e182" dependencies = [ "encoding_rs", "log", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index fdddb50..82d271f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -21,9 +21,9 @@ tauri-build = { version = "2.0.0-beta.2", features = [] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tauri = { version = "2.0.0-beta.3", features = [] } -tauri-plugin-shell = { git = "https://github.com/tauri-apps/plugins-workspace.git", rev = "a31ef8e67e25d233cf463efb65428d7e0893e404" } -tauri-plugin-fs = { git = "https://github.com/tauri-apps/plugins-workspace.git", rev = "a31ef8e67e25d233cf463efb65428d7e0893e404" } -tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace.git", rev = "a31ef8e67e25d233cf463efb65428d7e0893e404" } +tauri-plugin-shell = { git = "https://github.com/tauri-apps/plugins-workspace.git", branch = "chore/tauri-beta-3" } +tauri-plugin-fs = { git = "https://github.com/tauri-apps/plugins-workspace.git", branch = "chore/tauri-beta-3" } +tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace.git", branch = "chore/tauri-beta-3" } [profile.release] panic = "abort" # Strip expensive panic clean-up logic diff --git a/src/components/DT/columns.tsx b/src/components/DT/columns.tsx index d62a364..ec684e7 100644 --- a/src/components/DT/columns.tsx +++ b/src/components/DT/columns.tsx @@ -11,14 +11,17 @@ export type Prediction = { export const columns: ColumnDef[] = [ { accessorKey: "path", + id: "path", header: "Path", }, { accessorKey: "label", + id: "label", header: "Label", }, { accessorKey: "score", + id: "score", header: "Score", }, ]; diff --git a/src/components/DT/data-table.tsx b/src/components/DT/data-table.tsx index 63b5a66..af123bc 100644 --- a/src/components/DT/data-table.tsx +++ b/src/components/DT/data-table.tsx @@ -1,7 +1,5 @@ "use client"; -import { Button } from "@/components/ui/button"; - import { ColumnDef, ColumnFiltersState, @@ -11,6 +9,7 @@ import { getPaginationRowModel, useReactTable, } from "@tanstack/react-table"; +import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Table, @@ -20,8 +19,19 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuLabel, + DropdownMenuRadioGroup, + DropdownMenuRadioItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; import { useState } from "react"; import { DataTableViewOptions } from "@/components/DT/DataTableViewOptions"; +import { LucideScanSearch } from "lucide-react"; interface DataTableProps { columns: ColumnDef[]; @@ -33,6 +43,7 @@ export function DataTable({ data, }: DataTableProps) { const [columnFilters, setColumnFilters] = useState([]); + const [searchColumn, setSearchColumn] = useState("label"); const table = useReactTable({ data, columns, @@ -47,22 +58,56 @@ export function DataTable({ return (
- {" "} -
- - table - .getColumn("label") - ?.setFilterValue(event.target.value) - } - className="max-w-sm" - /> +
+
+ column.id === searchColumn + )[0].header + }'...`} + value={ + table + .getColumn(searchColumn) + ?.getFilterValue() as string + } + onChange={(event) => + table + .getColumn(searchColumn) + ?.setFilterValue(event.target.value) + } + className="max-w-sm" + /> + + + + + + Search Column + + + {columns + .filter( + (column) => column.id && column.header + ) + .map((column, index) => ( + + {column.header!.toString()} + + ))} + + + +
@@ -96,7 +141,10 @@ export function DataTable({ } > {row.getVisibleCells().map((cell: any) => ( - + {flexRender( cell.column.columnDef.cell, cell.getContext()