diff --git a/frontend/src/components/dialog/move-dirent-dialog.js b/frontend/src/components/dialog/move-dirent-dialog.js index f62ecb7267..d5545c83a4 100644 --- a/frontend/src/components/dialog/move-dirent-dialog.js +++ b/frontend/src/components/dialog/move-dirent-dialog.js @@ -199,6 +199,10 @@ class MoveDirent extends React.Component { this.setState({ errMessage: message }); }; + clearErrMessage = () => { + this.setState({ errMessage: '' }); + }; + updateMode = (mode) => { if (mode === this.state.mode) return; @@ -229,6 +233,7 @@ class MoveDirent extends React.Component { } this.setState({ selectedSearchedItem: { repoID: '', filePath: '' } }); + this.clearErrMessage(); }; onUpdateSearchStatus = (status) => { @@ -237,20 +242,23 @@ class MoveDirent extends React.Component { onUpdateSearchResults = (results) => { this.setState({ - searchResults: results + searchResults: results, + selectedRepo: results.length > 0 ? new RepoInfo(results[0]) : null, + selectedPath: results.length > 0 ? results[0].path : '', }); }; onDirentItemClick = (repo, selectedPath) => { this.setState({ selectedPath: selectedPath, - repo, - errMessage: '', + selectedRepo: repo, }); + this.clearErrMessage(); }; onOpenSearchBar = () => { this.setState({ showSearchBar: true }); + this.clearErrMessage(); }; onCloseSearchBar = () => { @@ -263,12 +271,14 @@ class MoveDirent extends React.Component { showSearchBar: false, initToShowChildren: mode === MODE_TYPE_MAP.ONLY_CURRENT_LIBRARY, }); + this.clearErrMessage(); }; onSearchedItemClick = (item) => { item['type'] = item.is_dir ? 'dir' : 'file'; let repo = new RepoInfo(item); this.onDirentItemClick(repo, item.path, item); + this.clearErrMessage(); }; onSearchedItemDoubleClick = (item) => { @@ -311,7 +321,7 @@ class MoveDirent extends React.Component { render() { const { dirent, selectedDirentList, isMultipleOperation, path } = this.props; - const { mode, currentRepo, selectedRepo, selectedPath, showSearchBar, searchStatus, searchResults, selectedSearchedRepo } = this.state; + const { mode, currentRepo, selectedRepo, selectedPath, showSearchBar, searchStatus, searchResults, selectedSearchedRepo, errMessage } = this.state; const movedDirent = dirent || selectedDirentList[0]; const { permission } = movedDirent; const { isCustomPermission } = Utils.getUserPermission(permission); @@ -356,7 +366,9 @@ class MoveDirent extends React.Component { onCancel={this.toggle} selectRepo={this.selectRepo} setSelectedPath={this.setSelectedPath} + errMessage={errMessage} setErrMessage={this.setErrMessage} + clearErrMessage={this.clearErrMessage} handleSubmit={this.handleSubmit} onUpdateMode={this.updateMode} searchStatus={searchStatus} diff --git a/frontend/src/components/dialog/select-dirent-body.js b/frontend/src/components/dialog/select-dirent-body.js index 87f892894e..5991560ecb 100644 --- a/frontend/src/components/dialog/select-dirent-body.js +++ b/frontend/src/components/dialog/select-dirent-body.js @@ -22,7 +22,6 @@ class SelectDirentBody extends React.Component { constructor(props) { super(props); this.state = { - errMessage: '', showCreateFolderDialog: false, folderListOfSelectedRepo: [], }; @@ -52,13 +51,13 @@ class SelectDirentBody extends React.Component { onDirentItemClick = (repo, selectedPath) => { this.props.selectRepo(repo); this.props.setSelectedPath(selectedPath); - this.props.setErrMessage(''); + this.props.clearErrMessage(); }; onRepoItemClick = (repo) => { this.props.selectRepo(repo); this.props.setSelectedPath('/'); - this.props.setErrMessage(''); + this.props.clearErrMessage(); }; loadRepoDirentList = async (repo, path) => { @@ -72,7 +71,7 @@ class SelectDirentBody extends React.Component { createFolder = (fullPath) => { if (!this.props.selectedRepo) { - this.setState({ errMessage: gettext('Please select a library or folder first.') }); + this.props.setErrMessage(gettext('Please select a library or folder first.')); return; } this.newFolderName = fullPath.split('/').pop(); @@ -103,7 +102,8 @@ class SelectDirentBody extends React.Component { } else { this.setState({ folderListOfSelectedRepo: [] }); } - this.setState({ showCreateFolderDialog: !this.state.showCreateFolderDialog, errMessage: '' }); + this.setState({ showCreateFolderDialog: !this.state.showCreateFolderDialog }); + this.props.clearErrMessage(); }; checkDuplicatedName = (newName) => { @@ -120,6 +120,7 @@ class SelectDirentBody extends React.Component { this.props.selectRepo(null); } this.props.setSelectedPath('/'); + this.props.clearErrMessage(); }; render() { @@ -219,6 +220,7 @@ SelectDirentBody.propTypes = { selectRepo: PropTypes.func.isRequired, setSelectedPath: PropTypes.func, setErrMessage: PropTypes.func, + clearErrMessage: PropTypes.func, mode: PropTypes.string, onUpdateMode: PropTypes.func, searchStatus: PropTypes.string,