mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-02 01:02:05 +08:00
fea1c4ed14
* perf: workflow node past * feat: table export * feat: table export
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import React, { useRef, useCallback } from 'react';
|
|
import { Box, IconButton } from '@chakra-ui/react';
|
|
import { useTranslation } from 'next-i18next';
|
|
import { exportTableToCSV } from './utils';
|
|
import MyIcon from '../Icon';
|
|
|
|
type MarkdownTableProps = {
|
|
children: React.ReactNode;
|
|
};
|
|
|
|
/**
|
|
* Custom table component for Markdown with CSV export functionality
|
|
*/
|
|
const MarkdownTable = ({ children }: MarkdownTableProps) => {
|
|
const { t } = useTranslation();
|
|
const tableRef = useRef<HTMLTableElement>(null);
|
|
|
|
const handleExport = useCallback(() => {
|
|
if (tableRef.current) {
|
|
const timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-');
|
|
exportTableToCSV(tableRef.current, `table-${timestamp}`);
|
|
}
|
|
}, []);
|
|
|
|
return (
|
|
<Box
|
|
ref={tableRef}
|
|
as="table"
|
|
_hover={{
|
|
'.export-button': {
|
|
display: 'flex'
|
|
}
|
|
}}
|
|
>
|
|
<IconButton
|
|
className="export-button"
|
|
icon={<MyIcon name="export" w={'14px'} />}
|
|
size={'xs'}
|
|
display="none"
|
|
variant={'whiteBase'}
|
|
onClick={handleExport}
|
|
position="absolute"
|
|
top={1}
|
|
right={2}
|
|
zIndex={1}
|
|
aria-label={''}
|
|
/>
|
|
{children}
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
export default React.memo(MarkdownTable);
|