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,
|
BugReportOutlined as ProcessIcon,
|
||||||
Download as DownloadIcon,
|
Download as DownloadIcon,
|
||||||
} from '@mui/icons-material';
|
} 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 { zhCN, enUS } from '@mui/x-data-grid/locales';
|
||||||
import type { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
import type { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
||||||
import type { IDocumentInfoFilter } from '@/interfaces/database/document';
|
import type { IDocumentInfoFilter } from '@/interfaces/database/document';
|
||||||
@@ -147,7 +147,7 @@ const getStatusChip = (status: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getRunStatusChip = (run: RunningStatus, progress: number) => {
|
const getRunStatusChip = (run: RunningStatus, progress: number) => {
|
||||||
const statusConfig = {
|
const statusConfig = {
|
||||||
[RunningStatus.UNSTART]: { label: translate('knowledge.runStatus.unstart'), color: 'default' as const },
|
[RunningStatus.UNSTART]: { label: translate('knowledge.runStatus.unstart'), color: 'default' as const },
|
||||||
[RunningStatus.RUNNING]: { label: translate('knowledge.runStatus.parsing'), color: 'info' as const },
|
[RunningStatus.RUNNING]: { label: translate('knowledge.runStatus.parsing'), color: 'info' as const },
|
||||||
[RunningStatus.CANCEL]: { label: translate('knowledge.runStatus.cancel'), color: 'warning' 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} />
|
<CircularProgress size={16} />
|
||||||
<Box sx={{ minWidth: 80 }}>
|
<Box sx={{ minWidth: 80 }}>
|
||||||
<Typography variant="caption" color="text.secondary">
|
<Typography variant="caption" color="text.secondary">
|
||||||
{(progress*100).toFixed(2)}%
|
{(progress * 100).toFixed(2)}%
|
||||||
</Typography>
|
</Typography>
|
||||||
<LinearProgress variant="determinate" value={progress} sx={{ height: 4, borderRadius: 2 }} />
|
<LinearProgress variant="determinate" value={progress} sx={{ height: 4, borderRadius: 2 }} />
|
||||||
</Box>
|
</Box>
|
||||||
@@ -218,10 +218,10 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
|||||||
const { i18n, t } = useTranslation();
|
const { i18n, t } = useTranslation();
|
||||||
|
|
||||||
// 根据当前语言获取DataGrid的localeText
|
// 根据当前语言获取DataGrid的localeText
|
||||||
const getDataGridLocale = () => {
|
const getDataGridLocale = useCallback(() => {
|
||||||
const currentLanguage = i18n.language;
|
const currentLanguage = i18n.language;
|
||||||
return currentLanguage === LanguageAbbreviation.Zh ? zhCN : enUS;
|
return currentLanguage === LanguageAbbreviation.Zh ? zhCN : enUS;
|
||||||
};
|
}, [i18n]);
|
||||||
|
|
||||||
const handleFilterSubmit = useCallback(() => {
|
const handleFilterSubmit = useCallback(() => {
|
||||||
const filter = {
|
const filter = {
|
||||||
@@ -346,6 +346,24 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
|||||||
setSelectedSuffix(typeof value === 'string' ? value.split(',') : value);
|
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 }) => {
|
const handlePaginationModelChange = (model: { page: number; pageSize: number }) => {
|
||||||
if (model.page !== page - 1) { // DataGrid的page是0-based,我们的是1-based
|
if (model.page !== page - 1) { // DataGrid的page是0-based,我们的是1-based
|
||||||
@@ -603,23 +621,22 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
|||||||
{t('knowledge.uploadFile')}
|
{t('knowledge.uploadFile')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{rowSelectionModel.ids.size > 0 && (
|
{countSelected(rowSelectionModel, total) > 0 && (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
startIcon={<RefreshIcon />}
|
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>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="error"
|
color="error"
|
||||||
startIcon={<DeleteIcon />}
|
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>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -640,7 +657,9 @@ const DocumentListComponent: React.FC<DocumentListComponentProps> = ({
|
|||||||
checkboxSelection
|
checkboxSelection
|
||||||
disableRowSelectionOnClick
|
disableRowSelectionOnClick
|
||||||
rowSelectionModel={rowSelectionModel}
|
rowSelectionModel={rowSelectionModel}
|
||||||
onRowSelectionModelChange={onRowSelectionModelChange}
|
onRowSelectionModelChange={(model: GridRowSelectionModel) => {
|
||||||
|
onRowSelectionModelChange(model);
|
||||||
|
}}
|
||||||
pageSizeOptions={[10, 25, 50, 100]}
|
pageSizeOptions={[10, 25, 50, 100]}
|
||||||
paginationMode="server"
|
paginationMode="server"
|
||||||
rowCount={total}
|
rowCount={total}
|
||||||
|
|||||||
@@ -162,20 +162,20 @@ function TestChunkResult(props: TestChunkResultProps) {
|
|||||||
</Typography>
|
</Typography>
|
||||||
<Stack direction="row" spacing={1}>
|
<Stack direction="row" spacing={1}>
|
||||||
<Chip
|
<Chip
|
||||||
label={t('knowledge.similarity', { value: (chunk.similarity * 100).toFixed(1) })}
|
label={`${t('knowledge.similarity')}: ${(chunk.similarity).toFixed(0)}`}
|
||||||
size="small"
|
size="small"
|
||||||
color="primary"
|
color="primary"
|
||||||
/>
|
/>
|
||||||
{chunk.vector_similarity !== undefined && (
|
{chunk.vector_similarity !== undefined && (
|
||||||
<Chip
|
<Chip
|
||||||
label={t('knowledge.vectorSimilarity', { value: (chunk.vector_similarity * 100).toFixed(1) })}
|
label={`${t('knowledge.vectorSimilarity')}: ${(chunk.vector_similarity).toFixed(2)}`}
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{chunk.term_similarity !== undefined && (
|
{chunk.term_similarity !== undefined && (
|
||||||
<Chip
|
<Chip
|
||||||
label={t('knowledge.termSimilarity', { value: (chunk.term_similarity * 100).toFixed(1) })}
|
label={`${t('knowledge.termSimilarity')}: ${(chunk.term_similarity).toFixed(0)}`}
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ function KnowledgeBaseDetail() {
|
|||||||
// 删除文件
|
// 删除文件
|
||||||
const handleDeleteFiles = async () => {
|
const handleDeleteFiles = async () => {
|
||||||
try {
|
try {
|
||||||
await deleteDocuments(Array.from(rowSelectionModel.ids) as string[]);
|
await deleteDocuments(Array.from(rowSelectionModel.ids).map((id) => id.toString()));
|
||||||
setDeleteDialogOpen(false);
|
setDeleteDialogOpen(false);
|
||||||
setRowSelectionModel({
|
setRowSelectionModel({
|
||||||
type: 'include',
|
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 { 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 { DataGrid, type GridColDef } from '@mui/x-data-grid';
|
||||||
import {
|
import {
|
||||||
@@ -10,7 +10,6 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useKnowledgeOverview, useKnowledgeDetail } from '@/hooks/knowledge-hooks';
|
import { useKnowledgeOverview, useKnowledgeDetail } from '@/hooks/knowledge-hooks';
|
||||||
import logger from '@/utils/logger';
|
import logger from '@/utils/logger';
|
||||||
import i18n from '@/locales';
|
|
||||||
import { enUS, zhCN } from '@mui/x-data-grid/locales';
|
import { enUS, zhCN } from '@mui/x-data-grid/locales';
|
||||||
import KnowledgeBreadcrumbs from './components/KnowledgeBreadcrumbs';
|
import KnowledgeBreadcrumbs from './components/KnowledgeBreadcrumbs';
|
||||||
import { LanguageAbbreviation } from '@/constants/common';
|
import { LanguageAbbreviation } from '@/constants/common';
|
||||||
@@ -38,14 +37,14 @@ interface KnowledgeLogsPageProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function KnowledgeLogsPage({ embedded = false, kbId: kbIdProp }: KnowledgeLogsPageProps) {
|
function KnowledgeLogsPage({ embedded = false, kbId: kbIdProp }: KnowledgeLogsPageProps) {
|
||||||
const { t } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const [paginationModel, setPaginationModel] = React.useState({ page: 0, pageSize: 50 });
|
const [paginationModel, setPaginationModel] = React.useState({ page: 0, pageSize: 50 });
|
||||||
|
|
||||||
// 根据当前语言获取DataGrid的localeText
|
// 根据当前语言获取DataGrid的localeText
|
||||||
const getDataGridLocale = () => {
|
const getDataGridLocale = useCallback(() => {
|
||||||
const currentLanguage = i18n.language;
|
const currentLanguage = i18n.language;
|
||||||
return currentLanguage === LanguageAbbreviation.Zh ? zhCN : enUS;
|
return currentLanguage === LanguageAbbreviation.Zh ? zhCN : enUS;
|
||||||
};
|
}, [i18n]);
|
||||||
|
|
||||||
// 路由参数与数据Hook
|
// 路由参数与数据Hook
|
||||||
const { id: kbIdParam = '' } = useParams();
|
const { id: kbIdParam = '' } = useParams();
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ function TeamsSetting() {
|
|||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
color="error"
|
color="error"
|
||||||
onClick={() => handleDeleteUser(user.id)}
|
onClick={() => handleDeleteUser(user.user_id)}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user