Enhance ComponentsKnowledgePage with improved dialog content and layout

- Add DialogDescription components to provide context in the settings and search dialogs.
- Refactor layout for better spacing and organization of form elements in the settings dialog.
- Update search results display to improve user experience with clearer messaging and styling.
- Introduce footer buttons for closing dialogs, enhancing user interaction.
This commit is contained in:
Xin Wang
2026-07-12 18:26:34 +08:00
parent 5d52ce8380
commit 0536930fde

View File

@@ -27,6 +27,7 @@ import { DataList } from "@/components/ui/data-list";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogDescription,
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
@@ -975,29 +976,28 @@ function KnowledgeEditView({ knowledgeBaseId }: { knowledgeBaseId: string }) {
</Card> </Card>
<Dialog open={settingsOpen} onOpenChange={setSettingsOpen}> <Dialog open={settingsOpen} onOpenChange={setSettingsOpen}>
<DialogContent> <DialogContent className="sm:max-w-xl">
<DialogHeader> <DialogHeader>
<DialogTitle></DialogTitle> <DialogTitle></DialogTitle>
<DialogDescription>
Embedding
</DialogDescription>
</DialogHeader> </DialogHeader>
<div className="space-y-4"> <div className="space-y-5 rounded-xl border border-hairline bg-surface-strong/20 p-4">
<label className="block"> <label className="block space-y-2">
<div className="mb-2 text-sm font-medium text-foreground"> <span className="text-sm font-medium"></span>
</div>
<Textarea <Textarea
placeholder="用途说明(可选)" placeholder="用途说明(可选)"
value={description} value={description}
onChange={(event) => setDescription(event.target.value)} onChange={(event) => setDescription(event.target.value)}
rows={4} rows={4}
className="field-sizing-fixed min-h-24 resize-y border-hairline-strong bg-background" className="field-sizing-fixed min-h-24 resize-y"
/> />
</label> </label>
<div> <label className="block space-y-2">
<div className="mb-2 text-sm font-medium text-foreground"> <span className="text-sm font-medium">Embedding </span>
Embedding
</div>
<Select value={embeddingId} onValueChange={setEmbeddingId}> <Select value={embeddingId} onValueChange={setEmbeddingId}>
<SelectTrigger className="border-hairline-strong bg-background"> <SelectTrigger className="w-full">
<SelectValue placeholder="选择 Embedding 模型" /> <SelectValue placeholder="选择 Embedding 模型" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
@@ -1009,13 +1009,16 @@ function KnowledgeEditView({ knowledgeBaseId }: { knowledgeBaseId: string }) {
</SelectContent> </SelectContent>
</Select> </Select>
{documents.length > 0 && ( {documents.length > 0 && (
<p className="mt-2 text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">
Embedding Embedding
</p> </p>
)} )}
</div> </label>
</div> </div>
<DialogFooter> <DialogFooter>
<Button variant="outline" onClick={() => setSettingsOpen(false)}>
</Button>
<Button <Button
disabled={busy || !embeddingId} disabled={busy || !embeddingId}
onClick={() => void saveSettings()} onClick={() => void saveSettings()}
@@ -1028,17 +1031,16 @@ function KnowledgeEditView({ knowledgeBaseId }: { knowledgeBaseId: string }) {
</Dialog> </Dialog>
<Dialog open={searchOpen} onOpenChange={setSearchOpen}> <Dialog open={searchOpen} onOpenChange={setSearchOpen}>
<DialogContent className="sm:max-w-2xl"> <DialogContent className="max-h-[calc(100vh-3rem)] overflow-y-auto sm:max-w-3xl">
<DialogHeader> <DialogHeader>
<DialogTitle></DialogTitle> <DialogTitle></DialogTitle>
<DialogDescription>
</DialogDescription>
</DialogHeader> </DialogHeader>
<div className="space-y-4"> <div className="space-y-4">
<p className="text-sm text-muted-foreground">
</p>
<div className="flex gap-2"> <div className="flex gap-2">
<Input <Input
className="border-hairline-strong bg-background"
placeholder="输入问题,例如:退款规则是什么?" placeholder="输入问题,例如:退款规则是什么?"
value={testQuery} value={testQuery}
onChange={(event) => setTestQuery(event.target.value)} onChange={(event) => setTestQuery(event.target.value)}
@@ -1047,6 +1049,7 @@ function KnowledgeEditView({ knowledgeBaseId }: { knowledgeBaseId: string }) {
}} }}
/> />
<Button <Button
className="shrink-0 gap-2"
disabled={searching || !testQuery.trim()} disabled={searching || !testQuery.trim()}
onClick={() => void testSearch()} onClick={() => void testSearch()}
> >
@@ -1058,29 +1061,36 @@ function KnowledgeEditView({ knowledgeBaseId }: { knowledgeBaseId: string }) {
</Button> </Button>
</div> </div>
<div className="max-h-[50vh] space-y-3 overflow-y-auto"> {searchResults.length === 0 ? (
{searchResults.length === 0 ? ( <div className="rounded-xl border border-dashed border-hairline-strong px-4 py-10 text-center text-sm text-muted-foreground">
<p className="py-4 text-center text-sm text-muted-foreground">
</div>
</p> ) : (
) : ( <div className="max-h-[50vh] divide-y divide-hairline overflow-y-auto rounded-xl border border-hairline">
searchResults.map((result, index) => ( {searchResults.map((result, index) => (
<div <div
key={`${result.document}-${index}`} key={`${result.document}-${index}`}
className="rounded-xl border border-hairline p-3" className="space-y-2 px-4 py-3"
> >
<div className="mb-2 flex justify-between text-xs text-muted-foreground"> <div className="flex justify-between gap-3 text-xs text-muted-foreground">
<span>{result.document}</span> <span className="truncate">{result.document}</span>
<span> {result.score}</span> <span className="shrink-0 tabular-nums">
{result.score}
</span>
</div> </div>
<p className="whitespace-pre-wrap text-sm leading-6"> <p className="whitespace-pre-wrap text-sm leading-6 text-foreground">
{result.content} {result.content}
</p> </p>
</div> </div>
)) ))}
)} </div>
</div> )}
</div> </div>
<DialogFooter>
<Button variant="outline" onClick={() => setSearchOpen(false)}>
</Button>
</DialogFooter>
</DialogContent> </DialogContent>
</Dialog> </Dialog>