1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-08 18:30:53 +00:00

replace code to user-select component (#3033)

This commit is contained in:
杨顺强
2019-03-04 15:53:12 +08:00
committed by Daniel Pan
parent 6ca920db64
commit 9498551ca2
6 changed files with 39 additions and 141 deletions

View File

@@ -1,9 +1,8 @@
import React, { Fragment } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import AsyncSelect from 'react-select/lib/Async';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import UserSelect from '../user-select';
const propTypes = {
toggle: PropTypes.func.isRequired,
@@ -19,39 +18,16 @@ class AddOrgAdminDialog extends React.Component {
this.options = [];
}
loadOptions = (value, callback) => {
if (value.trim().length > 0) {
seafileAPI.searchUsers(value.trim()).then((res) => {
this.options = [];
for (let i = 0 ; i < res.data.users.length; i++) {
let obj = {};
obj.value = res.data.users[i].name;
obj.email = res.data.users[i].email;
obj.label =
<Fragment>
<img src={res.data.users[i].avatar_url} className="select-module select-module-icon avatar" alt="Avatar"/>
<span className='select-module select-module-name'>{res.data.users[i].name}</span>
</Fragment>;
this.options.push(obj);
}
callback(this.options);
});
}
}
handleSelectChange = (option) => {
this.setState({selectedOption: option});
this.options = [];
}
addOrgAdmin = () => {
let users = [];
if (this.state.selectedOption && this.state.selectedOption.length > 0 ) {
for (let i = 0; i < this.state.selectedOption.length; i ++) {
users[i] = this.state.selectedOption[i].email;
}
if (this.state.selectedOption) {
let userEmail = this.state.selectedOption.email;
this.props.addOrgAdmin(userEmail)
}
this.props.addOrgAdmin(users)
}
toggle = () => {
@@ -63,18 +39,12 @@ class AddOrgAdminDialog extends React.Component {
<Modal isOpen={true}>
<ModalHeader>{gettext('Add Admins')}</ModalHeader>
<ModalBody>
<AsyncSelect
inputId={'react-select-1-input'}
className='reviewer-select'
<UserSelect
ref="userSelect"
isMulti={false}
className="reviewer-select"
placeholder={gettext('Select a user as admin...')}
loadOptions={this.loadOptions}
onChange={this.handleSelectChange}
value={this.state.selectedOption}
maxMenuHeight={200}
isMulti
isFocused
isClearable
classNamePrefix
onSelectChange={this.handleSelectChange}
/>
</ModalBody>
<ModalFooter>

View File

@@ -1,9 +1,9 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import AsyncSelect from 'react-select/lib/Async';
import { gettext, isPro } from '../../utils/constants';
import { Button } from 'reactstrap';
import { seafileAPI } from '../../utils/seafile-api.js';
import UserSelect from '../user-select';
import SharePermissionEditor from '../select-editor/share-permission-editor';
class UserItem extends React.Component {
@@ -90,12 +90,6 @@ const propTypes = {
repoID: PropTypes.string.isRequired
};
const NoOptionsMessage = (props) => {
return (
<div {...props.innerProps} style={{margin: '6px 10px', textAlign: 'center', color: 'hsl(0,0%,50%)'}}>{gettext('User not found')}</div>
);
};
class ShareToUser extends React.Component {
constructor(props) {
@@ -137,26 +131,6 @@ class ShareToUser extends React.Component {
this.setState({permission: permission});
}
loadOptions = (value, callback) => {
if (value.trim().length > 0) {
seafileAPI.searchUsers(value.trim()).then((res) => {
this.options = [];
for (let i = 0 ; i < res.data.users.length; i++) {
let obj = {};
obj.value = res.data.users[i].name;
obj.email = res.data.users[i].email;
obj.label =
<Fragment>
<img src={res.data.users[i].avatar_url} className="select-module select-module-icon avatar" alt="Avatar"/>
<span className='select-module select-module-name'>{res.data.users[i].name}</span>
</Fragment>;
this.options.push(obj);
}
callback(this.options);
});
}
}
shareToUser = () => {
let users = [];
let path = this.props.itemPath;
@@ -289,19 +263,12 @@ class ShareToUser extends React.Component {
<tbody>
<tr>
<td>
<AsyncSelect
inputId={'react-select-1-input'}
className='reviewer-select'
<UserSelect
ref="userSelect"
isMulti={true}
className="reviewer-select"
placeholder={gettext('Select users...')}
loadOptions={this.loadOptions}
onChange={this.handleSelectChange}
value={this.state.selectedOption}
components={{ NoOptionsMessage }}
maxMenuHeight={200}
isMulti
isFocused
isClearable
classNamePrefix
onSelectChange={this.handleSelectChange}
/>
</td>
<td>

View File

@@ -1,10 +1,10 @@
import React, { Fragment } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import AsyncSelect from 'react-select/lib/Async';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import toaster from '../toast';
import { gettext } from '../../utils/constants';
import { Button, Modal, ModalHeader, ModalBody } from 'reactstrap';
import { seafileAPI } from '../../utils/seafile-api.js';
import UserSelect from '../user-select';
const propTypes = {
itemName: PropTypes.string.isRequired,
@@ -29,26 +29,6 @@ class TransferDialog extends React.Component {
this.options = [];
}
loadOptions = (value, callback) => {
if (value.trim().length > 0) {
seafileAPI.searchUsers(value.trim()).then((res) => {
this.options = [];
for (let i = 0 ; i < res.data.users.length; i++) {
let obj = {};
obj.value = res.data.users[i].name;
obj.email = res.data.users[i].email;
obj.label =
<Fragment>
<img src={res.data.users[i].avatar_url} className="avatar reviewer-select-avatar" alt=""/>
<span className='reviewer-select-name'>{res.data.users[i].name}</span>
</Fragment>;
this.options.push(obj);
}
callback(this.options);
});
}
}
submit = () => {
let repoID = this.props.repoID;
let user = this.state.selectedOption.email;
@@ -74,16 +54,17 @@ class TransferDialog extends React.Component {
<div dangerouslySetInnerHTML={{__html:message}} />
</ModalHeader>
<ModalBody>
<AsyncSelect
className='reviewer-select' isFocused
loadOptions={this.loadOptions}
<UserSelect
ref="userSelect"
isMulti={false}
className="reviewer-select"
placeholder={gettext('Please enter 1 or more character')}
onChange={this.handleSelectChange}
isClearable classNamePrefix
inputId={'react-select-transfer-input'}
/><br />
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
onSelectChange={this.handleSelectChange}
/>
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}

View File

@@ -1,9 +1,9 @@
import React from 'react';
import AsyncSelect from 'react-select/lib/Async';
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api.js';
import UserSelect from '../user-select';
import '../../css/transfer-group-dialog.css';
@@ -32,26 +32,6 @@ class TransferGroupDialog extends React.Component {
this.options = [];
}
loadOptions = (value, callback) => {
if (value.trim().length > 0) {
seafileAPI.searchUsers(value.trim()).then((res) => {
this.options = [];
for (let i = 0 ; i < res.data.users.length; i++) {
let obj = {};
obj.value = res.data.users[i].name;
obj.email = res.data.users[i].email;
obj.label =
<React.Fragment>
<img src={res.data.users[i].avatar_url} className="avatar" alt=""/>
<span className="transfer-group-name">{res.data.users[i].name}</span>
</React.Fragment>;
this.options.push(obj);
}
callback(this.options);
});
}
}
transferGroup = () => {
const email = this.state.selectedOption && this.state.selectedOption.email;
if (email) {
@@ -77,12 +57,12 @@ class TransferGroupDialog extends React.Component {
<ModalHeader toggle={this.toggle}>{gettext('Transfer Group')}</ModalHeader>
<ModalBody>
<p>{gettext('Transfer group to')}</p>
<AsyncSelect
className='group-transfer-select'
isClearable classNamePrefix
loadOptions={this.loadOptions}
onChange={this.handleSelectChange}
<UserSelect
ref="userSelect"
isMulti={false}
className="reviewer-select"
placeholder={gettext('Please enter 1 or more character')}
onSelectChange={this.handleSelectChange}
/>
<div className="error">{this.state.errMessage}</div>
</ModalBody>