chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -121,7 +121,7 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
setCurrentPhotoId,
|
||||
reload: reloadAsync,
|
||||
onCancel: () => {
|
||||
// 重置url参数
|
||||
// Reset url parameters
|
||||
resetUrlQueryParams();
|
||||
},
|
||||
onSubmit: () => {
|
||||
@@ -129,12 +129,12 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
},
|
||||
});
|
||||
|
||||
// 手动控制 data 加载时机
|
||||
// Manually control data loading timing
|
||||
useEffect(() => {
|
||||
if (dataSetDetail?.dataset_id) {
|
||||
reloadAsync();
|
||||
|
||||
// 重新加载时,回到最顶部
|
||||
// When reloading, return to the top
|
||||
ref.current?.scrollTo?.({
|
||||
top: 0,
|
||||
behavior: 'smooth',
|
||||
@@ -142,7 +142,7 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
}
|
||||
}, [searchValue, photoFilterValue, dataSetDetail?.dataset_id]);
|
||||
|
||||
// 自动打开编辑弹窗
|
||||
// Automatically open the editing pop-up window
|
||||
useEffect(() => {
|
||||
if (shouldAutoOpenDetailModal) {
|
||||
if (firstAutoOpenEditDocumentId) {
|
||||
@@ -182,10 +182,10 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
caption: originCaption,
|
||||
status: originStatus,
|
||||
} = item;
|
||||
// 此处使用 progressMap 可以保持不断刷新直至完成
|
||||
// Use progressMap here to keep refreshing until completion
|
||||
// @ts-expect-error -- linter-disable-autofix
|
||||
const status = progressMap[document_id]?.status || originStatus;
|
||||
// 使用 progressMap 获取最新的caption
|
||||
// Use progressMap to get the latest caption
|
||||
const caption =
|
||||
// @ts-expect-error -- linter-disable-autofix
|
||||
(progressMap[document_id] as ProgressItem & PhotoInfo)
|
||||
@@ -202,11 +202,11 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
|
||||
const handleDelete = () => {
|
||||
UIModal.error({
|
||||
// 必填参数,统一 confirm modal 的样式
|
||||
// Required parameters to confirm modal style
|
||||
className: styles['confirm-modal'],
|
||||
closeIcon: <IconCloseKnowledge />,
|
||||
|
||||
// 自定义参数
|
||||
// custom parameters
|
||||
title: I18n.t('kl2_007'),
|
||||
content: I18n.t(
|
||||
'dataset_detail_table_deleteModel_description',
|
||||
@@ -247,7 +247,7 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
const isAudiFailed =
|
||||
originStatus === DocumentStatus.AuditFailed;
|
||||
const getCaption = () => {
|
||||
// 违规图片
|
||||
// Illegal pictures
|
||||
if (isAudiFailed) {
|
||||
return (
|
||||
<span>
|
||||
@@ -256,7 +256,7 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
);
|
||||
}
|
||||
|
||||
// 处理失败
|
||||
// Processing failed
|
||||
if (status === DocumentStatus.Failed) {
|
||||
return (
|
||||
<span className={styles['failed-tag']}>
|
||||
@@ -265,7 +265,7 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
);
|
||||
}
|
||||
|
||||
// 处理中
|
||||
// Processing
|
||||
if (status === DocumentStatus.Processing) {
|
||||
return (
|
||||
<span className={styles['processing-tag']}>
|
||||
@@ -274,12 +274,12 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
);
|
||||
}
|
||||
|
||||
// 已标注
|
||||
// marked
|
||||
if (hasCaption) {
|
||||
return caption;
|
||||
}
|
||||
|
||||
// 未标注
|
||||
// unmarked
|
||||
return I18n.t('knowledge_photo_016');
|
||||
};
|
||||
|
||||
@@ -295,7 +295,7 @@ export const ImageKnowledgeWorkspace: FC<
|
||||
) : (
|
||||
<Image
|
||||
src={url}
|
||||
// 仅设置宽度,高度会按图片原比例自动缩放
|
||||
// Only set the width, and the height will be automatically scaled according to the original scale of the picture.
|
||||
width={222}
|
||||
preview={false}
|
||||
onClick={handleEdit}
|
||||
|
||||
@@ -60,7 +60,7 @@ export const usePhotoList = (
|
||||
? true
|
||||
: filterPhotoType === FilterPhotoType.NoCaption
|
||||
? false
|
||||
: // 传 undefined 代表返回全部
|
||||
: // Pass undefined to return all
|
||||
undefined,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -78,7 +78,7 @@ export const ImportKnowledgeSourceButton = ({
|
||||
onSourceChange(unitType);
|
||||
return;
|
||||
}
|
||||
/** 默认跳转到upload */
|
||||
/** Default jump to upload */
|
||||
const formatType = dataSetDetail?.format_type;
|
||||
const docID = documentList?.[0]?.document_id;
|
||||
const params: Record<string, string> = {
|
||||
|
||||
@@ -23,7 +23,7 @@ import { type Dataset, type DocumentInfo } from '@coze-arch/bot-api/knowledge';
|
||||
import { DocumentStatus, FormatType } from '@coze-arch/bot-api/knowledge';
|
||||
|
||||
/**
|
||||
* 处理表格类型数据集的禁用提示
|
||||
* Disable hints for working with table-type datasets
|
||||
*/
|
||||
export const getTableFormatTooltip = (documentList: DocumentInfo[]): string => {
|
||||
const docInfo = documentList?.[0];
|
||||
@@ -44,7 +44,7 @@ export const getTableFormatTooltip = (documentList: DocumentInfo[]): string => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理默认类型数据集的禁用提示
|
||||
* Disable hints for handling default type datasets
|
||||
*/
|
||||
export const getDefaultFormatTooltip = (dataSetDetail: Dataset): string => {
|
||||
// @ts-expect-error -- linter-disable-autofix
|
||||
@@ -60,10 +60,10 @@ export const getDefaultFormatTooltip = (dataSetDetail: Dataset): string => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建按钮禁用时的提示文本
|
||||
* @param dataSetDetail - 数据集详情
|
||||
* @param documentList - 文档列表
|
||||
* @returns 提示文本
|
||||
* Create prompt text when button is disabled
|
||||
* @param dataSetDetail - Dataset Details
|
||||
* @param documentList - Document List
|
||||
* @Returns prompt text
|
||||
*/
|
||||
export const createBtnDisableToolTip = (
|
||||
dataSetDetail: Dataset,
|
||||
|
||||
@@ -121,12 +121,12 @@ export const getUpdatedDataset = (
|
||||
actionType: ActionType,
|
||||
dataSetDetail: Dataset,
|
||||
): KnowledgeInfo[] => {
|
||||
// 更新后的bot知识库
|
||||
// Updated bot knowledge base
|
||||
let updatedDatasetList: KnowledgeInfo[] = [];
|
||||
// 原本的bot知识库内容
|
||||
// The original bot knowledge base content
|
||||
let originDataset: KnowledgeInfo[] = [];
|
||||
|
||||
// 兼容json版本的dataset,FG全量后删除
|
||||
// Compatible with the json version of dataset, delete it after FG is full
|
||||
if ('dataset' in dataset) {
|
||||
originDataset = dataset?.dataset ?? [];
|
||||
} else {
|
||||
@@ -147,7 +147,7 @@ export const getUpdatedDataset = (
|
||||
return updatedDatasetList;
|
||||
};
|
||||
|
||||
// 更新bot知识库逻辑
|
||||
// Update bot knowledge base logic
|
||||
export const handleDatasetUpdate = async ({
|
||||
botInfo,
|
||||
botId,
|
||||
@@ -181,7 +181,7 @@ export const handleDatasetUpdate = async ({
|
||||
updateSuccess();
|
||||
};
|
||||
|
||||
// 根据不同botInfo信息 获取不同的bot原有的dataset
|
||||
// Get the original dataset of different bots according to different botInfo information
|
||||
export const getDatasetInfo = (
|
||||
botInfo: GetDraftBotInfoAgwData | undefined,
|
||||
agentId: string,
|
||||
|
||||
@@ -96,7 +96,7 @@ export const useBeforeKnowledgeIDEClose = ({
|
||||
};
|
||||
|
||||
const handleBotIdeBack = () => {
|
||||
// Bot IDE检查是否有绑定knowledge,如果有绑定知识库正常关闭,没有绑定确认提示处理
|
||||
// Bot IDE checks whether there is binding knowledge. If there is binding knowledge base, it will be closed normally, and there is no binding confirmation prompt.
|
||||
if (hasAddDataset) {
|
||||
Modal.confirm({
|
||||
title: I18n.t('bot_ide_knowledge_confirm_title'),
|
||||
@@ -124,17 +124,17 @@ export const useBeforeKnowledgeIDEClose = ({
|
||||
console.error(error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
// 无论成功无论都跳转一次
|
||||
// Jump once regardless of success
|
||||
handleFullModalBack();
|
||||
}
|
||||
},
|
||||
onCancel: () => {
|
||||
// 取消,正常跳转
|
||||
// Cancel, jump normally
|
||||
handleFullModalBack();
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// 正常绑定不做弹窗拦截
|
||||
// Normal binding does not do pop-up interception
|
||||
handleFullModalBack();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -92,7 +92,7 @@ export const TableKnowledgeWorkspace = ({
|
||||
slices,
|
||||
]);
|
||||
|
||||
// 创建 UI Context 值
|
||||
// Creating UI Context Values
|
||||
const uiContextValue = {
|
||||
tableViewRef,
|
||||
isLoadingMoreSliceList,
|
||||
@@ -100,7 +100,7 @@ export const TableKnowledgeWorkspace = ({
|
||||
isShowAddBtn,
|
||||
};
|
||||
|
||||
// 创建数据 Context 值
|
||||
// Creating Data Context Values
|
||||
const dataContextValue = {
|
||||
sliceListData: sliceListData || { list: [], total: 0 },
|
||||
curIndex,
|
||||
@@ -108,7 +108,7 @@ export const TableKnowledgeWorkspace = ({
|
||||
delSliceIds,
|
||||
};
|
||||
|
||||
// 创建操作 Context 值
|
||||
// Create Action Context Value
|
||||
const actionsContextValue = {
|
||||
setCurIndex,
|
||||
setCurSliceId,
|
||||
|
||||
@@ -38,7 +38,7 @@ import { useTableUI } from '../context/table-ui-context';
|
||||
import { useTableData } from '../context/table-data-context';
|
||||
import { useTableActions } from '../context/table-actions-context';
|
||||
|
||||
// 表格内容组件
|
||||
// Table Content Component
|
||||
const TableContent = () => {
|
||||
const knowledgeIDEBiz = useKnowledgeParamsStore(state => state.params.biz);
|
||||
const documentList = useKnowledgeStore(state => state.documentList);
|
||||
@@ -55,14 +55,14 @@ const TableContent = () => {
|
||||
|
||||
const canEdit = Boolean(useKnowledgeStore(state => state.canEdit));
|
||||
|
||||
// 删除切片弹窗
|
||||
// Delete slice pop-up
|
||||
const { deleteSliceModalNode, openDeleteSliceModal } = useDeleteSliceModal();
|
||||
|
||||
// 编辑slice弹窗
|
||||
// Edit slice pop-up
|
||||
const { tableSegmentModalNode, openTableSegmentModal } =
|
||||
useTableSegmentModal();
|
||||
|
||||
// 获取表格操作方法
|
||||
// Get table manipulation method
|
||||
const { deleteSlice, rowUpdateSliceData, modalEditSlice } =
|
||||
useTableSliceOperations({
|
||||
openDeleteSliceModal,
|
||||
@@ -71,7 +71,7 @@ const TableContent = () => {
|
||||
|
||||
const { tableH } = useTableHeight();
|
||||
|
||||
// 如果没有数据,直接返回空
|
||||
// If there is no data, return to empty directly
|
||||
if (!slices?.length) {
|
||||
return null;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ const TableContent = () => {
|
||||
);
|
||||
};
|
||||
|
||||
// 添加行按钮组件
|
||||
// Add line button component
|
||||
const AddRowButton = () => {
|
||||
const { isShowAddBtn } = useTableUI();
|
||||
const documentList = useKnowledgeStore(state => state.documentList);
|
||||
@@ -164,12 +164,12 @@ const AddRowButton = () => {
|
||||
);
|
||||
};
|
||||
|
||||
// 主组件
|
||||
// main component
|
||||
export const TableDataView = () => {
|
||||
const { sliceListData } = useTableData();
|
||||
const slices = sliceListData?.list;
|
||||
|
||||
// 如果没有数据,只显示添加按钮
|
||||
// If there is no data, only the add button is displayed.
|
||||
if (!slices?.length) {
|
||||
return <AddRowButton />;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { createContext, useContext } from 'react';
|
||||
|
||||
import { type DatasetDataScrollList } from '@/service';
|
||||
|
||||
// 表格操作相关的 Context
|
||||
// Context related to table manipulation
|
||||
interface TableActionsContextType {
|
||||
setCurIndex: (index: number | ((prev: number) => number)) => void;
|
||||
setCurSliceId: (id: string | ((prev: string) => string)) => void;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { createContext, useContext } from 'react';
|
||||
|
||||
import { type DatasetDataScrollList } from '@/service';
|
||||
|
||||
// 表格数据相关的 Context
|
||||
// Context related to tabular data
|
||||
interface TableDataContextType {
|
||||
sliceListData: DatasetDataScrollList;
|
||||
curIndex: number;
|
||||
|
||||
@@ -19,7 +19,7 @@ import { type MutableRefObject } from 'react';
|
||||
|
||||
import { type TableViewMethods } from '@coze-common/table-view';
|
||||
|
||||
// 表格 UI 相关的 Context
|
||||
// Context related to table UI
|
||||
interface TableUIContextType {
|
||||
tableViewRef: MutableRefObject<TableViewMethods | null>;
|
||||
isLoadingMoreSliceList: boolean;
|
||||
|
||||
@@ -30,7 +30,7 @@ export const useCreateSlice = () => {
|
||||
const documentList = useKnowledgeStore(state => state.documentList);
|
||||
const curDoc = documentList?.[0];
|
||||
|
||||
// 创建切片
|
||||
// Create slice
|
||||
const { createSlice } = useCreateSliceService({
|
||||
onReload: (createItem: ISliceInfo) => {
|
||||
const list =
|
||||
|
||||
@@ -25,7 +25,7 @@ import { useScrollListSliceReq } from '@/service';
|
||||
export const useGetSliceListData = () => {
|
||||
const documentList = useKnowledgeStore(state => state.documentList);
|
||||
const curDocId = documentList?.[0]?.document_id;
|
||||
// 加载数据
|
||||
// load data
|
||||
const {
|
||||
data: sliceListData,
|
||||
mutate: mutateSliceListData,
|
||||
|
||||
@@ -20,7 +20,7 @@ const ADD_BTN_HEIGHT = 56;
|
||||
|
||||
export const useScroll = () => {
|
||||
const { sliceListData } = useTableData();
|
||||
// 滚动表格到底部
|
||||
// Scroll table to the bottom
|
||||
const scrollTableBodyToBottom = () => {
|
||||
const bodyDom = document.querySelector(
|
||||
'.table-view-box .semi-table-container>.semi-table-body',
|
||||
|
||||
@@ -24,7 +24,7 @@ export const useTableHeight = () => {
|
||||
const { sliceListData } = useTableData();
|
||||
const [tableH, setTableHeight] = useState<number | string>(0);
|
||||
|
||||
// 更新表格高度
|
||||
// Update table height
|
||||
useEffect(() => {
|
||||
const h = tableViewRef?.current?.getTableHeight();
|
||||
if (h) {
|
||||
|
||||
@@ -35,7 +35,7 @@ export const useAddRow = ({
|
||||
const { sliceListData } = useTableData();
|
||||
const { mutateSliceListData } = useTableActions();
|
||||
const handleAddRow = () => {
|
||||
/** 先增加容器的高度 */
|
||||
/** Increase the height of the container first */
|
||||
increaseTableHeight(ADD_BTN_HEIGHT);
|
||||
const items = JSON.parse(sliceListData?.list[0]?.content ?? '[]');
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ import { useTableData } from '../../context/table-data-context';
|
||||
import { useTableActions } from '../../context/table-actions-context';
|
||||
|
||||
export const useDeleteSliceModal = () => {
|
||||
// 外部数据
|
||||
// external data
|
||||
const dataSetDetail = useKnowledgeStore(state => state.dataSetDetail);
|
||||
const setDataSetDetail = useKnowledgeStore(state => state.setDataSetDetail);
|
||||
const documentList = useKnowledgeStore(state => state.documentList);
|
||||
|
||||
// 内部数据
|
||||
// internal data
|
||||
const { sliceListData, delSliceIds } = useTableData();
|
||||
const { tableViewRef } = useTableUI();
|
||||
const { mutateSliceListData } = useTableActions();
|
||||
@@ -41,7 +41,7 @@ export const useDeleteSliceModal = () => {
|
||||
const curDoc = documentList?.[0];
|
||||
const slices = sliceListData?.list;
|
||||
|
||||
// 删除切片弹窗
|
||||
// Delete slice pop-up
|
||||
const { node: deleteSliceModalNode, delete: openDeleteSliceModal } =
|
||||
useSliceDeleteModal({
|
||||
onDel: async () => {
|
||||
|
||||
@@ -33,7 +33,7 @@ export const useTableSegmentModal = () => {
|
||||
const { mutateSliceListData } = useTableActions();
|
||||
const curDoc = documentList?.[0];
|
||||
|
||||
// 表格分段弹窗
|
||||
// table segmentation pop-up
|
||||
const {
|
||||
node: tableSegmentModalNode,
|
||||
edit: openTableSegmentModal,
|
||||
|
||||
@@ -48,11 +48,11 @@ export const useTableSliceOperations = ({
|
||||
return;
|
||||
}
|
||||
|
||||
/** 新增的行 */
|
||||
/** new row */
|
||||
const addIndex = indexs.filter(i => !slices[i].slice_id);
|
||||
const addIds = addIndex.map(i => slices[i]?.addId);
|
||||
const oldIndex = indexs.filter(v => !addIndex.includes(v));
|
||||
// 确保过滤掉undefined值
|
||||
// Make sure to filter out undefined values
|
||||
const sliceIds = oldIndex
|
||||
.map(i => slices[i].slice_id)
|
||||
.filter(Boolean) as string[];
|
||||
@@ -129,12 +129,12 @@ export const useTableSliceOperations = ({
|
||||
if (sliceId) {
|
||||
await updateSlice(sliceId as string, updateContent, updateValue);
|
||||
} else {
|
||||
/** 新增分片 */
|
||||
/** Add sharding */
|
||||
const createParams = await handleCreateSlice(updateContent);
|
||||
if (createParams && createSlice && curDoc?.document_id) {
|
||||
// 调用传入的createSlice方法创建新的分片
|
||||
// Call the createSlice method passed in to create a new sharding.
|
||||
try {
|
||||
// 这里需要使用props中传入的createSlice方法来调用API
|
||||
// Here you need to use the createSlice method passed in the props to call the API.
|
||||
await createSlice({
|
||||
document_id: curDoc.document_id,
|
||||
raw_text: updateContent,
|
||||
@@ -145,7 +145,7 @@ export const useTableSliceOperations = ({
|
||||
}
|
||||
}
|
||||
|
||||
// 改为接口请求成功后才更新
|
||||
// Change to update after the interface request is successful
|
||||
if (slices) {
|
||||
return true;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ export const useTableSliceOperations = ({
|
||||
}
|
||||
};
|
||||
|
||||
/** 弹窗编辑切片 */
|
||||
/** Pop-up editing slice */
|
||||
const handleModalEditSlice = (_record: TableViewRecord, index: number) => {
|
||||
if (!slices || index < 0 || index >= slices.length) {
|
||||
return;
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
import { TableKnowledgeWorkspace } from './components/main';
|
||||
|
||||
// 导出组件
|
||||
// export component
|
||||
export { TableKnowledgeWorkspace };
|
||||
export type { TableKnowledgeWorkspaceProps } from './components/main';
|
||||
|
||||
@@ -66,7 +66,7 @@ const getTableCacheWidthMap = (tableKey: string) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* slice 数据转换为 TableView 组件接收的数据类型
|
||||
* Slice data to the data type received by the TableView component
|
||||
*/
|
||||
|
||||
export const getTableRenderColumnsData = ({
|
||||
@@ -158,7 +158,7 @@ export const getTableRenderColumnsData = ({
|
||||
/>
|
||||
);
|
||||
}
|
||||
// 针对违规内容高亮处理
|
||||
// Highlighting violations
|
||||
const isAudiFailed = record?.status === SliceStatus.AuditFailed;
|
||||
const textRender = () => (
|
||||
<div className={`w-full ${isAudiFailed ? 'text-red-500' : ''}`}>
|
||||
|
||||
@@ -75,7 +75,7 @@ export const DocSelector = ({
|
||||
}
|
||||
try {
|
||||
const regx = new RegExp(searchValue);
|
||||
// 搜索结果不展示「全部内容」选项
|
||||
// Search results do not show the "All Content" option
|
||||
return (
|
||||
(op.value !== 'all' && op.value === value) ||
|
||||
(op?.text as string)?.match(regx)
|
||||
|
||||
@@ -48,7 +48,7 @@ export const LevelContent: React.FC<LevelContentProps> = ({
|
||||
const canEdit = useKnowledgeStore(state => state.canEdit);
|
||||
const searchValue = useKnowledgeStore(state => state.searchValue);
|
||||
|
||||
// 转换层级分段数据为编辑器可用格式
|
||||
// Convert hierarchical segmented data into an editor-usable format
|
||||
const renderLevelSegmentsData = levelSegments.map(item =>
|
||||
createLevelDocumentChunkByLevelSegment(item),
|
||||
);
|
||||
|
||||
@@ -76,10 +76,10 @@ export const TextKnowledgeWorkspace = ({
|
||||
const documentList = useKnowledgeStore(state => state.documentList);
|
||||
const resourceNavigate = useDataNavigate();
|
||||
|
||||
// 初始化选择第一个文档
|
||||
// Initialize to select the first document
|
||||
useInitSelectFirstDoc();
|
||||
|
||||
// 文档管理
|
||||
// Document Management
|
||||
const {
|
||||
handleSelectDocument,
|
||||
handleRenameDocument,
|
||||
@@ -89,15 +89,15 @@ export const TextKnowledgeWorkspace = ({
|
||||
reloadDataset,
|
||||
});
|
||||
|
||||
// 文档基本信息
|
||||
// Documentation basic information
|
||||
const { curDoc, curDocId, isProcessing, processFinished, datasetId } =
|
||||
useDocumentInfo(progressMap);
|
||||
|
||||
// 文件预览
|
||||
// file preview
|
||||
const { showOriginalFile, handleToggleOriginalFile } =
|
||||
useFilePreview(curDocId);
|
||||
|
||||
// 文档片段数据
|
||||
// document fragment data
|
||||
const { loading, renderData, handleContentChange, reload } = useSliceData({
|
||||
curDocId,
|
||||
datasetId,
|
||||
@@ -107,7 +107,7 @@ export const TextKnowledgeWorkspace = ({
|
||||
rollbackDocumentSelection,
|
||||
});
|
||||
|
||||
// 层级分段数据
|
||||
// hierarchical segmented data
|
||||
const {
|
||||
levelSegments,
|
||||
selectionIDs,
|
||||
@@ -119,11 +119,11 @@ export const TextKnowledgeWorkspace = ({
|
||||
curDoc,
|
||||
});
|
||||
|
||||
// 片段计数器
|
||||
// fragment counter
|
||||
const { handleIncreaseSliceCount, handleDecreaseSliceCount } =
|
||||
useSliceCounter();
|
||||
|
||||
// 模态框
|
||||
// modal box
|
||||
const {
|
||||
deleteModalNode,
|
||||
showDeleteModal,
|
||||
@@ -153,10 +153,10 @@ export const TextKnowledgeWorkspace = ({
|
||||
},
|
||||
});
|
||||
|
||||
// 文档选项
|
||||
// Document Options
|
||||
const docOptions = getDocumentOptions(documentList, progressMap);
|
||||
|
||||
// 处理重新分段
|
||||
// Handle re-segmentation
|
||||
const handleResegment = () => {
|
||||
const isLocalText = Boolean(
|
||||
curDoc?.source_type === DocumentSource.Document,
|
||||
|
||||
@@ -39,7 +39,7 @@ import {
|
||||
import { DocTag } from './doc-tag';
|
||||
import { DocSelector } from './doc-selector';
|
||||
|
||||
// 文档基本信息
|
||||
// Documentation basic information
|
||||
export interface DocumentData {
|
||||
curDoc?: DocumentInfo;
|
||||
curDocId: string;
|
||||
@@ -47,13 +47,13 @@ export interface DocumentData {
|
||||
docOptions: OptionProps[];
|
||||
}
|
||||
|
||||
// 文件预览相关
|
||||
// File preview related
|
||||
export interface FilePreviewData {
|
||||
showOriginalFile: boolean;
|
||||
fileUrl?: string;
|
||||
}
|
||||
|
||||
// 文档操作回调
|
||||
// document action callback
|
||||
export interface DocumentActions {
|
||||
onChangeDoc: (docId: string) => void;
|
||||
onRenameDoc: (docId: string, newName: string) => void;
|
||||
@@ -64,7 +64,7 @@ export interface DocumentActions {
|
||||
reloadDataset?: () => void;
|
||||
}
|
||||
|
||||
// 自定义UI元素
|
||||
// Custom UI elements
|
||||
export interface CustomUIElements {
|
||||
linkOriginUrlButton?: ReactNode;
|
||||
fetchSliceButton?: ReactNode;
|
||||
@@ -92,7 +92,7 @@ export const TextToolbar: React.FC<TextToolbarProps> = ({
|
||||
}) => {
|
||||
const canEdit = useKnowledgeStore(state => state.canEdit);
|
||||
|
||||
// 控制按钮显示逻辑
|
||||
// Control button display logic
|
||||
const showUpdateFreBtn =
|
||||
canEdit &&
|
||||
curDoc &&
|
||||
|
||||
@@ -80,7 +80,7 @@ export const DocSelector = ({
|
||||
const regx = new RegExp(searchValue);
|
||||
const newOptions = options.filter(
|
||||
op =>
|
||||
// 搜索结果不展示「全部内容」选项
|
||||
// Search results do not show the "All Content" option
|
||||
(op.value !== 'all' && op.value === value) ||
|
||||
(op?.text as string)?.match(regx),
|
||||
);
|
||||
@@ -107,7 +107,7 @@ export const DocSelector = ({
|
||||
const handleEditDocName = e => {
|
||||
e.stopPropagation();
|
||||
setVisible(true);
|
||||
// TODO 打开弹框
|
||||
// TODO opens the box
|
||||
};
|
||||
const triggerRender = ({ value: values }) => (
|
||||
<Popover
|
||||
@@ -200,7 +200,7 @@ export const DocSelector = ({
|
||||
</Popover>
|
||||
);
|
||||
|
||||
// TODO: 交互改版,这里做了个假的
|
||||
// TODO: Interactive revision, made a fake here
|
||||
return (
|
||||
<Select
|
||||
clickToHide={true}
|
||||
|
||||
@@ -15,26 +15,26 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* 按照功能导出所有 hooks
|
||||
* Export all hooks by function
|
||||
*/
|
||||
|
||||
// 文档管理
|
||||
// Document Management
|
||||
export { useDocumentManagement } from './use-case/use-document-management';
|
||||
|
||||
// 文档信息
|
||||
// Document information
|
||||
export { useDocumentInfo } from './life-cycle/use-document-info';
|
||||
|
||||
// 文档片段数据
|
||||
// document fragment data
|
||||
export { useSliceData } from './life-cycle/use-slice-data';
|
||||
|
||||
// 层级分段数据
|
||||
// hierarchical segmented data
|
||||
export { useLevelSegments } from './use-case/use-level-segments';
|
||||
|
||||
// 文档片段计数
|
||||
// Document fragment count
|
||||
export { useSliceCounter } from './use-case/use-slice-counter';
|
||||
|
||||
// 文件预览
|
||||
// file preview
|
||||
export { useFilePreview } from './use-case/use-file-preview';
|
||||
|
||||
// 模态框
|
||||
// modal box
|
||||
export { useModals } from './use-case/use-modals';
|
||||
|
||||
@@ -21,7 +21,7 @@ import { DocumentStatus } from '@coze-arch/bot-api/knowledge';
|
||||
import { type ProgressMap } from '@/types';
|
||||
|
||||
/**
|
||||
* 处理文档基本信息的 hook
|
||||
* Hooks that handle basic information about documents
|
||||
*/
|
||||
export const useDocumentInfo = (progressMap: ProgressMap) => {
|
||||
const { documentList, dataSetDetail, curDocId } = useKnowledgeStore(
|
||||
@@ -32,16 +32,16 @@ export const useDocumentInfo = (progressMap: ProgressMap) => {
|
||||
})),
|
||||
);
|
||||
|
||||
// 当前文档
|
||||
// current document
|
||||
const curDoc = documentList?.find(i => i.document_id === curDocId);
|
||||
|
||||
// 处理状态
|
||||
// processing state
|
||||
const isProcessing = curDoc?.status === DocumentStatus.Processing;
|
||||
const processFinished = curDocId
|
||||
? progressMap[curDocId]?.status === DocumentStatus.Enable
|
||||
: false;
|
||||
|
||||
// 数据集ID
|
||||
// Dataset ID
|
||||
const datasetId = dataSetDetail?.dataset_id ?? '';
|
||||
|
||||
return {
|
||||
|
||||
@@ -40,7 +40,7 @@ interface UseSliceDataParams {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文档片段数据获取的 hook
|
||||
* Hooks for processing document fragment data acquisition
|
||||
*/
|
||||
export const useSliceData = ({
|
||||
curDocId,
|
||||
@@ -56,7 +56,7 @@ export const useSliceData = ({
|
||||
})),
|
||||
);
|
||||
|
||||
// 获取文档内容
|
||||
// Get document content
|
||||
const {
|
||||
loading,
|
||||
data: sliceData,
|
||||
@@ -67,12 +67,12 @@ export const useSliceData = ({
|
||||
params: {
|
||||
keyword: searchValue,
|
||||
document_id:
|
||||
// 如果是层级分段则不请求
|
||||
// If it is a hierarchical segmentation, it is not requested.
|
||||
curChunkType !== ChunkType.LevelChunk ? curDocId : '',
|
||||
},
|
||||
reloadDeps: [searchValue, curDocId, datasetId, processFinished],
|
||||
onError: error => {
|
||||
/** 拉取 slice 失败时,回退 curDocId,避免文档标题和内容不一致,用户迷惑 */
|
||||
/** When pulling a slice fails, roll back curDocId to avoid inconsistencies between the document title and content, and user confusion */
|
||||
dataReporter.errorEvent(DataNamespace.KNOWLEDGE, {
|
||||
eventName: ReportEventNames.KnowledgeGetSliceList,
|
||||
error,
|
||||
@@ -83,7 +83,7 @@ export const useSliceData = ({
|
||||
},
|
||||
});
|
||||
|
||||
// 使用 useMemo 缓存 chunks 数组,避免因 progressMap 更新导致不必要的重新创建
|
||||
// Use useMemo to cache the chunks array to avoid unnecessary recreations due to progressMap updates
|
||||
const renderData = useMemo(
|
||||
() =>
|
||||
sliceData?.list.map(item => createBaseDocumentChunkBySliceInfo(item)) ??
|
||||
@@ -91,7 +91,7 @@ export const useSliceData = ({
|
||||
[sliceData?.list],
|
||||
);
|
||||
|
||||
// 处理内容变化
|
||||
// Handling content changes
|
||||
const handleContentChange = (chunks: DocumentChunk[]) => {
|
||||
mutate({
|
||||
...sliceData,
|
||||
|
||||
@@ -35,10 +35,10 @@ export const useDocumentManagement = (props?: {
|
||||
})),
|
||||
);
|
||||
|
||||
// 缓存上一个文档ID,用于加载失败后回滚
|
||||
// Cache the previous document ID for rollback after load failure
|
||||
const prevDocIdRef = useRef<string | null>(null);
|
||||
|
||||
// 更新文档名称
|
||||
// Update document name
|
||||
const { run: updateDocument } = useUpdateDocument({
|
||||
onSuccess: () => {
|
||||
Toast.success(I18n.t('Update_success'));
|
||||
@@ -46,13 +46,13 @@ export const useDocumentManagement = (props?: {
|
||||
},
|
||||
});
|
||||
|
||||
// 选择文档
|
||||
// Select document
|
||||
const handleSelectDocument = (docId: string) => {
|
||||
prevDocIdRef.current = curDocId || null;
|
||||
setCurDocId(docId);
|
||||
};
|
||||
|
||||
// 重命名文档
|
||||
// rename document
|
||||
const handleRenameDocument = (docId: string, newName: string) => {
|
||||
updateDocument({
|
||||
document_id: docId,
|
||||
@@ -60,7 +60,7 @@ export const useDocumentManagement = (props?: {
|
||||
});
|
||||
};
|
||||
|
||||
// 更新文档频率
|
||||
// Update document frequency
|
||||
const handleUpdateDocumentFrequency = (
|
||||
docId: string,
|
||||
formData: { updateInterval?: number; updateType?: UpdateType },
|
||||
@@ -85,7 +85,7 @@ export const useDocumentManagement = (props?: {
|
||||
return updatedDocList;
|
||||
};
|
||||
|
||||
// 回滚文档选择
|
||||
// Rollback document selection
|
||||
const rollbackDocumentSelection = () => {
|
||||
if (prevDocIdRef.current) {
|
||||
setCurDocId(prevDocIdRef.current);
|
||||
|
||||
@@ -19,7 +19,7 @@ import { useState, useEffect } from 'react';
|
||||
export const useFilePreview = (curDocId: string) => {
|
||||
const [showOriginalFile, setShowOriginalFile] = useState(false);
|
||||
|
||||
// 切换文档时,重置预览状态
|
||||
// Reset the preview state when switching documents
|
||||
useEffect(() => {
|
||||
if (showOriginalFile) {
|
||||
setShowOriginalFile(false);
|
||||
|
||||
@@ -30,10 +30,10 @@ interface UseLevelSegmentsParams {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理层级分段数据的 hook
|
||||
* Hooks for processing hierarchical segmented data
|
||||
*/
|
||||
export const useLevelSegments = ({ curDoc }: UseLevelSegmentsParams) => {
|
||||
// 用于层级分段选中滚动
|
||||
// Scroll selected for hierarchical segmentation
|
||||
const [selectionIDs, setSelectionIDs] = useState<string[]>([]);
|
||||
|
||||
const { levelSegments, setLevelSegments } = useKnowledgeStore(
|
||||
@@ -43,33 +43,33 @@ export const useLevelSegments = ({ curDoc }: UseLevelSegmentsParams) => {
|
||||
})),
|
||||
);
|
||||
|
||||
// 获取层级分段 slice 列表
|
||||
// Get a list of hierarchical segments and slices
|
||||
const { content: treeContent, loading: tosLoading } = useTosContent(
|
||||
curDoc?.chunk_strategy?.chunk_type === ChunkType.LevelChunk
|
||||
? curDoc?.doc_tree_tos_url
|
||||
: undefined,
|
||||
);
|
||||
|
||||
// 使用 useMemo 缓存转换后的层级分段数据
|
||||
// Use useMemo to cache hierarchical segmented data after conversion
|
||||
const renderLevelSegmentsData = useMemo(
|
||||
() =>
|
||||
levelSegments.map(item => createLevelDocumentChunkByLevelSegment(item)),
|
||||
[levelSegments],
|
||||
);
|
||||
|
||||
// 处理层级分段变更
|
||||
// Handling hierarchy segmentation changes
|
||||
const handleLevelSegmentsChange = (chunks: ILevelSegment[]) => {
|
||||
setLevelSegments(chunks);
|
||||
};
|
||||
|
||||
// 处理删除层级分段
|
||||
// Handling deletion of hierarchical segmentation
|
||||
const handleLevelSegmentDelete = (chunk: ILevelSegment) => {
|
||||
setLevelSegments(
|
||||
levelSegments.filter(item => item.slice_id !== chunk.slice_id),
|
||||
);
|
||||
};
|
||||
|
||||
// 初始化时加载层级分段
|
||||
// Load hierarchical segmentation during initialization
|
||||
useEffect(() => {
|
||||
setLevelSegments(withTitle(treeContent?.chunks ?? [], curDoc?.name ?? ''));
|
||||
}, [treeContent]);
|
||||
|
||||
@@ -51,7 +51,7 @@ export const useModals = (props: UseModalsProps): UseModalsReturn => {
|
||||
const { docId, documentType, documentSource, onDelete, onUpdateFrequency } =
|
||||
props;
|
||||
|
||||
// 删除模态框
|
||||
// Delete modal box
|
||||
const { node: deleteModalNode, delete: showDeleteModal } = useDeleteUnitModal(
|
||||
{
|
||||
docId,
|
||||
@@ -61,7 +61,7 @@ export const useModals = (props: UseModalsProps): UseModalsReturn => {
|
||||
},
|
||||
);
|
||||
|
||||
// 更新频率模态框
|
||||
// Update frequency mode box
|
||||
const { node: updateFrequencyModalNode, edit: showUpdateFrequencyModal } =
|
||||
useUpdateFrequencyModal({
|
||||
docId,
|
||||
|
||||
@@ -18,7 +18,7 @@ import { useShallow } from 'zustand/react/shallow';
|
||||
import { useKnowledgeStore } from '@coze-data/knowledge-stores';
|
||||
|
||||
/**
|
||||
* 处理文档片段计数的 hook
|
||||
* Hooks that handle document fragment counting
|
||||
*/
|
||||
export const useSliceCounter = () => {
|
||||
const { dataSetDetail, setDataSetDetail } = useKnowledgeStore(
|
||||
@@ -28,7 +28,7 @@ export const useSliceCounter = () => {
|
||||
})),
|
||||
);
|
||||
|
||||
// 处理添加块时更新计数
|
||||
// Update count when processing added blocks
|
||||
const handleIncreaseSliceCount = () => {
|
||||
if (!dataSetDetail) {
|
||||
return;
|
||||
@@ -45,7 +45,7 @@ export const useSliceCounter = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// 处理删除块时更新计数
|
||||
// Update count when processing deleted blocks
|
||||
const handleDecreaseSliceCount = () => {
|
||||
if (!dataSetDetail) {
|
||||
return;
|
||||
|
||||
@@ -35,7 +35,7 @@ import { type ProgressMap } from '@/types';
|
||||
const FINISH_PROGRESS = 100;
|
||||
|
||||
/**
|
||||
* 创建基础文档块
|
||||
* Create base document block
|
||||
*/
|
||||
export const createBaseDocumentChunkBySliceInfo = (
|
||||
props: SliceInfo,
|
||||
@@ -45,7 +45,7 @@ export const createBaseDocumentChunkBySliceInfo = (
|
||||
});
|
||||
|
||||
/**
|
||||
* 创建层级文档块
|
||||
* Create hierarchical document blocks
|
||||
*/
|
||||
export const createLevelDocumentChunkByLevelSegment = (
|
||||
props: ILevelSegment,
|
||||
@@ -57,7 +57,7 @@ export const createLevelDocumentChunkByLevelSegment = (
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取文档选项
|
||||
* Get document options
|
||||
*/
|
||||
export const getDocumentOptions = (
|
||||
documentList: DocumentInfo[],
|
||||
|
||||
Reference in New Issue
Block a user