MCPcopy Index your code
hub / github.com/coder/coder / UserCombobox

Function UserCombobox

site/src/modules/tasks/TasksSidebar/UserCombobox.tsx:39–122  ·  view source on GitHub ↗
({
	value,
	onValueChange,
})

Source from the content-addressed store, hash-verified

37};
38
39export const UserCombobox: FC<UserComboboxProps> = ({
40 value,
41 onValueChange,
42}) => {
43 const [open, setOpen] = useState(false);
44 const [search, setSearch] = useState("");
45 const debouncedSearch = useDebouncedValue(search, 250);
46 // By default, this combobox filters by the authenticated user.
47 // To ensure consistent behavior, we must always include the
48 // authenticated user in the list of options.
49 const { user } = useAuthenticated();
50 const { data: options, isFetched } = useQuery({
51 ...users({ q: debouncedSearch }),
52 select: (res) => mapUsersToOptions(res.users, user, value),
53 placeholderData: keepPreviousData,
54 });
55 const selectedOption = options?.find((o) => o.value === value);
56
57 return (
58 <Popover open={open} onOpenChange={setOpen}>
59 <PopoverTrigger asChild>
60 <Button
61 disabled={!isFetched}
62 role="combobox"
63 aria-expanded={open}
64 className="justify-between rounded-full bg-surface-tertiary border border-border hover:bg-surface-quaternary text-content-primary pl-3 w-fit"
65 size="sm"
66 >
67 {isFetched ? (
68 selectedOption ? (
69 <UserItem option={selectedOption} className="-ml-2" />
70 ) : (
71 "All users"
72 )
73 ) : (
74 "Loading users..."
75 )}
76
77 <ChevronsUpDownIcon className="shrink-0 opacity-50" />
78 </Button>
79 </PopoverTrigger>
80 <PopoverContent
81 className="flex flex-col w-[280px] p-0"
82 side="bottom"
83 align="start"
84 >
85 <Command className="flex-1 min-h-0">
86 <CommandInput
87 placeholder="Search user..."
88 value={search}
89 onValueChange={setSearch}
90 aria-label="Search user"
91 />
92 <CommandList className="flex-1 min-h-0 max-h-none">
93 <CommandEmpty>No users found.</CommandEmpty>
94 <CommandGroup>
95 {options?.map((option) => (
96 <CommandItem

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