add clear button to filter inputs in all systems and containers tables (#1447)

This commit is contained in:
henrygd
2025-11-19 17:58:58 -05:00
parent ca4988951f
commit 26d367b188
2 changed files with 44 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ import { Sheet, SheetTitle, SheetHeader, SheetContent, SheetDescription } from "
import { Dialog, DialogContent, DialogTitle } from "../ui/dialog" import { Dialog, DialogContent, DialogTitle } from "../ui/dialog"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
import { $allSystemsById } from "@/lib/stores" import { $allSystemsById } from "@/lib/stores"
import { MaximizeIcon, RefreshCwIcon } from "lucide-react" import { MaximizeIcon, RefreshCwIcon, XIcon } from "lucide-react"
import { Separator } from "../ui/separator" import { Separator } from "../ui/separator"
import { $router, Link } from "../router" import { $router, Link } from "../router"
import { listenKeys } from "nanostores" import { listenKeys } from "nanostores"
@@ -147,12 +147,26 @@ export default function ContainersTable({ systemId }: { systemId?: string }) {
<Trans>Click on a container to view more information.</Trans> <Trans>Click on a container to view more information.</Trans>
</CardDescription> </CardDescription>
</div> </div>
<Input <div className="relative ms-auto w-full max-w-full md:w-64">
placeholder={t`Filter...`} <Input
value={globalFilter} placeholder={t`Filter...`}
onChange={(e) => setGlobalFilter(e.target.value)} value={globalFilter}
className="ms-auto px-4 w-full max-w-full md:w-64" onChange={(e) => setGlobalFilter(e.target.value)}
/> className="ps-4 pe-10 w-full"
/>
{globalFilter && (
<Button
type="button"
variant="ghost"
size="icon"
aria-label={t`Clear filter`}
className="absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7 text-muted-foreground"
onClick={() => setGlobalFilter("")}
>
<XIcon className="h-4 w-4" />
</Button>
)}
</div>
</div> </div>
</CardHeader> </CardHeader>
<div className="rounded-md"> <div className="rounded-md">

View File

@@ -24,6 +24,7 @@ import {
LayoutGridIcon, LayoutGridIcon,
LayoutListIcon, LayoutListIcon,
Settings2Icon, Settings2Icon,
XIcon,
} from "lucide-react" } from "lucide-react"
import { memo, useEffect, useMemo, useRef, useState } from "react" import { memo, useEffect, useMemo, useRef, useState } from "react"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
@@ -60,7 +61,7 @@ export default function SystemsTable() {
const upSystems = $upSystems.get() const upSystems = $upSystems.get()
const pausedSystems = $pausedSystems.get() const pausedSystems = $pausedSystems.get()
const { i18n, t } = useLingui() const { i18n, t } = useLingui()
const [filter, setFilter] = useState<string>() const [filter, setFilter] = useState<string>("")
const [statusFilter, setStatusFilter] = useState<StatusFilter>("all") const [statusFilter, setStatusFilter] = useState<StatusFilter>("all")
const [sorting, setSorting] = useBrowserStorage<SortingState>( const [sorting, setSorting] = useBrowserStorage<SortingState>(
"sortMode", "sortMode",
@@ -145,7 +146,26 @@ export default function SystemsTable() {
</div> </div>
<div className="flex gap-2 ms-auto w-full md:w-80"> <div className="flex gap-2 ms-auto w-full md:w-80">
<Input placeholder={t`Filter...`} onChange={(e) => setFilter(e.target.value)} className="px-4" /> <div className="relative flex-1">
<Input
placeholder={t`Filter...`}
onChange={(e) => setFilter(e.target.value)}
value={filter}
className="ps-4 pe-10 w-full"
/>
{filter && (
<Button
type="button"
variant="ghost"
size="icon"
aria-label="Clear filter"
className="absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7 text-muted-foreground"
onClick={() => setFilter("")}
>
<XIcon className="h-4 w-4" />
</Button>
)}
</div>
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button variant="outline"> <Button variant="outline">
@@ -278,6 +298,7 @@ export default function SystemsTable() {
upSystemsLength, upSystemsLength,
downSystemsLength, downSystemsLength,
pausedSystemsLength, pausedSystemsLength,
filter,
]) ])
return ( return (