Fix: table parser metadata (#15127)

### What problem does this PR solve?

This PR improves the table upload flow for CSV/Excel files by allowing
table column role configuration at upload time.

Previously, users had to:
1. Upload and parse a table file.
2. Open parser settings and manually set table column roles.
3. Re-parse the file for the roles to take effect.

This was inefficient and required an unnecessary second parse.

With this change:
1. When the knowledge base uses table parsing, the upload dialog
extracts CSV/Excel headers client-side.
2. Users can choose Auto mode or Manual mode.
3. In Manual mode, users can assign per-column roles before upload.
4. The selected parser config is sent with the upload request and
applied server-side during document creation.

Result: configured table column roles are applied from the first parse.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: Ahmad Intisar <ahmadintisar@Ahmads-MacBook-M4-Pro.local>
This commit is contained in:
Ahmad Intisar
2026-05-25 13:05:38 +05:00
committed by GitHub
parent e7d45dd645
commit e6068a7f7e
7 changed files with 316 additions and 26 deletions

View File

@@ -69,9 +69,13 @@ export const useUploadNextDocument = () => {
data,
isPending: loading,
mutateAsync,
} = useMutation<ResponseType<IDocumentInfo[]>, Error, File[]>({
} = useMutation<
ResponseType<IDocumentInfo[]>,
Error,
{ fileList: File[]; parserConfig?: Record<string, any> }
>({
mutationKey: [DocumentApiAction.UploadDocument],
mutationFn: async (fileList) => {
mutationFn: async ({ fileList, parserConfig }) => {
if (!id) {
return { code: 500, message: 'Dataset ID is required' };
}
@@ -79,6 +83,9 @@ export const useUploadNextDocument = () => {
fileList.forEach((file: any) => {
formData.append('file', file);
});
if (parserConfig) {
formData.append('parser_config', JSON.stringify(parserConfig));
}
try {
const ret = await uploadDocument(id, formData);
@@ -100,7 +107,13 @@ export const useUploadNextDocument = () => {
},
});
return { uploadDocument: mutateAsync, loading, data };
const upload = useCallback(
(fileList: File[], parserConfig?: Record<string, any>) =>
mutateAsync({ fileList, parserConfig }),
[mutateAsync],
);
return { uploadDocument: upload, loading, data };
};
export const useFetchDocumentList = (loop = true) => {