diff --git a/frontend/src/components/dialog/edit-filetag-dialog.js b/frontend/src/components/dialog/edit-filetag-dialog.js index 8cff7478cc..073ddaabd4 100644 --- a/frontend/src/components/dialog/edit-filetag-dialog.js +++ b/frontend/src/components/dialog/edit-filetag-dialog.js @@ -10,10 +10,8 @@ require('../../css/repo-tag.css'); const TagItemPropTypes = { repoID: PropTypes.string.isRequired, repoTag: PropTypes.object.isRequired, - filePath: PropTypes.string, - filesPath: PropTypes.array, - fileTagList: PropTypes.array, - multiFileTagList: PropTypes.array, + filePath: PropTypes.string.isRequired, + fileTagList: PropTypes.array.isRequired, onEditFileTag: PropTypes.func.isRequired, }; @@ -22,8 +20,7 @@ class TagItem extends React.Component { constructor(props) { super(props); this.state = { - showSelectedTag: false, - freeze: false, + showSelectedTag: false }; } @@ -41,103 +38,35 @@ class TagItem extends React.Component { getRepoTagIdList = () => { let repoTagIdList = []; - if (this.props.fileTagList.length > 0) { - let fileTagList = this.props.fileTagList; - fileTagList.map((fileTag) => { - repoTagIdList.push(fileTag.repo_tag_id); - }); - return repoTagIdList; - } else { - const tagList = this.props.multiFileTagList; - const length = tagList.length; - let tagArray = []; - for (let i = 0; i< length; i++) { - for (let j = 0; j < tagList[i].length; j++) { - tagArray.push(tagList[i][j].repo_tag_id); - } - } - repoTagIdList = this.getCommonTag(tagArray, length); - return repoTagIdList; - } - } - - getCommonTag = (filesTags, filesNumber) => { - let hash = {}; - let tagNumber = 1; - let commonTags = []; - for (let i = 0, len = filesTags.length; i < len; i++) { - let filesTag = filesTags[i]; - if (!hash[filesTag]) { - hash[filesTag] = 1; - } else{ - hash[filesTag]++; - } - if (hash[filesTag] == tagNumber) { - if (tagNumber === filesNumber) { - commonTags.push(filesTag); - } - } else if (hash[filesTag] > tagNumber) { - tagNumber = hash[filesTag]; - if (tagNumber === filesNumber) { - commonTags.push(filesTag); - } - } - } - return commonTags; + let fileTagList = this.props.fileTagList; + fileTagList.map((fileTag) => { + repoTagIdList.push(fileTag.repo_tag_id); + }); + return repoTagIdList; } onEditFileTag = () => { - if (this.state.freeze) return; - let { repoID, repoTag, filePath, filesPath, fileTagList } = this.props; - this.setState({ freeze: true }); - if (filesPath.length === 1) { - let repoTagIdList = this.getRepoTagIdList(); - if (repoTagIdList.indexOf(repoTag.id) === -1) { - seafileAPI.addFileTag(repoID, filePath, repoTag.id).then(() => { - repoTagIdList = this.getRepoTagIdList(); - this.props.onEditFileTag(); - this.setState({ freeze: false }); - }); - } else { - let fileTag = null; - for (let i = 0; i < fileTagList.length; i++) { - if (fileTagList[i].repo_tag_id === repoTag.id) { - fileTag = fileTagList[i]; - break; - } - } - seafileAPI.deleteFileTag(repoID, fileTag.id).then(() => { - repoTagIdList = this.getRepoTagIdList(); - this.props.onEditFileTag(); - this.setState({ freeze: false }); - }); - } - } else { - this.onEditFilesTag(); - } - } - - onEditFilesTag = () => { - let { repoID, repoTag, filesPath, multiFileTagList } = this.props; + let { repoID, repoTag, filePath } = this.props; let repoTagIdList = this.getRepoTagIdList(); if (repoTagIdList.indexOf(repoTag.id) === -1) { - for (let i = 0, length = filesPath.length; i < length; i++) { - seafileAPI.addFileTag(repoID, filesPath[i], repoTag.id).then(() => { - this.props.onEditFileTag(); - this.setState({ freeze: false }); - }); - } + let id = repoTag.id; + seafileAPI.addFileTag(repoID, filePath, id).then(() => { + repoTagIdList = this.getRepoTagIdList(); + this.props.onEditFileTag(); + }); } else { - for (let i = 0, len = multiFileTagList.length; i < len; i++) { - for (let j = 0, length = multiFileTagList[i].length; j < length; j++) { - if (multiFileTagList[i][j].repo_tag_id === repoTag.id) { - seafileAPI.deleteFileTag(repoID, multiFileTagList[i][j].file_tag_id).then(() => { - this.props.onEditFileTag(); - this.setState({ freeze: false }); - }); - } + let fileTag = null; + let fileTagList = this.props.fileTagList; + for(let i = 0; i < fileTagList.length; i++) { + if (fileTagList[i].repo_tag_id === repoTag.id) { + fileTag = fileTagList[i]; + break; } - } + } + seafileAPI.deleteFileTag(repoID, fileTag.id).then(() => { + repoTagIdList = this.getRepoTagIdList(); + this.props.onEditFileTag(); + }); } } @@ -164,10 +93,8 @@ TagItem.propTypes = TagItemPropTypes; const propTypes = { repoID: PropTypes.string.isRequired, - filePath: PropTypes.string, - filesPath: PropTypes.array, - fileTagList: PropTypes.array, - multiFileTagList: PropTypes.array, + filePath: PropTypes.string.isRequired, + fileTagList: PropTypes.array.isRequired, onFileTagChanged: PropTypes.func.isRequired, toggleCancel: PropTypes.func.isRequired, }; @@ -220,9 +147,7 @@ class EditFileTagDialog extends React.Component { repoTag={repoTag} repoID={this.props.repoID} filePath={this.props.filePath} - filesPath={this.props.filesPath} fileTagList={this.props.fileTagList} - multiFileTagList={this.props.multiFileTagList} onEditFileTag={this.onEditFileTag} /> ); @@ -240,4 +165,4 @@ class EditFileTagDialog extends React.Component { EditFileTagDialog.propTypes = propTypes; -export default EditFileTagDialog; +export default EditFileTagDialog; \ No newline at end of file diff --git a/frontend/src/components/dirent-list-view/dirents-menu.js b/frontend/src/components/dirent-list-view/dirents-menu.js index 1ea6312d26..e822b06186 100644 --- a/frontend/src/components/dirent-list-view/dirents-menu.js +++ b/frontend/src/components/dirent-list-view/dirents-menu.js @@ -38,14 +38,8 @@ class DirentMenu extends React.Component { menuList.splice(2, 1); } } - } else if (length > 1) { - menuList = ['Tags']; - for (let i = 0; i < length; i++) { - if (dirents[i].type === 'dir') { - menuList = []; - break; - } - } + } else { + menuList = []; } this.setState({ menuList: menuList, diff --git a/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js b/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js index 507a17766a..10b3c07cc8 100644 --- a/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js +++ b/frontend/src/components/toolbar/mutilple-dir-operation-toolbar.js @@ -120,7 +120,7 @@ class MutipleDirOperationToolbar extends React.Component { }); break; case 'Tags': - this.listFilesTags(dirents); + this.listFileTags(dirent); break; case 'Details': this.props.showDirentDetail(); @@ -239,18 +239,6 @@ class MutipleDirOperationToolbar extends React.Component { }); } - listFilesTags = (dirents) => { - if (dirents.length === 1) { - this.listFileTags(dirents[0]); - } else if (dirents.length > 1) { - this.listMultiFileTags(dirents); - } - this.setState({ - showLibContentViewDialogs: true, - showEditFileTagDialog: true, - }); - } - listFileTags = (dirent) => { let filePath = this.getDirentPath(dirent); seafileAPI.listFileTags(this.props.repoID, filePath).then(res => { @@ -259,30 +247,14 @@ class MutipleDirOperationToolbar extends React.Component { fileTagList[i].id = fileTagList[i].file_tag_id; } this.setState({ - fileTagList: fileTagList + fileTagList: fileTagList, + showLibContentViewDialogs: true, + showEditFileTagDialog: true, }); }); } - listMultiFileTags = (dirents) => { - let multiFileTagList = []; - let len = dirents.length; - for (let j = 0; j < len; j++) { - seafileAPI.listFileTags(this.props.repoID, this.getDirentPath(dirents[j])).then(res => { - let fileTagList = res.data.file_tags; - for (let i = 0, length = fileTagList.length; i < length; i++) { - fileTagList[i].id = fileTagList[i].file_tag_id; - } - multiFileTagList.push(fileTagList); - }); - this.setState({ - multiFileTagList: multiFileTagList - }); - } - } - onMenuFileTagChanged = () => { - this.listMultiFileTags(this.props.selectedDirentList); this.listFileTags(this.props.selectedDirentList[0]); let length = this.props.selectedDirentList.length; for (let i = 0; i < length; i++) { @@ -312,14 +284,6 @@ class MutipleDirOperationToolbar extends React.Component { render() { const { repoID } = this.props; let direntPath = this.getDirentPath(this.props.selectedDirentList[0]); - - let direntsPath = []; - if (this.state.showLibContentViewDialogs && this.props.selectedDirentList.length > 0) { - for (let i = 0; i < this.props.selectedDirentList.length; i++) { - let newDirentPath = this.getDirentPath(this.props.selectedDirentList[i]); - direntsPath.push(newDirentPath); - } - } return (
@@ -386,12 +350,9 @@ class MutipleDirOperationToolbar extends React.Component { }