1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +00:00

Optimized module code (#2574)

This commit is contained in:
杨顺强
2018-11-28 12:41:49 +08:00
committed by Daniel Pan
parent 330407be0b
commit 09f32f2312
21 changed files with 120 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { serviceUrl, gettext, repoID } from '../../utils/constants';
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import URLDecorator from '../../utils/url-decorator';
import Toast from '../toast';
@@ -13,6 +13,8 @@ import CopyDirentDialog from '../dialog/copy-dirent-dialog';
const propTypes = {
path: PropTypes.string.isRequired,
repoID: PropTypes.string.isRequired,
serviceUrl: PropTypes.string.isRequired,
isItemFreezed: PropTypes.bool.isRequired,
dirent: PropTypes.object.isRequired,
onItemClick: PropTypes.func.isRequired,
@@ -123,6 +125,7 @@ class DirentListItem extends React.Component {
onItemStarred = () => {
let dirent = this.props.dirent;
let repoID = this.props.repoID;
let filePath = this.getDirentPath(dirent);
if (dirent.starred) {
seafileAPI.unStarFile(repoID, filePath).then(() => {
@@ -247,6 +250,7 @@ class DirentListItem extends React.Component {
}
onLockItem = () => {
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
seafileAPI.lockfile(repoID, filePath).then(() => {
this.props.updateDirent(this.props.dirent, 'is_locked', true);
@@ -256,6 +260,7 @@ class DirentListItem extends React.Component {
}
onUnlockItem = () => {
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
seafileAPI.unlockfile(repoID, filePath).then(() => {
this.props.updateDirent(this.props.dirent, 'is_locked', false);
@@ -265,6 +270,7 @@ class DirentListItem extends React.Component {
}
onNewDraft = () => {
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
seafileAPI.createDraft(repoID, filePath).then(res => {
let draft_file_Path = res.data.draft_file_path;
@@ -283,6 +289,7 @@ class DirentListItem extends React.Component {
}
onHistory = () => {
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
let referer = location.href;
let url = URLDecorator.getUrl({type: 'file_revisions', repoID: repoID, filePath: filePath, referer: referer});
@@ -295,6 +302,7 @@ class DirentListItem extends React.Component {
}
onOpenViaClient = () => {
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
let url = URLDecorator.getUrl({type: 'open_via_client', repoID: repoID, filePath: filePath});
location.href = url;
@@ -304,6 +312,7 @@ class DirentListItem extends React.Component {
onItemDownload = (e) => {
e.nativeEvent.stopImmediatePropagation();
let dirent = this.props.dirent;
let repoID = this.props.repoID;
let direntPath = this.getDirentPath(dirent);
if (dirent.type === 'dir') {
this.setState({isProgressDialogShow: true, progress: 0});
@@ -359,7 +368,7 @@ class DirentListItem extends React.Component {
}
render() {
let { dirent } = this.props;
let { dirent, serviceUrl } = this.props;
return (
<Fragment>
<tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseEnter={this.onMouseEnter} onMouseOver={this.onMouseOver} onMouseLeave={this.onMouseLeave}>
@@ -429,6 +438,7 @@ class DirentListItem extends React.Component {
<ModalPortal>
<MoveDirentDialog
path={this.props.path}
repoID={this.props.repoID}
dirent={this.props.dirent}
isMutipleOperation={this.state.isMutipleOperation}
onItemMove={this.props.onItemMove}
@@ -440,6 +450,7 @@ class DirentListItem extends React.Component {
<ModalPortal>
<CopyDirentDialog
path={this.props.path}
repoID={this.props.repoID}
dirent={this.props.dirent}
isMutipleOperation={this.state.isMutipleOperation}
onItemCopy={this.props.onItemCopy}