MCPcopy Create free account
hub / github.com/coder/coder / UsersCombobox

Function UsersCombobox

site/src/pages/TasksPage/UsersCombobox.tsx:40–117  ·  view source on GitHub ↗
({
	value,
	onValueChange,
})

Source from the content-addressed store, hash-verified

38};
39
40export const UsersCombobox: FC<UsersComboboxProps> = ({
41 value,
42 onValueChange,
43}) => {
44 const [open, setOpen] = useState(false);
45 const [search, setSearch] = useState("");
46 const debouncedSearch = useDebouncedValue(search, 250);
47 const { user } = useAuthenticated();
48 const { data: options } = useQuery({
49 ...users({ q: debouncedSearch ? `name:"${debouncedSearch}"` : "" }),
50 select: (res) => mapUsersToOptions(res.users, user, value),
51 placeholderData: keepPreviousData,
52 });
53 const selectedOption = options?.find((o) => o.value === value);
54
55 return (
56 <Popover open={open} onOpenChange={setOpen}>
57 <PopoverTrigger asChild>
58 <Button
59 disabled={!options}
60 variant="outline"
61 role="combobox"
62 aria-expanded={open}
63 className="w-[280px] justify-between"
64 >
65 {options ? (
66 selectedOption ? (
67 <UserItem option={selectedOption} className="-ml-1" />
68 ) : (
69 "Select user..."
70 )
71 ) : (
72 <Skeleton variant="text" className="w-[120px] h-3" />
73 )}
74 <ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
75 </Button>
76 </PopoverTrigger>
77 <PopoverContent className="w-[280px] p-0">
78 {/*
79 * `shouldFilter` is false because we don't want to filter on the `value`
80 * because we're using the `name` field to filter on the backend.
81 */}
82 <Command shouldFilter={false}>
83 <CommandInput
84 placeholder="Search user..."
85 value={search}
86 onValueChange={setSearch}
87 />
88 <CommandList>
89 <CommandEmpty>No users found.</CommandEmpty>
90 <CommandGroup>
91 {options?.map((option) => (
92 <CommandItem
93 key={option.value}
94 value={option.value}
95 onSelect={() => {
96 onValueChange(option.value);
97 setOpen(false);

Callers

nothing calls this directly

Calls 6

useDebouncedValueFunction · 0.90
useAuthenticatedFunction · 0.90
usersFunction · 0.90
cnFunction · 0.90
findMethod · 0.80
mapUsersToOptionsFunction · 0.70

Tested by

no test coverage detected