From 95cbaaae213c45a6cdf81cff1639f41242c24c00 Mon Sep 17 00:00:00 2001 From: Fred KISSIE Date: Sat, 25 Apr 2026 04:47:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20new=20multi=20select=20tag=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/machines-selector.tsx | 62 ++++++------------- .../multi-select/multi-select-input.tsx | 51 +++++++++++---- 2 files changed, 58 insertions(+), 55 deletions(-) diff --git a/src/components/machines-selector.tsx b/src/components/machines-selector.tsx index d4aef49d6..8c4757fd0 100644 --- a/src/components/machines-selector.tsx +++ b/src/components/machines-selector.tsx @@ -5,10 +5,7 @@ import { useMemo, useState } from "react"; import { useDebounce } from "use-debounce"; import { useTranslations } from "next-intl"; -import { - SuggestionsTagInput, - type SuggestionsTagInputProps -} from "./tags/suggestions-tag-input"; +import { MultiSelectInput } from "./multi-select/multi-select-input"; export type SelectedMachine = Pick< ListClientsResponse["clients"][number], @@ -19,22 +16,12 @@ export type MachineSelectorProps = { orgId: string; selectedMachines?: SelectedMachine[]; onSelectMachines: (machine: SelectedMachine[]) => void; -} & Omit< - SuggestionsTagInputProps, - | "tags" - | "setTags" - | "suggestedOptions" - | "searchQuery" - | "onSearchQueryChange" - | "activeTagIndex" - | "setActiveTagIndex" ->; +}; export function MachinesSelector({ orgId, selectedMachines = [], - onSelectMachines, - ...props + onSelectMachines }: MachineSelectorProps) { const t = useTranslations(); const [machineSearchQuery, setMachineSearchQuery] = useState(""); @@ -60,42 +47,29 @@ export function MachinesSelector({ return allMachines; }, [machines, selectedMachines, debouncedValue]); - const [activeTagIndex, setActiveTagIndex] = useState(null); - return ( - ({ + ({ id: mc.clientId.toString(), text: mc.name }))} - setTags={(newTags) => { - const tags = - typeof newTags === "function" - ? newTags( - selectedMachines.map((mc) => ({ - id: mc.clientId.toString(), - text: mc.name - })) - ) - : newTags; + value={selectedMachines.map((mc) => ({ + id: mc.clientId.toString(), + text: mc.name + }))} + onChange={(newValues) => { onSelectMachines( - tags.map((tag) => ({ - clientId: Number(tag.id), - name: tag.text + newValues.map((v) => ({ + clientId: Number(v.id), + name: v.text })) ); }} - searchQuery={machineSearchQuery} - onSearchQueryChange={setMachineSearchQuery} - suggestedOptions={machinesShown.map((mc) => ({ - id: mc.clientId.toString(), - text: mc.name - }))} - allowDuplicates={false} /> ); } diff --git a/src/components/multi-select/multi-select-input.tsx b/src/components/multi-select/multi-select-input.tsx index d0d8e2873..4f4fec528 100644 --- a/src/components/multi-select/multi-select-input.tsx +++ b/src/components/multi-select/multi-select-input.tsx @@ -3,14 +3,15 @@ import { PopoverContent, PopoverTrigger } from "@app/components/ui/popover"; -import { Button } from "@app/components/ui/button"; +import { Button, buttonVariants } from "@app/components/ui/button"; import { cn } from "@app/lib/cn"; -import { ChevronDownIcon } from "lucide-react"; +import { ChevronDownIcon, XIcon } from "lucide-react"; import { type TagValue, type MultiSelectTagsProps, MultiSelectTags } from "./multi-select-tags"; +import { useState } from "react"; export interface MultiSelectInputProps< T extends TagValue @@ -22,13 +23,20 @@ export function MultiSelectInput({ buttonText, ...props }: MultiSelectInputProps) { + const selectedValues = new Set(props.value.map((v) => v.id)); + return ( - +
({ "overflow-x-auto" )} > - {/* {(field.value ?? []).map((client) => ( + {props.value.map((option) => ( e.stopPropagation()} > - {client.name} + {option.text} + - ))} */} + ))} {buttonText} - +