1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 19:01:42 +00:00

Fix/record not found (#7606)

* fix path

* fix record not found after rename node

* fix path update

* fix rename dialog display

---------

Co-authored-by: zhouwenxuan <aries@Mac.local>
This commit is contained in:
Aries
2025-03-14 10:31:04 +08:00
committed by GitHub
parent cb074ea304
commit 0c29734c5f
5 changed files with 34 additions and 63 deletions

View File

@@ -66,6 +66,7 @@ class Rename extends React.Component {
handleKeyDown = (e) => { handleKeyDown = (e) => {
if (e.key === 'Enter') { if (e.key === 'Enter') {
e.preventDefault();
this.handleSubmit(); this.handleSubmit();
} }
}; };

View File

@@ -4,14 +4,12 @@ import { siteRoot, thumbnailSizeForGrid } from '../../../utils/constants';
import { seafileAPI } from '../../../utils/seafile-api'; import { seafileAPI } from '../../../utils/seafile-api';
import { Utils } from '../../../utils/utils'; import { Utils } from '../../../utils/utils';
import toaster from '../../toast'; import toaster from '../../toast';
import Dirent from '../../../models/dirent';
import { Detail, Header, Body } from '../detail'; import { Detail, Header, Body } from '../detail';
import DirDetails from './dir-details'; import DirDetails from './dir-details';
import FileDetails from './file-details'; import FileDetails from './file-details';
import ObjectUtils from '../../../utils/object'; import ObjectUtils from '../../../utils/object';
import { MetadataDetailsProvider } from '../../../metadata/hooks'; import { MetadataDetailsProvider } from '../../../metadata/hooks';
import { Settings, AI } from '../../../metadata/components/metadata-details'; import { Settings, AI } from '../../../metadata/components/metadata-details';
import { getDirentPath } from './utils';
import './index.css'; import './index.css';
@@ -21,40 +19,12 @@ class DirentDetails extends React.Component {
super(props); super(props);
this.state = { this.state = {
direntDetail: '', direntDetail: '',
dirent: null,
}; };
} }
updateDetail = (repoID, dirent, direntPath) => { updateDetail = (repoID, dirent, direntPath) => {
if (!dirent) {
this.setState({ dirent: null, direntDetail: '' });
return;
}
seafileAPI[dirent.type === 'file' ? 'getFileInfo' : 'getDirInfo'](repoID, direntPath).then(res => { seafileAPI[dirent.type === 'file' ? 'getFileInfo' : 'getDirInfo'](repoID, direntPath).then(res => {
this.setState(({ this.setState({ direntDetail: res.data });
direntDetail: res.data,
dirent,
}));
}).catch(error => {
const errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
};
loadDetail = (repoID, dirent, path) => {
if (dirent) {
const direntPath = Utils.joinPath(path, dirent.name);
this.updateDetail(repoID, dirent, direntPath);
return;
}
const dirPath = Utils.getDirName(path);
seafileAPI.listDir(repoID, dirPath).then(res => {
const direntList = res.data.dirent_list;
let folderDirent = direntList.find(item => item.parent_dir + item.name === path) || null;
if (folderDirent) {
folderDirent = new Dirent(folderDirent);
}
this.updateDetail(repoID, folderDirent, path);
}).catch(error => { }).catch(error => {
const errMessage = Utils.getErrorMsg(error); const errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage); toaster.danger(errMessage);
@@ -62,7 +32,8 @@ class DirentDetails extends React.Component {
}; };
componentDidMount() { componentDidMount() {
this.loadDetail(this.props.repoID, this.props.dirent, this.props.path); const fullPath = Utils.joinPath(this.props.path, this.props.dirent.name);
this.updateDetail(this.props.repoID, this.props.dirent, fullPath);
} }
UNSAFE_componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
@@ -71,19 +42,16 @@ class DirentDetails extends React.Component {
!ObjectUtils.isSameObject(dirent, nextProps.dirent, ['name']) || !ObjectUtils.isSameObject(dirent, nextProps.dirent, ['name']) ||
JSON.stringify(repoTags || []) !== JSON.stringify(nextProps.repoTags || []) || JSON.stringify(repoTags || []) !== JSON.stringify(nextProps.repoTags || []) ||
JSON.stringify(fileTags || []) !== JSON.stringify(nextProps.fileTags || []) || JSON.stringify(fileTags || []) !== JSON.stringify(nextProps.fileTags || []) ||
path !== nextProps.path || (path !== nextProps.path && !ObjectUtils.isSameObject(dirent, nextProps.dirent, ['name'])) ||
repoID !== nextProps.repoID repoID !== nextProps.repoID
) { ) {
this.setState({ dirent: null }, () => { const fullPath = Utils.joinPath(nextProps.path, nextProps.dirent.name);
this.loadDetail(nextProps.repoID, nextProps.dirent, nextProps.path); this.updateDetail(nextProps.repoID, nextProps.dirent, fullPath);
});
} else if (nextProps.dirent && ObjectUtils.isSameObject(dirent, nextProps.dirent, ['name'])) {
this.setState({ dirent: nextProps.dirent });
} }
} }
renderImage = () => { renderImage = () => {
const { dirent } = this.state; const { dirent } = this.props;
if (!dirent) return null; if (!dirent) return null;
const isImg = Utils.imageCheck(dirent.name); const isImg = Utils.imageCheck(dirent.name);
if (!isImg) return null; if (!isImg) return null;
@@ -102,9 +70,8 @@ class DirentDetails extends React.Component {
}; };
render() { render() {
const { dirent, direntDetail } = this.state; const { direntDetail } = this.state;
const { repoID, fileTags } = this.props; const { repoID, fileTags, path, dirent } = this.props;
if (!dirent || !direntDetail) { if (!dirent || !direntDetail) {
return ( return (
<Detail> <Detail>
@@ -116,16 +83,11 @@ class DirentDetails extends React.Component {
); );
} }
let path = this.props.path;
if (dirent?.type !== 'file') {
path = this.props.dirent ? Utils.joinPath(path, dirent.name) : path;
}
return ( return (
<MetadataDetailsProvider <MetadataDetailsProvider
repoID={repoID} repoID={repoID}
repoInfo={this.props.currentRepoInfo} repoInfo={this.props.currentRepoInfo}
path={getDirentPath(dirent, path)} path={path}
dirent={dirent} dirent={dirent}
direntDetail={direntDetail} direntDetail={direntDetail}
direntType={dirent?.type !== 'file' ? 'dir' : 'file'} direntType={dirent?.type !== 'file' ? 'dir' : 'file'}
@@ -163,7 +125,7 @@ class DirentDetails extends React.Component {
DirentDetails.propTypes = { DirentDetails.propTypes = {
repoID: PropTypes.string.isRequired, repoID: PropTypes.string.isRequired,
dirent: PropTypes.object, dirent: PropTypes.object.isRequired,
path: PropTypes.string.isRequired, path: PropTypes.string.isRequired,
currentRepoInfo: PropTypes.object.isRequired, currentRepoInfo: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired,

View File

@@ -43,6 +43,8 @@ const Detail = React.memo(({ repoID, path, currentMode, dirent, currentRepoInfo,
return (<LibDetail currentRepoInfo={currentRepoInfo} onClose={onClose} />); return (<LibDetail currentRepoInfo={currentRepoInfo} onClose={onClose} />);
} }
if (!dirent) return null;
return ( return (
<DirentDetail <DirentDetail
repoID={repoID} repoID={repoID}

View File

@@ -169,9 +169,8 @@ export const MetadataDetailsProvider = ({ repoID, repoInfo, path, dirent, dirent
setLoading(true); setLoading(true);
direntRef.current = dirent; direntRef.current = dirent;
const dirName = Utils.getDirName(path); const fileName = dirent.name;
const fileName = Utils.getFileName(path); let parentDir = path;
let parentDir = direntType === 'file' ? dirName : dirName.slice(0, dirName.length - fileName.length - 1);
if (!parentDir.startsWith('/')) { if (!parentDir.startsWith('/')) {
parentDir = '/' + parentDir; parentDir = '/' + parentDir;

View File

@@ -279,10 +279,7 @@ class LibContentView extends React.Component {
}); });
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate() {
if (prevState.path !== this.state.path) {
this.setState({ currentDirent: null });
}
this.lastModifyTime = new Date(); this.lastModifyTime = new Date();
this.props.eventBus.dispatch(EVENT_BUS_TYPE.CURRENT_LIBRARY_CHANGED, { this.props.eventBus.dispatch(EVENT_BUS_TYPE.CURRENT_LIBRARY_CHANGED, {
repoID: this.props.repoID, repoID: this.props.repoID,
@@ -563,6 +560,7 @@ class LibContentView extends React.Component {
this.setState({ this.setState({
isDirentListLoading: true, isDirentListLoading: true,
direntList: [], direntList: [],
path,
}); });
seafileAPI.listDir(repoID, path, { 'with_thumbnail': true }).then(res => { seafileAPI.listDir(repoID, path, { 'with_thumbnail': true }).then(res => {
const { dirent_list, user_perm: userPerm, dir_id: dirID } = res.data; const { dirent_list, user_perm: userPerm, dir_id: dirID } = res.data;
@@ -1083,13 +1081,11 @@ class LibContentView extends React.Component {
}; };
onMainNavBarClick = (nodePath) => { onMainNavBarClick = (nodePath) => {
// just for dir
this.resetSelected(nodePath);
if (this.state.isTreePanelShown) { if (this.state.isTreePanelShown) {
let tree = this.state.treeData.clone(); let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(nodePath); let node = tree.getNodeByPath(nodePath);
tree.expandNode(node); tree.expandNode(node);
this.setState({ treeData: tree, currentNode: node }); this.setState({ treeData: tree, currentNode: nodePath !== '/' ? node : null });
} }
this.showDir(nodePath); this.showDir(nodePath);
@@ -1853,6 +1849,7 @@ class LibContentView extends React.Component {
this.setState({ this.setState({
isTreeDataLoading: false, isTreeDataLoading: false,
treeData: tree, treeData: tree,
currentNode: tree.getNodeByPath(path),
userPerm: user_perm, userPerm: user_perm,
}); });
}).catch(() => { }).catch(() => {
@@ -1869,6 +1866,7 @@ class LibContentView extends React.Component {
} }
if (node.object.isDir()) { if (node.object.isDir()) {
this.setState({ currentNode: node, path: node.path });
let isLoaded = node.isLoaded; let isLoaded = node.isLoaded;
if (!node.isLoaded) { if (!node.isLoaded) {
let tree = this.state.treeData.clone(); let tree = this.state.treeData.clone();
@@ -1907,10 +1905,12 @@ class LibContentView extends React.Component {
this.showDir(node.path); this.showDir(node.path);
} else { } else {
if (Utils.isFileMetadata(node?.object?.type)) { if (Utils.isFileMetadata(node?.object?.type)) {
this.setState({ currentNode: null });
if (node.path !== this.state.path) { if (node.path !== this.state.path) {
this.showFileMetadata(node.path, node.view_id || '0000'); this.showFileMetadata(node.path, node.view_id || '0000');
} }
} else if (Utils.isTags(node?.object?.type)) { } else if (Utils.isTags(node?.object?.type)) {
this.setState({ currentNode: null });
if (node.path !== this.state.path) { if (node.path !== this.state.path) {
this.showTagsView(node.path, node.tag_id); this.showTagsView(node.path, node.tag_id);
} }
@@ -1956,7 +1956,9 @@ class LibContentView extends React.Component {
renameTreeNode = (path, newName) => { renameTreeNode = (path, newName) => {
let tree = treeHelper.renameNodeByPath(this.state.treeData, path, newName); let tree = treeHelper.renameNodeByPath(this.state.treeData, path, newName);
this.setState({ treeData: tree }); const newPath = Utils.joinPath(Utils.getDirName(path), newName);
const currentNode = path === this.state.currentNode?.path ? tree.getNodeByPath(newPath) : this.state.currentNode;
this.setState({ treeData: tree, currentNode });
}; };
deleteTreeNode = (path) => { deleteTreeNode = (path) => {
@@ -2192,7 +2194,7 @@ class LibContentView extends React.Component {
render() { render() {
const { repoID } = this.props; const { repoID } = this.props;
let { currentRepoInfo, userPerm, isCopyMoveProgressDialogShow, isDeleteFolderDialogOpen, errorMsg, let { currentRepoInfo, userPerm, isCopyMoveProgressDialogShow, isDeleteFolderDialogOpen, errorMsg,
path, usedRepoTags, isDirentSelected, currentMode } = this.state; path, usedRepoTags, isDirentSelected, currentMode, currentNode } = this.state;
if (this.state.libNeedDecrypt) { if (this.state.libNeedDecrypt) {
return ( return (
@@ -2258,6 +2260,11 @@ class LibContentView extends React.Component {
currentDirent = currentDirent.toJson(); currentDirent = currentDirent.toJson();
} }
let detailPath = this.state.path;
if (!currentDirent && currentMode !== METADATA_MODE && currentMode !== TAGS_MODE) {
detailPath = Utils.getDirName(this.state.path);
}
const detailDirent = currentDirent || currentNode?.object || null;
return ( return (
<MetadataStatusProvider repoID={repoID} repoInfo={currentRepoInfo} hideMetadataView={this.hideMetadataView}> <MetadataStatusProvider repoID={repoID} repoInfo={currentRepoInfo} hideMetadataView={this.hideMetadataView}>
<TagsProvider repoID={repoID} currentPath={path} repoInfo={currentRepoInfo} selectTagsView={this.onTreeNodeClick} > <TagsProvider repoID={repoID} currentPath={path} repoInfo={currentRepoInfo} selectTagsView={this.onTreeNodeClick} >
@@ -2443,10 +2450,10 @@ class LibContentView extends React.Component {
} }
{!isCustomPermission && this.state.isDirentDetailShow && ( {!isCustomPermission && this.state.isDirentDetailShow && (
<Detail <Detail
path={this.state.path} path={detailPath}
repoID={this.props.repoID} repoID={this.props.repoID}
currentRepoInfo={{ ...this.state.currentRepoInfo }} currentRepoInfo={{ ...this.state.currentRepoInfo }}
dirent={currentDirent} dirent={detailDirent}
repoTags={this.state.repoTags} repoTags={this.state.repoTags}
fileTags={this.state.isViewFile ? this.state.fileTags : []} fileTags={this.state.isViewFile ? this.state.fileTags : []}
onFileTagChanged={this.onFileTagChanged} onFileTagChanged={this.onFileTagChanged}