fix(knowledge): ensure proper id handling in document operations
refactor(teams): update user deletion to use user_id instead of id refactor(knowledge): optimize data grid locale handling with useCallback style(knowledge): adjust similarity display format in test chunks refactor(knowledge): improve document selection logic and typing
This commit is contained in:
@@ -49,7 +49,7 @@ import {
|
||||
BugReportOutlined as ProcessIcon,
|
||||
Download as DownloadIcon,
|
||||
} from '@mui/icons-material';
|
||||
import { DataGrid, type GridColDef, type GridRowSelectionModel } from '@mui/x-data-grid';
|
||||
import { DataGrid, type GridColDef, type GridRowSelectionModel, type GridRowId } from '@mui/x-data-grid';
|
||||
import { zhCN, enUS } from '@mui/x-data-grid/locales';
|
||||
import type { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
||||
import type { IDocumentInfoFilter } from '@/interfaces/database/document';
|
||||
@@ -147,7 +147,7 @@ const getStatusChip = (status: string) => {
|
||||
};
|
||||
|
||||
const getRunStatusChip = (run: RunningStatus, progress: number) => {
|
||||
const statusConfig = {
|
||||
const statusConfig = {
|
||||
[RunningStatus.UNSTART]: { label: translate('knowledge.runStatus.unstart'), color: 'default' as const },
|
||||
[RunningStatus.RUNNING]: { label: translate('knowledge.runStatus.parsing'), color: 'info' as const },
|
||||
[RunningStatus.CANCEL]: { label: translate('knowledge.runStatus.cancel'), color: 'warning' as const },
|
||||
@@ -163,7 +163,7 @@ const getRunStatusChip = (run: RunningStatus, progress: number) => {
|
||||
<CircularProgress size={16} />
|
||||
<Box sx={{ minWidth: 80 }}>
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
{(progress*100).toFixed(2)}%
|
||||
{(progress * 100).toFixed(2)}%
|
||||
</Typography>
|
||||
<LinearProgress variant="determinate" value={progress} sx={{ height: 4, borderRadius: 2 }} />
|
||||
</Box>
|
||||
@@ -218,10 +218,10 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
||||
const { i18n, t } = useTranslation();
|
||||
|
||||
// 根据当前语言获取DataGrid的localeText
|
||||
const getDataGridLocale = () => {
|
||||
const getDataGridLocale = useCallback(() => {
|
||||
const currentLanguage = i18n.language;
|
||||
return currentLanguage === LanguageAbbreviation.Zh ? zhCN : enUS;
|
||||
};
|
||||
}, [i18n]);
|
||||
|
||||
const handleFilterSubmit = useCallback(() => {
|
||||
const filter = {
|
||||
@@ -346,6 +346,24 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
||||
setSelectedSuffix(typeof value === 'string' ? value.split(',') : value);
|
||||
};
|
||||
|
||||
// 选中数量计算(强类型)
|
||||
const countSelected = (model: GridRowSelectionModel, totalCount: number): number => {
|
||||
const size = model.ids.size ?? 0;
|
||||
return model.type === 'exclude' ? Math.max(totalCount - size, 0) : size;
|
||||
};
|
||||
|
||||
// 获取当前页有效选中 ID 列表(强类型)
|
||||
const getSelectedIdsOnCurrentPage = (model: GridRowSelectionModel, currentFiles: IKnowledgeFile[]): string[] => {
|
||||
if (model.type === 'include') {
|
||||
return Array.from(model.ids).map((id) => id.toString());
|
||||
}
|
||||
const excluded = model.ids;
|
||||
return currentFiles
|
||||
.map((f) => f.id)
|
||||
.filter((id) => !excluded.has(id))
|
||||
.map((id) => id.toString());
|
||||
};
|
||||
|
||||
// 处理分页变化
|
||||
const handlePaginationModelChange = (model: { page: number; pageSize: number }) => {
|
||||
if (model.page !== page - 1) { // DataGrid的page是0-based,我们的是1-based
|
||||
@@ -603,23 +621,22 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
||||
{t('knowledge.uploadFile')}
|
||||
</Button>
|
||||
|
||||
{rowSelectionModel.ids.size > 0 && (
|
||||
{countSelected(rowSelectionModel, total) > 0 && (
|
||||
<>
|
||||
<Button
|
||||
variant="outlined"
|
||||
startIcon={<RefreshIcon />}
|
||||
onClick={() => onReparse(Array.from(rowSelectionModel.ids).map((id) => id.toString()))}
|
||||
onClick={() => onReparse(getSelectedIdsOnCurrentPage(rowSelectionModel, files))}
|
||||
>
|
||||
{t('knowledge.reparse')} ({rowSelectionModel.ids.size})
|
||||
{t('knowledge.reparse')} ({countSelected(rowSelectionModel, total)})
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="error"
|
||||
startIcon={<DeleteIcon />}
|
||||
onClick={() => onDelete(Array.from(rowSelectionModel.ids).map((id) => id.toString()))}
|
||||
onClick={() => onDelete(getSelectedIdsOnCurrentPage(rowSelectionModel, files))}
|
||||
>
|
||||
{t('common.delete')} ({rowSelectionModel.ids.size})
|
||||
{t('common.delete')} ({countSelected(rowSelectionModel, total)})
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
@@ -640,7 +657,9 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
||||
checkboxSelection
|
||||
disableRowSelectionOnClick
|
||||
rowSelectionModel={rowSelectionModel}
|
||||
onRowSelectionModelChange={onRowSelectionModelChange}
|
||||
onRowSelectionModelChange={(model: GridRowSelectionModel) => {
|
||||
onRowSelectionModelChange(model);
|
||||
}}
|
||||
pageSizeOptions={[10, 25, 50, 100]}
|
||||
paginationMode="server"
|
||||
rowCount={total}
|
||||
|
||||
@@ -162,20 +162,20 @@ function TestChunkResult(props: TestChunkResultProps) {
|
||||
</Typography>
|
||||
<Stack direction="row" spacing={1}>
|
||||
<Chip
|
||||
label={t('knowledge.similarity', { value: (chunk.similarity * 100).toFixed(1) })}
|
||||
label={`${t('knowledge.similarity')}: ${(chunk.similarity).toFixed(0)}`}
|
||||
size="small"
|
||||
color="primary"
|
||||
/>
|
||||
{chunk.vector_similarity !== undefined && (
|
||||
<Chip
|
||||
label={t('knowledge.vectorSimilarity', { value: (chunk.vector_similarity * 100).toFixed(1) })}
|
||||
label={`${t('knowledge.vectorSimilarity')}: ${(chunk.vector_similarity).toFixed(2)}`}
|
||||
size="small"
|
||||
variant="outlined"
|
||||
/>
|
||||
)}
|
||||
{chunk.term_similarity !== undefined && (
|
||||
<Chip
|
||||
label={t('knowledge.termSimilarity', { value: (chunk.term_similarity * 100).toFixed(1) })}
|
||||
label={`${t('knowledge.termSimilarity')}: ${(chunk.term_similarity).toFixed(0)}`}
|
||||
size="small"
|
||||
variant="outlined"
|
||||
/>
|
||||
|
||||
@@ -134,7 +134,7 @@ function KnowledgeBaseDetail() {
|
||||
// 删除文件
|
||||
const handleDeleteFiles = async () => {
|
||||
try {
|
||||
await deleteDocuments(Array.from(rowSelectionModel.ids) as string[]);
|
||||
await deleteDocuments(Array.from(rowSelectionModel.ids).map((id) => id.toString()));
|
||||
setDeleteDialogOpen(false);
|
||||
setRowSelectionModel({
|
||||
type: 'include',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useCallback } from 'react';
|
||||
import { Box, Grid, Paper, Typography, IconButton, TextField, Tabs, Tab, Fab, Avatar, Chip, Dialog, DialogTitle, DialogContent, DialogActions, Button, Card, CardContent, Divider } from '@mui/material';
|
||||
import { DataGrid, type GridColDef } from '@mui/x-data-grid';
|
||||
import {
|
||||
@@ -10,7 +10,6 @@ import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useKnowledgeOverview, useKnowledgeDetail } from '@/hooks/knowledge-hooks';
|
||||
import logger from '@/utils/logger';
|
||||
import i18n from '@/locales';
|
||||
import { enUS, zhCN } from '@mui/x-data-grid/locales';
|
||||
import KnowledgeBreadcrumbs from './components/KnowledgeBreadcrumbs';
|
||||
import { LanguageAbbreviation } from '@/constants/common';
|
||||
@@ -38,14 +37,14 @@ interface KnowledgeLogsPageProps {
|
||||
}
|
||||
|
||||
function KnowledgeLogsPage({ embedded = false, kbId: kbIdProp }: KnowledgeLogsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const [paginationModel, setPaginationModel] = React.useState({ page: 0, pageSize: 50 });
|
||||
|
||||
// 根据当前语言获取DataGrid的localeText
|
||||
const getDataGridLocale = () => {
|
||||
const getDataGridLocale = useCallback(() => {
|
||||
const currentLanguage = i18n.language;
|
||||
return currentLanguage === LanguageAbbreviation.Zh ? zhCN : enUS;
|
||||
};
|
||||
}, [i18n]);
|
||||
|
||||
// 路由参数与数据Hook
|
||||
const { id: kbIdParam = '' } = useParams();
|
||||
|
||||
@@ -178,7 +178,7 @@ function TeamsSetting() {
|
||||
<IconButton
|
||||
size="small"
|
||||
color="error"
|
||||
onClick={() => handleDeleteUser(user.id)}
|
||||
onClick={() => handleDeleteUser(user.user_id)}
|
||||
>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
|
||||
Reference in New Issue
Block a user