fix(search): harden authorized results and ordering

This commit is contained in:
2026-07-21 17:42:22 +08:00
parent 110423406b
commit 60e5ef0a87
13 changed files with 481 additions and 80 deletions

View File

@@ -18,6 +18,7 @@ import {
import type { SearchResultDTO } from '../api/search'
import { LoginPage } from '../pages/login'
import { ProjectActionModals, type CronDraft, type ProjectActionModal, type ProjectDraft, type SourceDraft, type TaskDraft } from '../pages/projects/project-action-modals'
import { SearchResultPreview } from '../pages/projects/search-result-preview'
import type { ProjectSettingsUpdate } from '../pages/projects/project-sidebar'
import { ProjectPage } from '../pages/workspace-home'
import type { WorkspaceTaskUpdate } from '../pages/workspace-body'
@@ -37,6 +38,7 @@ function App() {
const [loading, setLoading] = useState(false)
const [actionLoading, setActionLoading] = useState(false)
const [activeModal, setActiveModal] = useState<ProjectActionModal>(null)
const [searchResultPreview, setSearchResultPreview] = useState<SearchResultDTO | null>(null)
const workspaceSearch = useWorkbenchSearch(session)
const dark = theme === 'dark'
@@ -228,16 +230,20 @@ function App() {
}
function handleSelectSearchResult(result: SearchResultDTO) {
const owningWorkspace = workspaces.find((workspace) => workspace.project.id === result.projectId)
if (!owningWorkspace) {
Message.warning('该搜索结果所在项目当前不可访问')
return
}
const target = searchResultTarget(result.type)
if (!target) {
Message.warning('该搜索结果暂不支持导航')
return
}
const owningWorkspace = workspaces.find((workspace) => workspace.project.id === result.projectId)
if (!owningWorkspace) {
if (isAuthorizedExternalPreview(result)) {
setSearchResultPreview(result)
} else {
Message.warning('该搜索结果所在项目当前不可访问')
}
return
}
setActiveProjectID(owningWorkspace.project.id)
setActiveView('project')
setActiveChannel(target.channel)
@@ -304,6 +310,7 @@ function App() {
onCreateCronPlan={handleCreateCronPlan}
tagOptions={activeTagOptions}
/>
<SearchResultPreview result={searchResultPreview} onClose={() => setSearchResultPreview(null)} />
</main>
</ConfigProvider>
)
@@ -316,4 +323,15 @@ function searchResultTarget(type: string): { channel: ChannelKey; openTask: bool
return null
}
function isAuthorizedExternalPreview(result: SearchResultDTO) {
return (
(result.type === 'task' || result.type === 'note')
&& typeof result.projectId === 'string'
&& result.projectId.trim() !== ''
&& typeof result.title === 'string'
&& result.title.trim() !== ''
&& typeof result.snippet === 'string'
)
}
export default App