Unverified Commit 3eafe155 authored by Licho's avatar Licho Committed by GitHub

fix: metadate get error (#2246)

Signed-off-by: 's avatarLicho <lecho.sun@gmail.com>
parent 5fbaeab2
import { TagAlignLeft } from '@/components/StyledComponents'; import {TagAlignLeft} from '@/components/StyledComponents';
import { BtnRoute } from '@/pages/DataStudio/route'; import {BtnRoute} from '@/pages/DataStudio/route';
import SchemaTree from '@/pages/RegCenter/DataSource/components/DataSourceDetail/SchemaTree'; import SchemaTree from '@/pages/RegCenter/DataSource/components/DataSourceDetail/SchemaTree';
import { DataSources } from '@/types/RegCenter/data'; import {DataSources} from '@/types/RegCenter/data';
import { l } from '@/utils/intl'; import {l} from '@/utils/intl';
import { DatabaseOutlined, TableOutlined } from '@ant-design/icons'; import {DatabaseOutlined, TableOutlined} from '@ant-design/icons';
import { Key, ProForm, ProFormSelect } from '@ant-design/pro-components'; import {Key, ProForm, ProFormSelect} from '@ant-design/pro-components';
import { connect } from '@umijs/max'; import {connect} from '@umijs/max';
import { Spin, Tag } from 'antd'; import {Spin, Tag} from 'antd';
import { useEffect, useState } from 'react'; import {useEffect, useState} from 'react';
import { StateType, STUDIO_MODEL } from '../../model'; import {StateType, STUDIO_MODEL} from '../../model';
import { clearMetaDataTable, showMetaDataTable } from './service'; import {clearMetaDataTable, showMetaDataTable} from './service';
const MetaData = (props: any) => { const MetaData = (props: any) => {
const { const {
...@@ -32,12 +32,11 @@ const MetaData = (props: any) => { ...@@ -32,12 +32,11 @@ const MetaData = (props: any) => {
setIsLoadingDatabase(false); setIsLoadingDatabase(false);
return; return;
} }
setIsLoadingDatabase(true);
await showMetaDataTable(databaseId).then((res) => { setIsLoadingDatabase(true);
const tables = await showMetaDataTable(databaseId) ?? []
setIsLoadingDatabase(false); setIsLoadingDatabase(false);
const { datas: tables } = res;
if (!tables) return;
for (let table of tables) { for (let table of tables) {
table.title = table.name; table.title = table.name;
table.key = table.name; table.key = table.name;
...@@ -52,8 +51,7 @@ const MetaData = (props: any) => { ...@@ -52,8 +51,7 @@ const MetaData = (props: any) => {
child.table = child.name; child.table = child.name;
} }
} }
setTreeData(tables ?? []); setTreeData(tables);
});
}; };
useEffect(() => { useEffect(() => {
...@@ -70,10 +68,7 @@ const MetaData = (props: any) => { ...@@ -70,10 +68,7 @@ const MetaData = (props: any) => {
onRefreshTreeData(value); onRefreshTreeData(value);
}; };
/** BtnRoute['menu.datastudio.metadata'][0].onClick = () => {
* 刷新数据库列表
*/
const refreshDataBase = () => {
if (!selectDatabaseId) return; if (!selectDatabaseId) return;
setIsLoadingDatabase(true); setIsLoadingDatabase(true);
clearMetaDataTable(selectDatabaseId).then(() => { clearMetaDataTable(selectDatabaseId).then(() => {
...@@ -81,11 +76,8 @@ const MetaData = (props: any) => { ...@@ -81,11 +76,8 @@ const MetaData = (props: any) => {
}); });
}; };
BtnRoute['menu.datastudio.metadata'][0].onClick = refreshDataBase;
/** /**
* 构建数据库列表 下拉框 * 构建数据库列表 下拉框
* @returns {{label: JSX.Element, value: number, key: number}[]}
*/ */
const getDataBaseOptions = () => { const getDataBaseOptions = () => {
return dbData.map( return dbData.map(
...@@ -109,7 +101,6 @@ const MetaData = (props: any) => { ...@@ -109,7 +101,6 @@ const MetaData = (props: any) => {
* 树节点点击事件 添加tab页 并传递参数 * 树节点点击事件 添加tab页 并传递参数
* @param keys * @param keys
* @param info * @param info
* @returns {Promise<void>}
*/ */
const handleTreeNodeClick = async (keys: Key[], info: any) => { const handleTreeNodeClick = async (keys: Key[], info: any) => {
// 选中的key // 选中的key
...@@ -121,8 +112,12 @@ const MetaData = (props: any) => { ...@@ -121,8 +112,12 @@ const MetaData = (props: any) => {
const { const {
node: { isLeaf, parentId: schemaName, name: tableName, fullInfo }, node: { isLeaf, parentId: schemaName, name: tableName, fullInfo },
} = info; } = info;
if (isLeaf) {
const queryParams = { id: selectDatabaseId, schemaName, tableName }; if (!isLeaf) {
return;
}
const queryParams = {id: selectDatabaseId, schemaName, tableName};
dispatch({ dispatch({
type: STUDIO_MODEL.addTab, type: STUDIO_MODEL.addTab,
payload: { payload: {
...@@ -130,11 +125,10 @@ const MetaData = (props: any) => { ...@@ -130,11 +125,10 @@ const MetaData = (props: any) => {
id: selectDatabaseId + schemaName + tableName, id: selectDatabaseId + schemaName + tableName,
breadcrumbLabel: [selectDb.type, selectDb.name].join('/'), breadcrumbLabel: [selectDb.type, selectDb.name].join('/'),
label: schemaName + '.' + tableName, label: schemaName + '.' + tableName,
params: { queryParams: queryParams, tableInfo: fullInfo }, params: {queryParams: queryParams, tableInfo: fullInfo},
type: 'metadata', type: 'metadata',
}, },
}); });
}
}; };
/** /**
......
...@@ -3,13 +3,18 @@ import { l } from '@/utils/intl'; ...@@ -3,13 +3,18 @@ import { l } from '@/utils/intl';
/*--- 刷新 元数据表 ---*/ /*--- 刷新 元数据表 ---*/
export async function showMetaDataTable(id: number) { export async function showMetaDataTable(id: number) {
return (
await handleGetOption( try {
const result = await handleGetOption(
'api/database/getSchemasAndTables', 'api/database/getSchemasAndTables',
l('pages.metadata.DataSearch'), l('pages.metadata.DataSearch'),
{ id: id }, {id: id},
) );
).datas; return result?.datas;
} catch (e) {
console.error(e)
return null;
}
} }
/*--- 清理 元数据表缓存 ---*/ /*--- 清理 元数据表缓存 ---*/
......
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