mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
### What problem does this PR solve? fix: misc frontend fixes for agent log, login, search settings - agent-log: restore server-side pagination on export and search; replace hardcoded labels with i18n keys; switch container to text-text-primary - login: validate register nickname against NICKNAME_PATTERN with reusable setting i18n - next-search: align llm_setting schema with chat (LlmSettingFieldSchema + LLMIdFormField nested, LlmSettingEnabledSchema at form root) so the slider Switch reads the correct path; strip *Enabled flags before submit to avoid backend "Unrecognized field name" errors - locales: add common.reset (zh/en) - skills/go-naming: fix relative link to rules/named.md ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
import message from '@/components/ui/message';
|
|
import { useExportAgentLog } from '@/hooks/use-agent-request';
|
|
import { IAgentLogResponse } from '@/interfaces/database/agent';
|
|
import { downloadFileFromBlob } from '@/utils/file-util';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useParams } from 'react-router';
|
|
|
|
interface ISearchParams {
|
|
keywords?: string;
|
|
from_date?: Date;
|
|
to_date?: Date;
|
|
orderby?: string;
|
|
desc?: boolean;
|
|
page?: number;
|
|
page_size?: number;
|
|
}
|
|
|
|
export const useExportAgentLogToCSV = () => {
|
|
const { t } = useTranslation();
|
|
const { id: canvasId } = useParams();
|
|
const { exportLogs, loading } = useExportAgentLog();
|
|
|
|
const convertToCSV = (data: IAgentLogResponse[]) => {
|
|
const headers = [
|
|
t('flow.id'),
|
|
t('flow.userId'),
|
|
t('flow.logTitle'),
|
|
t('flow.state'),
|
|
t('flow.number'),
|
|
t('flow.latestDate'),
|
|
t('flow.createDate'),
|
|
t('flow.version.version'),
|
|
];
|
|
|
|
const rows = data.map((item) => [
|
|
item.id,
|
|
item.user_id,
|
|
item.message?.length ? item.message[0]?.content : '',
|
|
item.errors ? t('flow.failed') : t('flow.success'),
|
|
item.round,
|
|
item.update_date,
|
|
item.create_date,
|
|
item.version_title,
|
|
]);
|
|
|
|
const csvContent = [
|
|
headers.join(','),
|
|
...rows.map((row) =>
|
|
row.map((cell) => `"${String(cell).replace(/"/g, '""')}"`).join(','),
|
|
),
|
|
].join('\n');
|
|
|
|
return csvContent;
|
|
};
|
|
|
|
const handleExport = async (searchParams: ISearchParams) => {
|
|
const allData = await exportLogs({
|
|
keywords: searchParams.keywords,
|
|
from_date: searchParams.from_date,
|
|
to_date: searchParams.to_date,
|
|
orderby: searchParams.orderby,
|
|
desc: searchParams.desc,
|
|
page: searchParams.page,
|
|
page_size: searchParams.page_size,
|
|
});
|
|
|
|
if (allData.length === 0) {
|
|
console.log('No data to export', allData);
|
|
message.warning(t('flow.noDataToExport'));
|
|
return;
|
|
}
|
|
|
|
const csvContent = convertToCSV(allData);
|
|
// Add BOM for Excel to correctly display UTF-8
|
|
const BOM = '\uFEFF';
|
|
const blob = new Blob([BOM + csvContent], {
|
|
type: 'text/csv;charset=utf-8;',
|
|
});
|
|
downloadFileFromBlob(
|
|
blob,
|
|
`agent-logs-${canvasId}-${new Date().toISOString().split('T')[0]}.csv`,
|
|
);
|
|
};
|
|
|
|
return { handleExport, loading };
|
|
};
|