Unverified Commit 346d051e authored by gaoyan's avatar gaoyan Committed by GitHub

[Fix-2793] Fix Catalog NPE (#3004)

parent cf37b0bf
......@@ -19,6 +19,7 @@
package org.dinky.data.dto;
import java.util.HashMap;
import java.util.Map;
import io.swagger.annotations.ApiModel;
......@@ -41,12 +42,12 @@ public class AbstractStatementDTO {
private Integer envId;
@ApiModelProperty(value = "Fragment Flag", dataType = "boolean", example = "false", notes = "是否为片段")
private Boolean fragment;
private Boolean fragment = false;
@ApiModelProperty(
value = "Variables",
dataType = "Map<String, String>",
example = "{\"key\": \"value\"}",
notes = "变量集合")
private Map<String, String> variables;
private Map<String, String> variables = new HashMap<>();
}
......@@ -366,8 +366,7 @@ const HeaderContainer = (props: connect) => {
// 发布按钮
icon: isOnline(currentData) ? <MergeCellsOutlined /> : <FundOutlined />,
title: isOnline(currentData) ? l('button.offline') : l('button.publish'),
isShow:
(currentTab?.type == TabsPageType.project),
isShow: currentTab?.type == TabsPageType.project,
click: () => handleChangeJobLife()
},
{
......
......@@ -22,20 +22,18 @@ import { isSql } from '@/pages/DataStudio/HeaderContainer/function';
import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext';
import { TableDataNode } from '@/pages/DataStudio/LeftContainer/Catalog/data';
import { StateType } from '@/pages/DataStudio/model';
import ColumnInfo from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SchemaDesc/ColumnInfo';
import TableInfo from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SchemaDesc/TableInfo';
import SchemaDesc from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SchemaDesc';
import { DIALECT } from '@/services/constants';
import { l } from '@/utils/intl';
import {
AppstoreOutlined,
BlockOutlined,
CodepenOutlined,
DownOutlined,
FunctionOutlined,
TableOutlined
} from '@ant-design/icons';
import { connect } from '@umijs/max';
import { Button, Col, Empty, Modal, Row, Select, Spin, Tabs } from 'antd';
import { Button, Col, Empty, Modal, Row, Select, Spin } from 'antd';
import { DataNode } from 'antd/es/tree';
import DirectoryTree from 'antd/es/tree/DirectoryTree';
import { DefaultOptionType } from 'rc-select/lib/Select';
......@@ -103,10 +101,12 @@ const Catalog: React.FC = (props: connect) => {
table,
dialect,
databaseId
}).then((res) => {
setLoading(false);
setColumnData(res);
});
})
.then((res) => {
setLoading(false);
setColumnData(res);
})
.catch(() => {});
}
}, [table]);
......@@ -133,111 +133,113 @@ const Catalog: React.FC = (props: connect) => {
databaseId
};
const result = getMSSchemaInfo(param);
result.then((res) => {
setLoading(false);
const tables: any[] = [];
if (res.tables) {
for (let i = 0; i < res.tables.length; i++) {
tables.push(res.tables[i]);
result
.then((res) => {
setLoading(false);
const tables: any[] = [];
if (res.tables) {
for (let i = 0; i < res.tables.length; i++) {
tables.push(res.tables[i]);
}
}
const treeDataTmp: DataNode[] = [];
const tablesData: TableDataNode[] = [];
for (const t of tables) {
tablesData.push({
title: t.name,
key: t.name,
icon: <TableOutlined />,
isLeaf: true,
isTable: true,
name: t.name,
schema: databaseTmp,
catalog: catalog,
comment: t.comment,
type: t.type,
engine: engine ?? t.engine,
options: t.options,
rows: t.rows,
createTime: t.createTime,
updateTime: t.updateTime
});
}
}
const treeDataTmp: DataNode[] = [];
const tablesData: TableDataNode[] = [];
for (const t of tables) {
tablesData.push({
title: t.name,
key: t.name,
icon: <TableOutlined />,
isLeaf: true,
isTable: true,
name: t.name,
schema: databaseTmp,
catalog: catalog,
comment: t.comment,
type: t.type,
engine: engine ?? t.engine,
options: t.options,
rows: t.rows,
createTime: t.createTime,
updateTime: t.updateTime
treeDataTmp.push({
title: 'tables',
key: 'tables',
children: tablesData
});
}
treeDataTmp.push({
title: 'tables',
key: 'tables',
children: tablesData
});
const viewsData: DataNode[] = [];
if (res.views) {
for (let i = 0; i < res.views.length; i++) {
viewsData.push({
title: res.views[i],
key: res.views[i],
icon: <BlockOutlined />,
isLeaf: true
});
const viewsData: DataNode[] = [];
if (res.views) {
for (let i = 0; i < res.views.length; i++) {
viewsData.push({
title: res.views[i],
key: res.views[i],
icon: <BlockOutlined />,
isLeaf: true
});
}
}
}
treeDataTmp.push({
title: 'views',
key: 'views',
children: viewsData
});
treeDataTmp.push({
title: 'views',
key: 'views',
children: viewsData
});
const functionsData: DataNode[] = [];
if (res.functions) {
for (let i = 0; i < res.functions.length; i++) {
functionsData.push({
title: res.functions[i],
key: res.functions[i],
icon: <FunctionOutlined />,
isLeaf: true
});
const functionsData: DataNode[] = [];
if (res.functions) {
for (let i = 0; i < res.functions.length; i++) {
functionsData.push({
title: res.functions[i],
key: res.functions[i],
icon: <FunctionOutlined />,
isLeaf: true
});
}
}
}
treeDataTmp.push({
title: 'functions',
key: 'functions',
children: functionsData
});
treeDataTmp.push({
title: 'functions',
key: 'functions',
children: functionsData
});
const userFunctionsData: DataNode[] = [];
if (res.userFunctions) {
for (let i = 0; i < res.userFunctions.length; i++) {
userFunctionsData.push({
title: res.userFunctions[i],
key: res.userFunctions[i],
icon: <FunctionOutlined />,
isLeaf: true
});
const userFunctionsData: DataNode[] = [];
if (res.userFunctions) {
for (let i = 0; i < res.userFunctions.length; i++) {
userFunctionsData.push({
title: res.userFunctions[i],
key: res.userFunctions[i],
icon: <FunctionOutlined />,
isLeaf: true
});
}
}
}
treeDataTmp.push({
title: 'user functions',
key: 'userFunctions',
children: userFunctionsData
});
treeDataTmp.push({
title: 'user functions',
key: 'userFunctions',
children: userFunctionsData
});
const modulesData: DataNode[] = [];
if (res.modules) {
for (let i = 0; i < res.modules.length; i++) {
modulesData.push({
title: res.modules[i],
key: res.modules[i],
icon: <AppstoreOutlined />,
isLeaf: true
});
const modulesData: DataNode[] = [];
if (res.modules) {
for (let i = 0; i < res.modules.length; i++) {
modulesData.push({
title: res.modules[i],
key: res.modules[i],
icon: <AppstoreOutlined />,
isLeaf: true
});
}
}
}
treeDataTmp.push({
title: 'modules',
key: 'modules',
children: modulesData
});
treeDataTmp.push({
title: 'modules',
key: 'modules',
children: modulesData
});
setTreeData(treeDataTmp);
});
setTreeData(treeDataTmp);
})
.catch(() => {});
};
const getCatalogs = () => {
......@@ -252,22 +254,24 @@ const Catalog: React.FC = (props: connect) => {
dialect: dialect,
databaseId
};
getMSCatalogs(param).then((d) => {
setCatalogSelect(
(d as any[]).map((item) => {
setLoading(false);
return {
label: item.name,
options: (item.schemas as any[]).map((schema) => {
return {
label: schema.name,
value: item.name + '.' + schema.name
};
})
};
})
);
});
getMSCatalogs(param)
.then((d) => {
setCatalogSelect(
(d as any[]).map((item) => {
setLoading(false);
return {
label: item.name,
options: (item.schemas as any[]).map((schema) => {
return {
label: schema.name,
value: item.name + '.' + schema.name
};
})
};
})
);
})
.catch(() => {});
}
};
......@@ -283,8 +287,8 @@ const Catalog: React.FC = (props: connect) => {
onRefreshTreeData(value);
};
const openColumnInfo = (_e: React.MouseEvent, node: TableDataNode) => {
if (node.isLeaf && node.isTable) {
const openColumnInfo = (node: TableDataNode) => {
if (node && node.isLeaf && node.isTable) {
setTable(node.name);
setRow(node);
setModalVisit(true);
......@@ -317,9 +321,8 @@ const Catalog: React.FC = (props: connect) => {
showIcon
switcherIcon={<DownOutlined />}
treeData={treeData}
onRightClick={({ event, node }: any) => {
openColumnInfo(event, node);
}}
onRightClick={({ node }: any) => openColumnInfo(node)}
onSelect={(_, info: any) => openColumnInfo(info.node)}
/>
) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
......@@ -328,7 +331,7 @@ const Catalog: React.FC = (props: connect) => {
<Modal
title={<>{row?.key}</> ?? <></>}
open={modalVisit}
width={10000}
width={'85%'}
onCancel={() => {
cancelHandle();
}}
......@@ -343,36 +346,7 @@ const Catalog: React.FC = (props: connect) => {
</Button>
]}
>
<Tabs
defaultActiveKey='tableInfo'
size='small'
items={[
{
key: 'tableInfo',
label: (
<span>
<TableOutlined />
{l('pages.datastudio.catalog.tableInfo')}
</span>
),
children: row ? (
<TableInfo tableInfo={row} />
) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
)
},
{
key: 'columnsInfo',
label: (
<span>
<CodepenOutlined />
{l('pages.datastudio.catalog.fieldInformation')}
</span>
),
children: <Spin spinning={loading}>{<ColumnInfo columnInfo={columnData} />}</Spin>
}
]}
/>
<SchemaDesc tableInfo={row} tableColumns={columnData} />
</Modal>
</Spin>
);
......
......@@ -29,7 +29,7 @@ import { Key, ProForm, ProFormSelect } from '@ant-design/pro-components';
import { connect } from '@umijs/max';
import { Spin, Tag } from 'antd';
import { useEffect, useState } from 'react';
import { StateType, STUDIO_MODEL } from '../../model';
import { StateType, STUDIO_MODEL, TabsPageType } from '../../model';
import { clearDataSourceTable, getDataSourceList, showDataSourceTable } from './service';
const DataSource = (props: any) => {
......@@ -161,7 +161,7 @@ const DataSource = (props: any) => {
breadcrumbLabel: [selectDb.type, selectDb.name].join('/'),
label: schemaName + '.' + tableName,
params: { queryParams: queryParams, tableInfo: fullInfo },
type: 'metadata'
type: TabsPageType.metadata
}
});
};
......
......@@ -84,7 +84,7 @@ const ColumnInfo: React.FC<ColumnInfoProps> = (props) => {
{
title: l('rc.ds.length'),
dataIndex: 'length',
width: '4%'
width: '6%'
},
{
title: l('rc.ds.precision'),
......
......@@ -25,8 +25,8 @@ import { Empty } from 'antd';
import React from 'react';
type SchemaDescProps = {
tableInfo: Partial<DataSources.Table>;
tableColumns: Partial<DataSources.Column[]>;
tableInfo?: Partial<DataSources.Table>;
tableColumns?: Partial<DataSources.Column[]>;
};
const SchemaDesc: React.FC<SchemaDescProps> = (props) => {
......@@ -34,12 +34,9 @@ const SchemaDesc: React.FC<SchemaDescProps> = (props) => {
return (
<>
{!(Object.keys(tableInfo).length === 0 && tableColumns.length === 0) ? (
<>
<TableInfo tableInfo={tableInfo} />
<ColumnInfo columnInfo={tableColumns} />
</>
) : (
{tableInfo && <TableInfo tableInfo={tableInfo} />}
{tableColumns && <ColumnInfo columnInfo={tableColumns} />}
{!tableInfo && !tableColumns && (
<Empty className={'code-content-empty'} description={l('rc.ds.detail.tips')} />
)}
</>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment