From e04888ff4d31957b4672d591b83147b63c85bc55 Mon Sep 17 00:00:00 2001 From: codex-bot Date: Tue, 21 Oct 2025 09:52:36 -0300 Subject: [PATCH] Machines: replace OS filter with searchable company dropdown; remove OS filter logic --- .../machines/admin-machines-overview.tsx | 99 +++++++++---------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/src/components/admin/machines/admin-machines-overview.tsx b/src/components/admin/machines/admin-machines-overview.tsx index 95930a4..3a519e3 100644 --- a/src/components/admin/machines/admin-machines-overview.tsx +++ b/src/components/admin/machines/admin-machines-overview.tsx @@ -37,6 +37,7 @@ import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { Checkbox } from "@/components/ui/checkbox" import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" @@ -972,8 +973,8 @@ export function AdminMachinesOverview({ tenantId }: { tenantId: string }) { const machines = useMachinesQuery(tenantId) const [q, setQ] = useState("") const [statusFilter, setStatusFilter] = useState("all") - const [osFilter, setOsFilter] = useState("all") - const [companyQuery, setCompanyQuery] = useState("") + const [companyFilterSlug, setCompanyFilterSlug] = useState("all") + const [companySearch, setCompanySearch] = useState("") const [onlyAlerts, setOnlyAlerts] = useState(false) const { convexUserId } = useAuth() const companies = useQuery( @@ -986,13 +987,7 @@ export function AdminMachinesOverview({ tenantId }: { tenantId: string }) { return map }, [companies]) - const osOptions = useMemo(() => { - const set = new Set() - machines.forEach((m) => m.osName && set.add(m.osName)) - return Array.from(set).sort() - }, [machines]) - - const companyNameOptions = useMemo(() => (companies ?? []).map((c) => c.name).sort((a,b)=>a.localeCompare(b,"pt-BR")), [companies]) + const companyOptions = useMemo(() => (companies ?? []).map((c) => ({ slug: c.slug ?? c.id, name: c.name })).sort((a,b)=>a.name.localeCompare(b.name,"pt-BR")), [companies]) const filteredMachines = useMemo(() => { const text = q.trim().toLowerCase() @@ -1002,11 +997,7 @@ const filteredMachines = useMemo(() => { const s = resolveMachineStatus(m).toLowerCase() if (s !== statusFilter) return false } - if (osFilter !== "all" && (m.osName ?? "").toLowerCase() !== osFilter.toLowerCase()) return false - if (companyQuery && companyQuery.trim().length > 0) { - const name = companyNameBySlug.get(m.companySlug ?? "")?.toLowerCase() ?? "" - if (!name.includes(companyQuery.trim().toLowerCase())) return false - } + if (companyFilterSlug !== "all" && (m.companySlug ?? "") !== companyFilterSlug) return false if (!text) return true const hay = [ m.hostname, @@ -1018,7 +1009,7 @@ const filteredMachines = useMemo(() => { .toLowerCase() return hay.includes(text) }) - }, [machines, q, statusFilter, osFilter, companyQuery, onlyAlerts, companyNameBySlug]) + }, [machines, q, statusFilter, companyFilterSlug, onlyAlerts]) return (
@@ -1044,47 +1035,53 @@ const filteredMachines = useMemo(() => { Desconhecido - -
- setCompanyQuery(e.target.value)} - placeholder="Buscar empresa" - className="min-w-[220px]" - /> - {companyQuery && companyNameOptions.filter((c) => c.toLowerCase().includes(companyQuery.toLowerCase())).slice(0,6).length > 0 ? ( -
- {companyNameOptions - .filter((c) => c.toLowerCase().includes(companyQuery.toLowerCase())) - .slice(0, 8) - .map((c) => ( - - ))} + + + + + +
+ setCompanySearch(e.target.value)} + placeholder="Buscar empresa..." + /> +
+ + {companyOptions + .filter((c) => c.name.toLowerCase().includes(companySearch.toLowerCase())) + .map((c) => ( + + ))} +
- ) : null} -
+ + - +
{machines.length === 0 ? (