3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 import classNames from 'classnames';
21 import * as React from 'react';
22 import { DropdownOverlay } from '../../../../components/controls/Dropdown';
23 import SearchBox from '../../../../components/controls/SearchBox';
24 import Avatar from '../../../../components/ui/Avatar';
25 import DeferredSpinner from '../../../../components/ui/DeferredSpinner';
26 import { PopupPlacement } from '../../../../components/ui/popups';
27 import { translate } from '../../../../helpers/l10n';
28 import { UserActive } from '../../../../types/users';
29 import './AssigneeSelection.css';
31 export interface HotspotAssigneeSelectRendererProps {
32 highlighted?: UserActive;
34 onKeyDown: (event: React.KeyboardEvent) => void;
35 onSearch: (query: string) => void;
36 onSelect: (user?: UserActive) => void;
38 suggestedUsers?: UserActive[];
41 export default function AssigneeSelectionRenderer(props: HotspotAssigneeSelectRendererProps) {
42 const { highlighted, loading, query, suggestedUsers } = props;
45 <div className="dropdown">
46 <div className="display-flex-center">
49 onChange={props.onSearch}
50 onKeyDown={props.onKeyDown}
51 placeholder={translate('hotspots.assignee.select_user')}
54 {loading && <DeferredSpinner className="spacer-left" />}
58 <DropdownOverlay noPadding={true} placement={PopupPlacement.BottomLeft}>
59 <ul className="hotspot-assignee-search-results">
61 suggestedUsers.map((suggestion) => (
63 className={classNames('padded', {
64 active: highlighted && highlighted.login === suggestion.login,
66 key={suggestion.login}
67 onClick={() => props.onSelect(suggestion)}
69 {suggestion.login && (
71 className="spacer-right"
72 hash={suggestion.avatar}
73 name={suggestion.name}