MCPcopy Index your code
hub / github.com/bytebase/bytebase / UserSelect

Function UserSelect

frontend/src/react/components/UserSelect.tsx:29–122  ·  view source on GitHub ↗
({
  value,
  onChange,
  disabled,
  placeholder,
  className,
  includeAllUsers,
}: UserSelectProps)

Source from the content-addressed store, hash-verified

27}
28
29export function UserSelect({
30 value,
31 onChange,
32 disabled,
33 placeholder,
34 className,
35 includeAllUsers,
36}: UserSelectProps) {
37 const listUsers = useAppStore((state) => state.listUsers);
38 const getOrFetchUserByIdentifier = useAppStore(
39 (state) => state.getOrFetchUserByIdentifier
40 );
41 const [users, setUsers] = useState<User[]>([]);
42 const [selectedUser, setSelectedUser] = useState<User | undefined>(undefined);
43 const [search, setSearch] = useState("");
44 // Track the latest in-flight request to ignore stale responses when the
45 // user types quickly (a slow A can arrive after a fast B).
46 const searchSeqRef = useRef(0);
47
48 // Hydrate the selected user so its label renders even when it isn't in
49 // the current search results.
50 useEffect(() => {
51 if (!value) {
52 setSelectedUser(undefined);
53 return;
54 }
55 let cancelled = false;
56 getOrFetchUserByIdentifier({ identifier: value }).then((user) => {
57 if (!cancelled) setSelectedUser(user);
58 });
59 return () => {
60 cancelled = true;
61 };
62 }, [value, getOrFetchUserByIdentifier]);
63
64 const handleSearch = useCallback(
65 (query: string) => {
66 setSearch(query);
67 const seq = ++searchSeqRef.current;
68 listUsers({
69 pageSize: getDefaultPagination(),
70 filter: { query: query.trim() },
71 }).then(({ users: fetched }) => {
72 if (seq === searchSeqRef.current) setUsers(fetched);
73 });
74 },
75 [listUsers]
76 );
77
78 const options: ComboboxOption[] = useMemo(() => {
79 const list: ComboboxOption[] = [];
80 const seen = new Set<string>();
81 if (includeAllUsers) {
82 list.push({
83 value: `${userNamePrefix}${ALL_USERS_USER_EMAIL}`,
84 label: ALL_USERS_USER_EMAIL,
85 });
86 seen.add(`${userNamePrefix}${ALL_USERS_USER_EMAIL}`);

Callers

nothing calls this directly

Calls 5

getDefaultPaginationFunction · 0.90
isValidEmailFunction · 0.90
toOptionFunction · 0.85
addMethod · 0.80
useAppStoreFunction · 0.70

Tested by

no test coverage detected