1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-24 12:58:34 +00:00

Fix search result is another repo (#7891)

* 01 fix searched another repo

* 02 search result is repo style

* 03 searched repo is deleted
This commit is contained in:
Michael An
2025-06-06 09:00:00 +08:00
committed by GitHub
parent 9a72af75af
commit 5f4bae8f9d
4 changed files with 66 additions and 25 deletions

View File

@@ -6,9 +6,9 @@ import { DRAG_HANDLER_HEIGHT } from '../../../resize-bar/constants';
import './index.css'; import './index.css';
const Detail = ({ children, className }) => { const Detail = ({ children, className, isInSearch }) => {
const lastSettingsValue = localStorage.getItem('sf_cur_view_detail_width'); const lastSettingsValue = localStorage.getItem('sf_cur_view_detail_width');
const [width, setWidth] = useState(lastSettingsValue ? parseInt(lastSettingsValue) : 300); const [width, setWidth] = useState(isInSearch ? 300 : (lastSettingsValue ? parseInt(lastSettingsValue) : 300));
const [isResizing, setResizing] = useState(false); const [isResizing, setResizing] = useState(false);
const resizeBarRef = useRef(null); const resizeBarRef = useRef(null);
const dragHandlerRef = useRef(null); const dragHandlerRef = useRef(null);
@@ -52,22 +52,24 @@ const Detail = ({ children, className }) => {
style={{ width }} style={{ width }}
> >
{children} {children}
<ResizeBar {!isInSearch &&
resizeBarRef={resizeBarRef} <ResizeBar
dragHandlerRef={dragHandlerRef} resizeBarRef={resizeBarRef}
resizeBarStyle={{ left: -1 }} dragHandlerRef={dragHandlerRef}
dragHandlerStyle={{ height: DRAG_HANDLER_HEIGHT }} resizeBarStyle={{ left: -1 }}
onResizeMouseDown={onResizeMouseDown} dragHandlerStyle={{ height: DRAG_HANDLER_HEIGHT }}
onResizeMouseOver={onResizeMouseOver} onResizeMouseDown={onResizeMouseDown}
/> onResizeMouseOver={onResizeMouseOver}
/>
}
</div> </div>
); );
}; };
Detail.propTypes = { Detail.propTypes = {
className: PropTypes.string, className: PropTypes.string,
children: PropTypes.any, children: PropTypes.any,
isInSearch: PropTypes.bool,
}; };
export default Detail; export default Detail;

View File

