Skip to content

Commit

Permalink
fix: metadate get error (DataLinkDC#2246)
Browse files Browse the repository at this point in the history
Signed-off-by: Licho <[email protected]>
  • Loading branch information
leechor authored Aug 19, 2023
1 parent 5fbaeab commit 3eafe15
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 58 deletions.
96 changes: 45 additions & 51 deletions dinky-web/src/pages/DataStudio/LeftContainer/MetaData/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { TagAlignLeft } from '@/components/StyledComponents';
import { BtnRoute } from '@/pages/DataStudio/route';
import {TagAlignLeft} from '@/components/StyledComponents';
import {BtnRoute} from '@/pages/DataStudio/route';
import SchemaTree from '@/pages/RegCenter/DataSource/components/DataSourceDetail/SchemaTree';
import { DataSources } from '@/types/RegCenter/data';
import { l } from '@/utils/intl';
import { DatabaseOutlined, TableOutlined } from '@ant-design/icons';
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 { clearMetaDataTable, showMetaDataTable } from './service';
import {DataSources} from '@/types/RegCenter/data';
import {l} from '@/utils/intl';
import {DatabaseOutlined, TableOutlined} from '@ant-design/icons';
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 {clearMetaDataTable, showMetaDataTable} from './service';

const MetaData = (props: any) => {
const {
Expand All @@ -32,28 +32,26 @@ const MetaData = (props: any) => {
setIsLoadingDatabase(false);
return;
}

setIsLoadingDatabase(true);
const tables = await showMetaDataTable(databaseId) ?? []
setIsLoadingDatabase(false);

await showMetaDataTable(databaseId).then((res) => {
setIsLoadingDatabase(false);
const { datas: tables } = res;
if (!tables) return;
for (let table of tables) {
table.title = table.name;
table.key = table.name;
table.icon = <DatabaseOutlined />;
table.children = table.tables;
for (let child of table.children) {
child.title = child.name;
child.key = table.name + '.' + child.name;
child.icon = <TableOutlined />;
child.isLeaf = true;
child.schema = table.name;
child.table = child.name;
}
for (let table of tables) {
table.title = table.name;
table.key = table.name;
table.icon = <DatabaseOutlined />;
table.children = table.tables;
for (let child of table.children) {
child.title = child.name;
child.key = table.name + '.' + child.name;
child.icon = <TableOutlined />;
child.isLeaf = true;
child.schema = table.name;
child.table = child.name;
}
setTreeData(tables ?? []);
});
}
setTreeData(tables);
};

useEffect(() => {
Expand All @@ -70,22 +68,16 @@ const MetaData = (props: any) => {
onRefreshTreeData(value);
};

/**
* 刷新数据库列表
*/
const refreshDataBase = () => {
BtnRoute['menu.datastudio.metadata'][0].onClick = () => {
if (!selectDatabaseId) return;
setIsLoadingDatabase(true);
clearMetaDataTable(selectDatabaseId).then(() => {
onChangeDataBase(selectDatabaseId);
});
};

BtnRoute['menu.datastudio.metadata'][0].onClick = refreshDataBase;

/**
* 构建数据库列表 下拉框
* @returns {{label: JSX.Element, value: number, key: number}[]}
*/
const getDataBaseOptions = () => {
return dbData.map(
Expand All @@ -109,7 +101,6 @@ const MetaData = (props: any) => {
* 树节点点击事件 添加tab页 并传递参数
* @param keys
* @param info
* @returns {Promise<void>}
*/
const handleTreeNodeClick = async (keys: Key[], info: any) => {
// 选中的key
Expand All @@ -121,20 +112,23 @@ const MetaData = (props: any) => {
const {
node: { isLeaf, parentId: schemaName, name: tableName, fullInfo },
} = info;
if (isLeaf) {
const queryParams = { id: selectDatabaseId, schemaName, tableName };
dispatch({
type: STUDIO_MODEL.addTab,
payload: {
icon: selectDb.type,
id: selectDatabaseId + schemaName + tableName,
breadcrumbLabel: [selectDb.type, selectDb.name].join('/'),
label: schemaName + '.' + tableName,
params: { queryParams: queryParams, tableInfo: fullInfo },
type: 'metadata',
},
});

if (!isLeaf) {
return;
}

const queryParams = {id: selectDatabaseId, schemaName, tableName};
dispatch({
type: STUDIO_MODEL.addTab,
payload: {
icon: selectDb.type,
id: selectDatabaseId + schemaName + tableName,
breadcrumbLabel: [selectDb.type, selectDb.name].join('/'),
label: schemaName + '.' + tableName,
params: {queryParams: queryParams, tableInfo: fullInfo},
type: 'metadata',
},
});
};

/**
Expand Down
19 changes: 12 additions & 7 deletions dinky-web/src/pages/DataStudio/LeftContainer/MetaData/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { l } from '@/utils/intl';

/*--- 刷新 元数据表 ---*/
export async function showMetaDataTable(id: number) {
return (
await handleGetOption(
'api/database/getSchemasAndTables',
l('pages.metadata.DataSearch'),
{ id: id },
)
).datas;

try {
const result = await handleGetOption(
'api/database/getSchemasAndTables',
l('pages.metadata.DataSearch'),
{id: id},
);
return result?.datas;
} catch (e) {
console.error(e)
return null;
}
}

/*--- 清理 元数据表缓存 ---*/
Expand Down

0 comments on commit 3eafe15

Please sign in to comment.