mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-27 13:57:46 +00:00
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com> Co-authored-by: 谨欣 <echo.cmy@antgroup.com> Co-authored-by: 严志勇 <yanzhiyong@tiansuixiansheng.com> Co-authored-by: yanzhiyong <932374019@qq.com>
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { AutoChart, BackEndChartType, getChartType } from '@/components/chart/autoChart';
|
|
import { formatSql } from '@/utils';
|
|
import { Datum } from '@antv/ava';
|
|
import { Table, Tabs, TabsProps } from 'antd';
|
|
import { CodePreview } from './code-preview';
|
|
|
|
function ChartView({ data, type, sql }: { data: Datum[]; type: BackEndChartType; sql: string }) {
|
|
const columns = data?.[0]
|
|
? Object.keys(data?.[0])?.map(item => {
|
|
return {
|
|
title: item,
|
|
dataIndex: item,
|
|
key: item,
|
|
};
|
|
})
|
|
: [];
|
|
const ChartItem = {
|
|
key: 'chart',
|
|
label: 'Chart',
|
|
children: <AutoChart data={data} chartType={getChartType(type)} />,
|
|
};
|
|
const SqlItem = {
|
|
key: 'sql',
|
|
label: 'SQL',
|
|
children: <CodePreview language='sql' code={formatSql(sql ?? '', 'mysql') as string} />,
|
|
};
|
|
const DataItem = {
|
|
key: 'data',
|
|
label: 'Data',
|
|
children: <Table dataSource={data} columns={columns} scroll={{ x: 'auto' }} />,
|
|
};
|
|
const TabItems: TabsProps['items'] = type === 'response_table' ? [DataItem, SqlItem] : [ChartItem, SqlItem, DataItem];
|
|
|
|
return <Tabs defaultActiveKey={type === 'response_table' ? 'data' : 'chart'} items={TabItems} size='small' />;
|
|
}
|
|
|
|
export default ChartView;
|