mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
replace code to user-select component (#3033)
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import React, { Fragment } from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import AsyncSelect from 'react-select/lib/Async';
|
|
||||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||||
import { gettext } from '../../utils/constants';
|
import { gettext } from '../../utils/constants';
|
||||||
import { seafileAPI } from '../../utils/seafile-api';
|
import UserSelect from '../user-select';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
toggle: PropTypes.func.isRequired,
|
toggle: PropTypes.func.isRequired,
|
||||||
@@ -19,40 +18,17 @@ class AddOrgAdminDialog extends React.Component {
|
|||||||
this.options = [];
|
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) => {
|
handleSelectChange = (option) => {
|
||||||
this.setState({selectedOption: option});
|
this.setState({selectedOption: option});
|
||||||
this.options = [];
|
this.options = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
addOrgAdmin = () => {
|
addOrgAdmin = () => {
|
||||||
let users = [];
|
if (this.state.selectedOption) {
|
||||||
if (this.state.selectedOption && this.state.selectedOption.length > 0 ) {
|
let userEmail = this.state.selectedOption.email;
|
||||||
for (let i = 0; i < this.state.selectedOption.length; i ++) {
|
this.props.addOrgAdmin(userEmail)
|
||||||
users[i] = this.state.selectedOption[i].email;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.props.addOrgAdmin(users)
|
|
||||||
}
|
|
||||||
|
|
||||||
toggle = () => {
|
toggle = () => {
|
||||||
this.props.toggle();
|
this.props.toggle();
|
||||||
@@ -63,18 +39,12 @@ class AddOrgAdminDialog extends React.Component {
|
|||||||
<Modal isOpen={true}>
|
<Modal isOpen={true}>
|
||||||
<ModalHeader>{gettext('Add Admins')}</ModalHeader>
|
<ModalHeader>{gettext('Add Admins')}</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<AsyncSelect
|
<UserSelect
|
||||||
inputId={'react-select-1-input'}
|
ref="userSelect"
|
||||||
className='reviewer-select'
|
isMulti={false}
|
||||||
|
className="reviewer-select"
|
||||||
placeholder={gettext('Select a user as admin...')}
|
placeholder={gettext('Select a user as admin...')}
|
||||||
loadOptions={this.loadOptions}
|
onSelectChange={this.handleSelectChange}
|
||||||
onChange={this.handleSelectChange}
|
|
||||||
value={this.state.selectedOption}
|
|
||||||
maxMenuHeight={200}
|
|
||||||
isMulti
|
|
||||||
isFocused
|
|
||||||
isClearable
|
|
||||||
classNamePrefix
|
|
||||||
/>
|
/>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import AsyncSelect from 'react-select/lib/Async';
|
|
||||||
import { gettext, isPro } from '../../utils/constants';
|
import { gettext, isPro } from '../../utils/constants';
|
||||||
import { Button } from 'reactstrap';
|
import { Button } from 'reactstrap';
|
||||||
import { seafileAPI } from '../../utils/seafile-api.js';
|
import { seafileAPI } from '../../utils/seafile-api.js';
|
||||||
|
import UserSelect from '../user-select';
|
||||||
import SharePermissionEditor from '../select-editor/share-permission-editor';
|
import SharePermissionEditor from '../select-editor/share-permission-editor';
|
||||||
|
|
||||||
class UserItem extends React.Component {
|
class UserItem extends React.Component {
|
||||||
@@ -90,12 +90,6 @@ const propTypes = {
|
|||||||
repoID: PropTypes.string.isRequired
|
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 {
|
class ShareToUser extends React.Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -137,26 +131,6 @@ class ShareToUser extends React.Component {
|
|||||||
this.setState({permission: permission});
|
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 = () => {
|
shareToUser = () => {
|
||||||
let users = [];
|
let users = [];
|
||||||
let path = this.props.itemPath;
|
let path = this.props.itemPath;
|
||||||
@@ -289,19 +263,12 @@ class ShareToUser extends React.Component {
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<AsyncSelect
|
<UserSelect
|
||||||
inputId={'react-select-1-input'}
|
ref="userSelect"
|
||||||
className='reviewer-select'
|
isMulti={true}
|
||||||
|
className="reviewer-select"
|
||||||
placeholder={gettext('Select users...')}
|
placeholder={gettext('Select users...')}
|
||||||
loadOptions={this.loadOptions}
|
onSelectChange={this.handleSelectChange}
|
||||||
onChange={this.handleSelectChange}
|
|
||||||
value={this.state.selectedOption}
|
|
||||||
components={{ NoOptionsMessage }}
|
|
||||||
maxMenuHeight={200}
|
|
||||||
isMulti
|
|
||||||
isFocused
|
|
||||||
isClearable
|
|
||||||
classNamePrefix
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import React, { Fragment } from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
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 toaster from '../toast';
|
||||||
import { gettext } from '../../utils/constants';
|
import { gettext } from '../../utils/constants';
|
||||||
import { Button, Modal, ModalHeader, ModalBody } from 'reactstrap';
|
|
||||||
import { seafileAPI } from '../../utils/seafile-api.js';
|
import { seafileAPI } from '../../utils/seafile-api.js';
|
||||||
|
import UserSelect from '../user-select';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
itemName: PropTypes.string.isRequired,
|
itemName: PropTypes.string.isRequired,
|
||||||
@@ -29,26 +29,6 @@ class TransferDialog extends React.Component {
|
|||||||
this.options = [];
|
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 = () => {
|
submit = () => {
|
||||||
let repoID = this.props.repoID;
|
let repoID = this.props.repoID;
|
||||||
let user = this.state.selectedOption.email;
|
let user = this.state.selectedOption.email;
|
||||||
@@ -74,16 +54,17 @@ class TransferDialog extends React.Component {
|
|||||||
<div dangerouslySetInnerHTML={{__html:message}} />
|
<div dangerouslySetInnerHTML={{__html:message}} />
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<AsyncSelect
|
<UserSelect
|
||||||
className='reviewer-select' isFocused
|
ref="userSelect"
|
||||||
loadOptions={this.loadOptions}
|
isMulti={false}
|
||||||
|
className="reviewer-select"
|
||||||
placeholder={gettext('Please enter 1 or more character')}
|
placeholder={gettext('Please enter 1 or more character')}
|
||||||
onChange={this.handleSelectChange}
|
onSelectChange={this.handleSelectChange}
|
||||||
isClearable classNamePrefix
|
/>
|
||||||
inputId={'react-select-transfer-input'}
|
|
||||||
/><br />
|
|
||||||
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
|
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
|
||||||
|
</ModalFooter>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import AsyncSelect from 'react-select/lib/Async';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { gettext } from '../../utils/constants';
|
|
||||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||||
|
import { gettext } from '../../utils/constants';
|
||||||
import { seafileAPI } from '../../utils/seafile-api.js';
|
import { seafileAPI } from '../../utils/seafile-api.js';
|
||||||
|
import UserSelect from '../user-select';
|
||||||
|
|
||||||
import '../../css/transfer-group-dialog.css';
|
import '../../css/transfer-group-dialog.css';
|
||||||
|
|
||||||
@@ -32,26 +32,6 @@ class TransferGroupDialog extends React.Component {
|
|||||||
this.options = [];
|
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 = () => {
|
transferGroup = () => {
|
||||||
const email = this.state.selectedOption && this.state.selectedOption.email;
|
const email = this.state.selectedOption && this.state.selectedOption.email;
|
||||||
if (email) {
|
if (email) {
|
||||||
@@ -77,12 +57,12 @@ class TransferGroupDialog extends React.Component {
|
|||||||
<ModalHeader toggle={this.toggle}>{gettext('Transfer Group')}</ModalHeader>
|
<ModalHeader toggle={this.toggle}>{gettext('Transfer Group')}</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p>{gettext('Transfer group to')}</p>
|
<p>{gettext('Transfer group to')}</p>
|
||||||
<AsyncSelect
|
<UserSelect
|
||||||
className='group-transfer-select'
|
ref="userSelect"
|
||||||
isClearable classNamePrefix
|
isMulti={false}
|
||||||
loadOptions={this.loadOptions}
|
className="reviewer-select"
|
||||||
onChange={this.handleSelectChange}
|
|
||||||
placeholder={gettext('Please enter 1 or more character')}
|
placeholder={gettext('Please enter 1 or more character')}
|
||||||
|
onSelectChange={this.handleSelectChange}
|
||||||
/>
|
/>
|
||||||
<div className="error">{this.state.errMessage}</div>
|
<div className="error">{this.state.errMessage}</div>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
|
@@ -8,7 +8,7 @@ const propTypes = {
|
|||||||
placeholder: PropTypes.string.isRequired,
|
placeholder: PropTypes.string.isRequired,
|
||||||
onSelectChange: PropTypes.func.isRequired,
|
onSelectChange: PropTypes.func.isRequired,
|
||||||
isMulti: PropTypes.bool.isRequired,
|
isMulti: PropTypes.bool.isRequired,
|
||||||
className: PropTypes.string.isRequired,
|
className: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const NoOptionsMessage = (props) => {
|
const NoOptionsMessage = (props) => {
|
||||||
@@ -65,7 +65,7 @@ class UserSelect extends React.Component {
|
|||||||
loadOptions={this.loadOptions}
|
loadOptions={this.loadOptions}
|
||||||
onChange={this.handleSelectChange}
|
onChange={this.handleSelectChange}
|
||||||
placeholder={this.props.placeholder}
|
placeholder={this.props.placeholder}
|
||||||
className={this.props.className}
|
className={`user-select ${this.props.className}`}
|
||||||
ref="userSelect"
|
ref="userSelect"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@@ -65,8 +65,8 @@ class OrgAdminList extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addOrgAdmin = (users) => {
|
addOrgAdmin = (userEmail) => {
|
||||||
seafileAPI.setOrgAdmin(orgID, users, true).then(res => {
|
seafileAPI.setOrgAdmin(orgID, userEmail, true).then(res => {
|
||||||
let userInfo = new OrgUserInfo(res.data);
|
let userInfo = new OrgUserInfo(res.data);
|
||||||
this.state.orgAdminUsers.unshift(userInfo);
|
this.state.orgAdminUsers.unshift(userInfo);
|
||||||
this.setState({
|
this.setState({
|
||||||
|
Reference in New Issue
Block a user