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';
const Detail = ({ children, className }) => {
const Detail = ({ children, className, isInSearch }) => {
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 resizeBarRef = useRef(null);
const dragHandlerRef = useRef(null);
@@ -52,22 +52,24 @@ const Detail = ({ children, className }) => {
style={{ width }}
>
{children}
<ResizeBar
resizeBarRef={resizeBarRef}
dragHandlerRef={dragHandlerRef}
resizeBarStyle={{ left: -1 }}
dragHandlerStyle={{ height: DRAG_HANDLER_HEIGHT }}
onResizeMouseDown={onResizeMouseDown}
onResizeMouseOver={onResizeMouseOver}
/>
{!isInSearch &&
<ResizeBar
resizeBarRef={resizeBarRef}
dragHandlerRef={dragHandlerRef}
resizeBarStyle={{ left: -1 }}
dragHandlerStyle={{ height: DRAG_HANDLER_HEIGHT }}
onResizeMouseDown={onResizeMouseDown}
onResizeMouseOver={onResizeMouseOver}
/>
}
</div>
);
};
Detail.propTypes = {
className: PropTypes.string,
children: PropTypes.any,
isInSearch: PropTypes.bool,
};
export default Detail;

View File

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

View File

@@ -9,7 +9,7 @@ import { MetadataStatusProvider } from '../../../hooks';
import Details from './details';
import LibDetail from '../../dirent-detail/lib-details';
import { Body, Header } from '../../dirent-detail/detail';
import { gettext } from '../../../utils/constants';
import { gettext, mediaUrl } from '../../../utils/constants';
import './index.css';
@@ -17,15 +17,33 @@ const SearchedItemDetails = ({ repoID, path, dirent }) => {
const [repoInfo, setRepoInfo] = useState(null);
const [direntDetail, setDirentDetail] = useState(null);
const [errMessage, setErrMessage] = useState(null);
const [libErrorMessage, setLibErrorMessage] = useState(null);
useEffect(() => {
seafileAPI.getRepoInfo(repoID).then(res => {
const repo = new Repo(res.data);
setRepoInfo(repo);
}).catch(error => {
const errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
const controller = new AbortController();
const fetchData = async () => {
try {
const res = await seafileAPI.getRepoInfo(repoID);
const repo = new Repo(res.data);
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]);
useEffect(() => {
@@ -68,6 +86,22 @@ const SearchedItemDetails = ({ repoID, 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 (errMessage) {
@@ -89,7 +123,7 @@ const SearchedItemDetails = ({ repoID, path, dirent }) => {
if (dirent.isLib) {
return (
<div className="searched-item-details">
<LibDetail currentRepoInfo={repoInfo} />
<LibDetail currentRepoInfo={repoInfo} isInSearch={true} />
</div>
);
}

View File

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