From b79894cb729b89a82ff047978c41ad4368d36a33 Mon Sep 17 00:00:00 2001 From: zxj96 <519213124@qq.com> Date: Thu, 25 Apr 2019 18:28:52 +0800 Subject: [PATCH] optimization code --- .../components/dirent-list-view/dirent-list-item.js | 13 +------------ .../toolbar/mutilple-dir-operation-toolbar.js | 9 ++++----- .../src/components/toolbar/view-file-toolbar.js | 3 ++- .../pages/lib-content-view/lib-content-toolbar.js | 2 ++ 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/dirent-list-view/dirent-list-item.js b/frontend/src/components/dirent-list-view/dirent-list-item.js index dfc2c0995e..999ef4faa5 100644 --- a/frontend/src/components/dirent-list-view/dirent-list-item.js +++ b/frontend/src/components/dirent-list-view/dirent-list-item.js @@ -413,18 +413,7 @@ class DirentListItem extends React.Component { return ''; } - let isShowShareBtn = false; - if (this.props.showShareBtn) { - if (canGenerateShareLink) { - isShowShareBtn = true; - } else { - if (dirent.type === 'dir') { - isShowShareBtn = true; - } else { - isShowShareBtn = false; - } - } - } + let isShowShareBtn = (dirent.type === 'dir' && this.props.isShowShareBtn) || canGenerateShareLink; return ( diff --git a/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js b/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js index 6b5227d692..9856178cb2 100644 --- a/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js +++ b/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js @@ -32,6 +32,7 @@ const propTypes = { onFilesTagChanged: PropTypes.func.isRequired, unSelectDirent: PropTypes.func.isRequired, updateDirent: PropTypes.func.isRequired, + showShareBtn: PropTypes.bool.isRequired, }; class MutipleDirOperationToolbar extends React.Component { @@ -92,18 +93,16 @@ class MutipleDirOperationToolbar extends React.Component { const { SHARE, TAGS, RELATED_FILES, HISTORY, OPEN_VIA_CLIENT, LOCK, UNLOCK } = TextTranslation; - let shareBtn = currentRepoInfo.encrypted ? [] : [SHARE]; if (dirent.type === 'dir') { + let shareBtn = this.props.showShareBtn ? [SHARE] : [] menuList = [...shareBtn]; return menuList; } if (dirent.type === 'file') { - if (!currentRepoInfo.encrypted) { - shareBtn = canGenerateShareLink ? [SHARE] : []; - } - + let shareBtn = (this.props.showShareBtn && canGenerateShareLink) ? [SHARE] : []; + menuList = [...shareBtn, TAGS, RELATED_FILES, 'Divider', HISTORY, 'Divider', OPEN_VIA_CLIENT]; if (!Utils.isMarkdownFile(dirent.name)) { menuList.splice(2, 1); diff --git a/frontend/src/components/toolbar/view-file-toolbar.js b/frontend/src/components/toolbar/view-file-toolbar.js index 8ce9ccfbf1..b289e330f2 100644 --- a/frontend/src/components/toolbar/view-file-toolbar.js +++ b/frontend/src/components/toolbar/view-file-toolbar.js @@ -23,6 +23,7 @@ const propTypes = { relatedFiles: PropTypes.array.isRequired, onFileTagChanged: PropTypes.func.isRequired, onRelatedFileChange: PropTypes.func.isRequired, + showShareBtn: PropTypes.bool.isRequired, }; class ViewFileToolbar extends React.Component { @@ -108,7 +109,7 @@ class ViewFileToolbar extends React.Component { {gettext('More')} - {canGenerateShareLink && + {this.props.showShareBtn && canGenerateShareLink && {gettext('Share')} } {gettext('Tags')} diff --git a/frontend/src/pages/lib-content-view/lib-content-toolbar.js b/frontend/src/pages/lib-content-view/lib-content-toolbar.js index 1bda24b038..1aa3ea3e64 100644 --- a/frontend/src/pages/lib-content-view/lib-content-toolbar.js +++ b/frontend/src/pages/lib-content-view/lib-content-toolbar.js @@ -71,6 +71,7 @@ class LibContentToolbar extends React.Component { relatedFiles={this.props.relatedFiles} onFileTagChanged={this.props.onFileTagChanged} onRelatedFileChange={this.props.onRelatedFileChange} + showShareBtn={this.props.showShareBtn} /> @@ -101,6 +102,7 @@ class LibContentToolbar extends React.Component { relatedFiles={this.props.relatedFiles} unSelectDirent={this.props.unSelectDirent} onFilesTagChanged={this.props.onFilesTagChanged} + showShareBtn={this.props.showShareBtn} /> :