mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-03 07:55:36 +00:00
ADD: repo-api-tokens GET POST PUT and access via-repo-token/dir and v… (#4136)
* ADD: repo-api-tokens GET POST PUT and access via-repo-token/dir and via-repo-token/upload-link by repo-api-token * MOD: POST /via-api-token/dir logic * MOD: check app and token when POST /repo-api-tokens * MOD: use seafile_api.get_dir_id_by_path in via_repo_token for list dirs
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import React, { Fragment } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Select from 'react-select';
|
||||
import { gettext } from '../../utils/constants';
|
||||
|
||||
const propTypes = {
|
||||
isTextMode: PropTypes.bool.isRequired,
|
||||
isEditIconShow: PropTypes.bool.isRequired,
|
||||
currentPermission: PropTypes.string.isRequired,
|
||||
onPermissionChanged: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class RepoAPITokenPermissionEditor extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isEditing: false,
|
||||
};
|
||||
this.options = [
|
||||
{ value: 'rw', label: <div>{gettext('Read-Write')}</div> },
|
||||
{ value: 'r', label: <div>{gettext('Read-Only')}</div> }
|
||||
];
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
document.addEventListener('click', this.onHideSelect);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
document.removeEventListener('click', this.onHideSelect);
|
||||
}
|
||||
|
||||
onHideSelect = () => {
|
||||
this.setState({ isEditing: false });
|
||||
}
|
||||
|
||||
onEditPermission = (e) => {
|
||||
e.nativeEvent.stopImmediatePropagation();
|
||||
this.setState({ isEditing: true });
|
||||
}
|
||||
|
||||
onPermissionChanged = (e) => {
|
||||
if (e.value !== this.props.currentPermission) {
|
||||
this.props.onPermissionChanged(e.value);
|
||||
}
|
||||
this.setState({ isEditing: false });
|
||||
}
|
||||
|
||||
onSelectHandler = (e) => {
|
||||
e.nativeEvent.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { currentPermission, isTextMode } = this.props;
|
||||
let optionTranslation = currentPermission === 'rw' ? gettext('Read-Write') : gettext('Read-Only');
|
||||
return (
|
||||
<div onClick={this.onSelectHandler}>
|
||||
{(isTextMode && !this.state.isEditing) ?
|
||||
<Fragment>
|
||||
<span>{optionTranslation}</span>
|
||||
{this.props.isEditIconShow &&
|
||||
<span title={gettext('Edit')} className="fa fa-pencil-alt attr-action-icon" onClick={this.onEditPermission}/>
|
||||
}
|
||||
</Fragment>
|
||||
:
|
||||
<Select
|
||||
options={this.options}
|
||||
placeholder={optionTranslation}
|
||||
onChange={this.onPermissionChanged}
|
||||
captureMenuScroll={false}
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
RepoAPITokenPermissionEditor.propTypes = propTypes;
|
||||
|
||||
export default RepoAPITokenPermissionEditor;
|
Reference in New Issue
Block a user