|
|
@@ -1,13 +1,15 @@
|
|
|
import React, { Component } from 'react';
|
|
|
-import Select from 'react-select';
|
|
|
+import AsyncSelect from 'react-select/lib/Async';
|
|
|
import PickerOption from './PickerOption';
|
|
|
import { debounce } from 'lodash';
|
|
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
|
import { User } from 'app/types';
|
|
|
+import ResetStyles from './ResetStyles';
|
|
|
+import IndicatorsContainer from './IndicatorsContainer';
|
|
|
+import NoOptionsMessage from './NoOptionsMessage';
|
|
|
|
|
|
export interface Props {
|
|
|
onSelected: (user: User) => void;
|
|
|
- value?: string;
|
|
|
className?: string;
|
|
|
}
|
|
|
|
|
|
@@ -31,20 +33,17 @@ export class UserPicker extends Component<Props, State> {
|
|
|
|
|
|
search(query?: string) {
|
|
|
const backendSrv = getBackendSrv();
|
|
|
-
|
|
|
this.setState({ isLoading: true });
|
|
|
|
|
|
return backendSrv
|
|
|
- .get(`/api/org/users?query=${query}&limit=10`)
|
|
|
+ .get(`/api/org/users?query=${query}&limit=1`)
|
|
|
.then(result => {
|
|
|
- return {
|
|
|
- options: result.map(user => ({
|
|
|
- id: user.userId,
|
|
|
- label: `${user.login} - ${user.email}`,
|
|
|
- avatarUrl: user.avatarUrl,
|
|
|
- login: user.login,
|
|
|
- })),
|
|
|
- };
|
|
|
+ return result.map(user => ({
|
|
|
+ id: user.userId,
|
|
|
+ label: `${user.login} - ${user.email}`,
|
|
|
+ avatarUrl: user.avatarUrl,
|
|
|
+ login: user.login,
|
|
|
+ }));
|
|
|
})
|
|
|
.finally(() => {
|
|
|
this.setState({ isLoading: false });
|
|
|
@@ -52,26 +51,31 @@ export class UserPicker extends Component<Props, State> {
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- const { value, className } = this.props;
|
|
|
+ const { className, onSelected } = this.props;
|
|
|
const { isLoading } = this.state;
|
|
|
|
|
|
return (
|
|
|
<div className="user-picker">
|
|
|
- <Select.Async
|
|
|
- valueKey="id"
|
|
|
- multi={false}
|
|
|
- labelKey="label"
|
|
|
- cache={false}
|
|
|
+ <AsyncSelect
|
|
|
+ classNamePrefix={`gf-form-select2`}
|
|
|
+ isMulti={false}
|
|
|
isLoading={isLoading}
|
|
|
+ defaultOptions={true}
|
|
|
loadOptions={this.debouncedSearch}
|
|
|
- loadingPlaceholder="Loading..."
|
|
|
- noResultsText="No users found"
|
|
|
- onChange={this.props.onSelected}
|
|
|
+ onChange={onSelected}
|
|
|
className={`gf-form-input gf-form-input--form-dropdown ${className || ''}`}
|
|
|
- optionComponent={PickerOption}
|
|
|
+ styles={ResetStyles}
|
|
|
+ components={{
|
|
|
+ Option: PickerOption,
|
|
|
+ IndicatorsContainer,
|
|
|
+ NoOptionsMessage,
|
|
|
+ }}
|
|
|
placeholder="Select user"
|
|
|
- value={value}
|
|
|
- autosize={true}
|
|
|
+ loadingMessage={() => 'Loading...'}
|
|
|
+ noOptionsMessage={() => 'No users found'}
|
|
|
+ getOptionValue={i => i.id}
|
|
|
+ getOptionLabel={i => i.label}
|
|
|
+ // menuIsOpen={true}
|
|
|
/>
|
|
|
</div>
|
|
|
);
|