@@ -11,7 +11,7 @@ import { seafileAPI } from '../../utils/seafile-api';
import Repo from '../../models/repo'; import Repo from '../../models/repo';
import { CellType } from '../../metadata/constants'; import { CellType } from '../../metadata/constants';
const LibDetail = React.memo(({ currentRepoInfo, onClose }) => { const LibDetail = React.memo(({ currentRepoInfo, onClose, isInSearch }) => {
const [isLoading, setLoading] = useState(true); const [isLoading, setLoading] = useState(true);
const [repo, setRepo] = useState({}); const [repo, setRepo] = useState({});
const libIconUrl = useMemo(() => Utils.getLibIconUrl(currentRepoInfo), [currentRepoInfo]); const libIconUrl = useMemo(() => Utils.getLibIconUrl(currentRepoInfo), [currentRepoInfo]);
@@ -33,7 +33,7 @@ const LibDetail = React.memo(({ currentRepoInfo, onClose }) => {
}, [currentRepoInfo.repo_id]); }, [currentRepoInfo.repo_id]);
return ( return (
<Detail> <Detail isInSearch={isInSearch}>
<Header title={currentRepoInfo.repo_name} icon={libIconUrl} onClose={onClose} /> <Header title={currentRepoInfo.repo_name} icon={libIconUrl} onClose={onClose} />
<Body> <Body>
{isLoading ? {isLoading ?
@@ -74,6 +74,7 @@ const LibDetail = React.memo(({ currentRepoInfo, onClose }) => {
LibDetail.propTypes = { LibDetail.propTypes = {
currentRepoInfo: PropTypes.object.isRequired, currentRepoInfo: PropTypes.object.isRequired,
onClose: PropTypes.func, onClose: PropTypes.func,
isInSearch: PropTypes.bool,
}; };
export default LibDetail; export default LibDetail;

View File

@@ -9,7 +9,7 @@ import { MetadataStatusProvider } from '../../../hooks';
import Details from './details'; import Details from './details';
import LibDetail from '../../dirent-detail/lib-details'; import LibDetail from '../../dirent-detail/lib-details';
import { Body, Header } from '../../dirent-detail/detail'; import { Body, Header } from '../../dirent-detail/detail';
import { gettext } from '../../../utils/constants'; import { gettext, mediaUrl } from '../../../utils/constants';
import './index.css'; import './index.css';
@@ -17,15 +17,33 @@ const SearchedItemDetails = ({ repoID, path, dirent }) => {
const [repoInfo, setRepoInfo] = useState(null); const [repoInfo, setRepoInfo] = useState(null);
const [direntDetail, setDirentDetail] = useState(null); const [direntDetail, setDirentDetail] = useState(null);
const [errMessage, setErrMessage] = useState(null); const [errMessage, setErrMessage] = useState(null);
const [libErrorMessage, setLibErrorMessage] = useState(null);
useEffect(() => { useEffect(() => {
seafileAPI.getRepoInfo(repoID).then(res => { const controller = new AbortController();
const repo = new Repo(res.data); const fetchData = async () => {
setRepoInfo(repo); try {
}).catch(error => { const res = await seafileAPI.getRepoInfo(repoID);
const errMessage = Utils.getErrorMsg(error); const repo = new Repo(res.data);
toaster.danger(errMessage); setRepoInfo(repo);
}); setLibErrorMessage(null);
} catch (error) {
if (error.response && error.response.status === 404) {
const err = gettext('Library does not exist');
setRepoInfo(null);
setLibErrorMessage(err);
} else {
const errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
}
}
};
const timer = setTimeout(fetchData, 200);
return () => {
controller.abort();
clearTimeout(timer);
};
}, [repoID]); }, [repoID]);
useEffect(() => { useEffect(() => {
@@ -68,6 +86,22 @@ const SearchedItemDetails = ({ repoID, path, dirent }) => {
}; };
}, [repoID, repoInfo, path, dirent]); }, [repoID, repoInfo, path, dirent]);
if (!repoInfo && libErrorMessage) {
return (
<div className="searched-item-details">
<div
className="cur-view-detail"
style={{ width: 300 }}
>
<Header title={dirent?.name || ''} icon={mediaUrl + 'img/lib/256/lib.png'}></Header>
<Body className="error">
{libErrorMessage}
</Body>
</div>
</div>
);
}
if (!repoInfo) return; if (!repoInfo) return;
if (errMessage) { if (errMessage) {
@@ -89,7 +123,7 @@ const SearchedItemDetails = ({ repoID, path, dirent }) => {
if (dirent.isLib) { if (dirent.isLib) {
return ( return (
<div className="searched-item-details"> <div className="searched-item-details">
<LibDetail currentRepoInfo={repoInfo} /> <LibDetail currentRepoInfo={repoInfo} isInSearch={true} />
</div> </div>
); );
} }

View File

@@ -711,13 +711,17 @@ class Search extends Component {
}; };
renderDetails = (results) => { renderDetails = (results) => {
const { repoID: currentRepoID } = this.props;
const { highlightIndex } = this.state; const { highlightIndex } = this.state;
const item = results[highlightIndex]; const item = results[highlightIndex];
if (!item) return null; if (!item) return null;
const repoID = item.repo_id; const repoID = item.repo_id;
const isLib = !currentRepoID && item.path === '/'; const dirent = {
const dirent = { name: item.name, type: item.is_dir ? 'dir' : 'file', isLib, file_tags: [], path: item.path }; name: item.name,
type: item.is_dir ? 'dir' : 'file',
isLib: item.path === '/',
file_tags: [],
path: item.path
};
return ( return (
<CollaboratorsProvider repoID={repoID}> <CollaboratorsProvider repoID={repoID}>
<SearchedItemDetails repoID={repoID} path={item.path} dirent={dirent} /> <SearchedItemDetails repoID={repoID} path={item.path} dirent={dirent} />