Unverified Commit f8438c78 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

optimize layout && added gen sql page (#1978)

parent 5c7529cc
...@@ -98,14 +98,13 @@ body, ...@@ -98,14 +98,13 @@ body,
// scrollbar style --- start ---- // scrollbar style --- start ----
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 0.5vw; width: 0.2vw;
height: 1vh; height: 0.5vh;
background-color: #f5f5f5;
} }
::-webkit-scrollbar-thumb { ::-webkit-scrollbar-thumb {
background-color: #ccc; background-color: #ccc;
border-radius: 6px; border-radius: 10px;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
} }
...@@ -232,14 +231,10 @@ ol { ...@@ -232,14 +231,10 @@ ol {
} }
} }
.schemaTree { .schemaTree{
height: 75vh; max-height: 78vh;
max-height: 75vh; min-height: 78vh;
background-color: white; margin-top: 1.5vh;
}
.columnTable{
max-height: 60vh;
overflow: auto;
} }
.code-content-empty { .code-content-empty {
......
...@@ -156,7 +156,7 @@ export default { ...@@ -156,7 +156,7 @@ export default {
'rc.ds.detail.tag.console': 'Console', 'rc.ds.detail.tag.console': 'Console',
// tips // tips
'rc.ds.detail.tips': 'Click on the table on the left to get the description information of the table', 'rc.ds.detail.tips': 'Click on the table on the left to get relevant information',
// columns info // columns info
'rc.ds.no': 'No.', 'rc.ds.no': 'No.',
......
...@@ -153,7 +153,7 @@ export default { ...@@ -153,7 +153,7 @@ export default {
'rc.ds.detail.tag.console': '控制台', 'rc.ds.detail.tag.console': '控制台',
// tips // tips
'rc.ds.detail.tips': '点击左侧的表,获取表的描述信息', 'rc.ds.detail.tips': '点击左侧的表,获取相关信息',
// columns info // columns info
'rc.ds.no': '序号', 'rc.ds.no': '序号',
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {DataSources} from '@/types/RegCenter/data';
import React from 'react';
import CodeShow from '@/components/CustomEditor/CodeShow';
import {ProCard} from '@ant-design/pro-components';
import {Empty} from 'antd';
import {l} from '@/utils/intl';
type GenSQLProps = {
sql: Partial<DataSources.SqlGeneration>;
}
/**
* props for CodeShow
*/
const CodeShowProps = {
height: '60vh',
width: '100%',
lineNumbers: 'on',
language: 'sql',
showFloatButton: true,
};
const GenSQL: React.FC<GenSQLProps> = (props) => {
const {sql} = props;
const [activeKey, setActiveKey] = React.useState<string>('flinkddl');
// tab list
const tabList = [
{
key: 'flinkddl',
label: 'Flink DDL',
children: <CodeShow {...CodeShowProps} code={sql.flinkSqlCreate || ''}/>
},
{
key: 'select',
label: 'Select',
children: <CodeShow {...CodeShowProps} code={sql.sqlSelect || ''}/>
},
{
key: 'sqlddl',
label: 'SQL DDL',
children: <CodeShow {...CodeShowProps} code={sql.sqlCreate || ''}/>
}
]
// tab props
const restTabProps = {
activeKey,
onChange: (key: string) =>setActiveKey(key),
tabPosition: 'left',
items: tabList
}
return <>
{ (sql.flinkSqlCreate || sql.sqlSelect || sql.sqlCreate) ?
<ProCard tabs={{...restTabProps}}/>
: <Empty className={'code-content-empty'} description={l('rc.ds.detail.tips')}/>
}
</>;
};
export default GenSQL;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import CodeEdit from '@/components/CustomEditor/CodeEdit';
import React, {useState} from 'react';
const CodeEditProps = {
height: '35vh',
width: '100%',
lineNumbers: 'on',
language: 'sql',
// autoRange: true, // todo: 使用此配置项,后续可以自动识别光标位置,根据;分割,得到 sql 片段区间, 在左侧自动添加 执行按钮 和 区间选中效果, 规划内,暂未实现
};
type SQLConsoleProps = {
querySQL: string,
}
const SQLConsole:React.FC<SQLConsoleProps> = (props) => {
const {querySQL} = props;
const [inputValue, setInputValue] = useState('');
const [loading, setLoading] = useState<boolean>(false);
const handleInputChange = (value: string) => {
setInputValue(value);
}
const execSql = async () => {
setLoading(true);
// todo: exec sql callback
setLoading(false);
}
return <>
<CodeEdit {...CodeEditProps} onChange={handleInputChange} code={inputValue}/>
</>
}
export default SQLConsole;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
type SQLQueryProps = {
query: string,
}
//todo: SQLQuery component
const SQLQuery: React.FC<SQLQueryProps> = (props) => {
const {query} = props;
return <div>SQLQuery</div>;
};
export default SQLQuery;
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {Space, Tabs} from 'antd'; import {Space} from 'antd';
import {l} from '@/utils/intl'; import {l} from '@/utils/intl';
import { import {
BookOutlined, BookOutlined,
...@@ -23,50 +23,69 @@ import { ...@@ -23,50 +23,69 @@ import {
import React from 'react'; import React from 'react';
import {DataSources} from '@/types/RegCenter/data'; import {DataSources} from '@/types/RegCenter/data';
import SchemaDesc from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SchemaDesc'; import SchemaDesc from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SchemaDesc';
import GenSQL from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/GenSQL';
import {ProCard} from '@ant-design/pro-components';
import SQLQuery from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SQLQuery';
import SQLConsole from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/SQLConsole';
/**
* props
*/
type RightTagsRouterProps = { type RightTagsRouterProps = {
tableInfo: Partial<DataSources.Table>; tableInfo: Partial<DataSources.Table>,
tableColumns: Partial<DataSources.Column[]>; tableColumns: Partial<DataSources.Column[]>,
genSQL: Partial<DataSources.SqlGeneration>,
rightButtons: React.ReactNode,
} }
const RightTagsRouter: React.FC<RightTagsRouterProps> = (props) => { const RightTagsRouter: React.FC<RightTagsRouterProps> = (props) => {
const {tableColumns, tableInfo} = props; const {tableColumns, tableInfo, genSQL, rightButtons} = props;
// state
const [activeKey, setActiveKey] = React.useState('desc'); const [activeKey, setActiveKey] = React.useState('desc');
// tab list
const tabList = [
{
key: 'desc',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.desc')}</Space>,
children: <SchemaDesc tableInfo={tableInfo} tableColumns={tableColumns}/>
},
{
key: 'query',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.query')}</Space>,
children: <SQLQuery query={'111'}/>
},
{
key: 'gensql',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.gensql')}</Space>,
children: <GenSQL sql={genSQL}/>
},
{
key: 'console',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.console')}</Space>,
children: <SQLConsole querySQL={''}/>
},
];
// tab props
const restTabProps = {
activeKey: activeKey,
type: 'card',
tabBarExtraContent: rightButtons,
animated: true,
onChange: (key: string) => setActiveKey(key),
items: tabList,
};
/**
* render
*/
return <> return <>
<Tabs <ProCard size="small" bordered tabs={{...restTabProps}}
activeKey={activeKey}
onChange={(key) => setActiveKey(key)}
size="small"
animated
destroyInactiveTabPane
style={{height: '100%'}}
items={[
{
key: 'desc',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.desc')}</Space>,
children: <SchemaDesc tableInfo={tableInfo} tableColumns={tableColumns}/>
},
{
key: 'query',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.query')}</Space>,
children: <SchemaDesc tableInfo={tableInfo} tableColumns={tableColumns}/>
},
{
key: 'gensql',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.gensql')}</Space>,
children: <SchemaDesc tableInfo={tableInfo} tableColumns={tableColumns}/>
},
{
key: 'console',
label: <Space><BookOutlined/>{l('rc.ds.detail.tag.console')}</Space>,
children: <SchemaDesc tableInfo={tableInfo} tableColumns={tableColumns}/>
},
]}
/> />
</>; </>;
}; };
......
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
import React, {useCallback, useEffect, useState} from 'react'; import React, {useCallback, useEffect, useState} from 'react';
import {DataSources} from '@/types/RegCenter/data'; import {DataSources} from '@/types/RegCenter/data';
import {Loading} from '@/pages/Other/Loading'; import {Button, Space} from 'antd';
import {Button, Col, Row, Space} from 'antd';
import {BackwardOutlined, ReloadOutlined} from '@ant-design/icons'; import {BackwardOutlined, ReloadOutlined} from '@ant-design/icons';
import {DataSourceDetailBackButton} from '@/components/StyledComponents'; import {DataSourceDetailBackButton} from '@/components/StyledComponents';
import {l} from '@/utils/intl'; import {l} from '@/utils/intl';
...@@ -27,6 +26,7 @@ import RightTagsRouter from '@/pages/RegCenter/DataSource/components/DataSourceD ...@@ -27,6 +26,7 @@ import RightTagsRouter from '@/pages/RegCenter/DataSource/components/DataSourceD
import {useNavigate} from '@umijs/max'; import {useNavigate} from '@umijs/max';
import {API_CONSTANTS, RESPONSE_CODE} from '@/services/constants'; import {API_CONSTANTS, RESPONSE_CODE} from '@/services/constants';
import {getDataByIdReturnResult, queryDataByParams} from '@/services/BusinessCrud'; import {getDataByIdReturnResult, queryDataByParams} from '@/services/BusinessCrud';
import {ProCard} from '@ant-design/pro-components';
type DataSourceDetailProps = { type DataSourceDetailProps = {
dataSource: Partial<DataSources.DataSource>; dataSource: Partial<DataSources.DataSource>;
...@@ -40,6 +40,7 @@ const DataSourceDetail: React.FC<DataSourceDetailProps> = (props) => { ...@@ -40,6 +40,7 @@ const DataSourceDetail: React.FC<DataSourceDetailProps> = (props) => {
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const [treeData, setTreeData] = useState<Partial<any>[]>([]); const [treeData, setTreeData] = useState<Partial<any>[]>([]);
const [tableColumns, setTableColumns] = useState<Partial<DataSources.Column[]>>([]); const [tableColumns, setTableColumns] = useState<Partial<DataSources.Column[]>>([]);
const [genSQL, setGenSQL] = useState<Partial<DataSources.SqlGeneration>>({});
const [tableInfo, setTableInfo] = useState<Partial<DataSources.Table>>({}); const [tableInfo, setTableInfo] = useState<Partial<DataSources.Table>>({});
const handleBackClick = () => { const handleBackClick = () => {
...@@ -49,10 +50,15 @@ const DataSourceDetail: React.FC<DataSourceDetailProps> = (props) => { ...@@ -49,10 +50,15 @@ const DataSourceDetail: React.FC<DataSourceDetailProps> = (props) => {
backClick(); backClick();
}; };
const clearState = () => {
const querySchemaTree = useCallback(async () => {
setTableColumns([]); setTableColumns([]);
setTableInfo({}); setTableInfo({});
setGenSQL({});
};
const querySchemaTree = useCallback(async () => {
clearState();
setLoading(true); setLoading(true);
await getDataByIdReturnResult(API_CONSTANTS.DATASOURCE_GET_SCHEMA_TABLES, dataSource.id).then((res) => { await getDataByIdReturnResult(API_CONSTANTS.DATASOURCE_GET_SCHEMA_TABLES, dataSource.id).then((res) => {
if (res.code === RESPONSE_CODE.SUCCESS) { if (res.code === RESPONSE_CODE.SUCCESS) {
...@@ -67,53 +73,72 @@ const DataSourceDetail: React.FC<DataSourceDetailProps> = (props) => { ...@@ -67,53 +73,72 @@ const DataSourceDetail: React.FC<DataSourceDetailProps> = (props) => {
querySchemaTree(); querySchemaTree();
}, []); }, []);
/**
* tree node click
*/
const onSchemaTreeNodeClick = useCallback(async (info: any) => { const onSchemaTreeNodeClick = useCallback(async (info: any) => {
const {node: nodeInfo, node: {isLeaf, parentId, name, fullInfo}} = info; const {node: {isLeaf, parentId, name, fullInfo}} = info;
if (isLeaf) { if (isLeaf) {
console.log(nodeInfo, 'nodeInfo'); /**
const data = await queryDataByParams(API_CONSTANTS.DATASOURCE_GET_COLUMNS_BY_TABLE, { * get table columns
*/
const columnsData = await queryDataByParams(API_CONSTANTS.DATASOURCE_GET_COLUMNS_BY_TABLE, {
id: dataSource.id, id: dataSource.id,
schemaName: parentId, schemaName: parentId,
tableName: name tableName: name
}); });
setTableColumns(data); /**
* get gen sql
*/
const genSQLData = await queryDataByParams(API_CONSTANTS.DATASOURCE_GET_GEN_SQL, {
id: dataSource.id,
schemaName: parentId,
tableName: name
});
setTableColumns(columnsData);
setGenSQL(genSQLData);
setTableInfo(fullInfo); setTableInfo(fullInfo);
} else { } else {
setTableColumns([]); clearState();
setTableInfo({});
} }
}, []); }, []);
/**
* render back button and refresh button
* @return {JSX.Element}
*/
const renderBackButton = () => {
return <>
<DataSourceDetailBackButton>
<Space size={'middle'}>
<Button size={'middle'} icon={<ReloadOutlined spin={loading}/>} type="primary"
onClick={() => querySchemaTree()}>{l('button.refresh')}</Button>
<Button size={'middle'} icon={<BackwardOutlined/>} type="primary"
onClick={handleBackClick}>{l('button.back')}</Button>
</Space>
</DataSourceDetailBackButton>
</>;
};
/**
* render
*/
return <> return <>
<DataSourceDetailBackButton> <ProCard loading={loading} ghost split="vertical">
<Space size={'large'}> <ProCard bordered className={'siderTree schemaTree'} colSpan="20%">
<Button size={'middle'} icon={<ReloadOutlined spin={loading}/>} type="primary" {/* tree */}
onClick={() => querySchemaTree()}>{l('button.refresh')}</Button> <SchemaTree onNodeClick={(info: any) => onSchemaTreeNodeClick(info)} treeData={treeData}/>
<Button size={'middle'} icon={<BackwardOutlined/>} type="primary" </ProCard>
onClick={handleBackClick}>{l('button.back')}</Button> <ProCard headerBordered>
</Space> {/* tags */}
</DataSourceDetailBackButton> <RightTagsRouter
{ tableInfo={tableInfo}
loading ? tableColumns={tableColumns}
<Loading loading={loading}/> genSQL={genSQL}
: rightButtons={renderBackButton()}
<> />
<Row> </ProCard>
<Col span={4} className={'siderTree schemaTree'}> </ProCard>
{/* tree */}
<SchemaTree onNodeClick={(info: any) => onSchemaTreeNodeClick(info)} treeData={treeData}/>
</Col>
<Col span={20}>
{/* tags */}
<RightTagsRouter
tableInfo={tableInfo}
tableColumns={tableColumns}
/>
</Col>
</Row>
</>
}
</>; </>;
}; };
......
...@@ -94,6 +94,7 @@ export const API_CONSTANTS = { ...@@ -94,6 +94,7 @@ export const API_CONSTANTS = {
// get schema by datasource id // get schema by datasource id
DATASOURCE_GET_SCHEMA_TABLES: "/api/database/getSchemasAndTables", DATASOURCE_GET_SCHEMA_TABLES: "/api/database/getSchemasAndTables",
DATASOURCE_GET_COLUMNS_BY_TABLE: "/api/database/listColumns", DATASOURCE_GET_COLUMNS_BY_TABLE: "/api/database/listColumns",
DATASOURCE_GET_GEN_SQL: "/api/database/getSqlGeneration",
// document list // document list
......
...@@ -155,6 +155,15 @@ declare namespace DataSources { ...@@ -155,6 +155,15 @@ declare namespace DataSources {
collation: string, collation: string,
}; };
/**
* table columns info
*/
export type SqlGeneration = {
flinkSqlCreate: string,
sqlSelect: string,
sqlCreate: string,
};
} }
......
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