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

refactor: delete database alias (#1598)

* refactor: delete database alias * format code * refactor: delete database tsx * format code * format code * format code
parent 623fc445
......@@ -24,8 +24,6 @@ import org.dinky.metadata.driver.DriverConfig;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
......@@ -46,17 +44,10 @@ public class DataBase extends SuperEntity {
private Integer tenantId;
@TableField(fill = FieldFill.INSERT)
private String alias;
private String groupName;
private String type;
private String url;
private String username;
private String password;
private String note;
......
......@@ -12,9 +12,6 @@
<if test='param.name!=null and param.name!=""'>
and a.name like "%${param.name}%"
</if>
<if test='param.alias!=null and param.alias!=""'>
and a.alias like "%${param.alias}%"
</if>
<if test='param.createTime!=null and param.createTime!=""'>
and a.create_time <![CDATA[>=]]> str_to_date( #{param.createTime},'%Y-%m-%d %H:%i:%s')
</if>
......
......@@ -168,7 +168,6 @@ CREATE TABLE `dinky_database` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`tenant_id` int(11) NOT NULL DEFAULT 1 COMMENT 'tenant id',
`name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'database name',
`alias` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'database alias',
`group_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'Default' COMMENT 'database belong group name',
`type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'database type',
`ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'database ip',
......
......@@ -71,4 +71,4 @@ ALTER TABLE dinky_catalogue RENAME INDEX `dlink_catalogue_un` TO `catalogue_un_i
ALTER TABLE dinky_schema_history RENAME INDEX `dlink_schema_history_s_idx` TO `schema_history_idx`;
ALTER TABLE dinky_database DROP COLUMN `alias`;
/*
*
* 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 {Button, Drawer, Empty, Modal, Table, Tooltip} from "antd";
import {StateType} from "@/pages/DataStudio/model";
import {connect} from "umi";
import React, {useState} from "react";
import {PlusOutlined, ReloadOutlined} from '@ant-design/icons';
import {showDataBase} from "../../StudioEvent/DDL";
import DBForm from "@/pages/RegistrationCenter/DataBase/components/DBForm";
import {Scrollbars} from 'react-custom-scrollbars';
import ProDescriptions from "@ant-design/pro-descriptions";
import {handleRemove} from "@/components/Common/crud";
import {l} from "@/utils/intl";
const StudioDataBase = (props: any) => {
const {database, toolHeight, dispatch} = props;
const [chooseDBModalVisible, handleDBFormModalVisible] = useState<boolean>(false);
const [values, setValues] = useState<any>({});
const [row, setRow] = useState<{}>();
const getColumns = () => {
return [{
title: "数据源名",
dataIndex: "alias",
key: "alias",
sorter: true,
render: (dom, entity) => {
return <a onClick={() => setRow(entity)}>{entity.alias === "" ? entity.name : entity.alias}</a>;
},
}];
};
const getAllColumns = () => {
return [{
title: "ID",
dataIndex: "id",
key: "id",
}, {
title: "数据源名",
dataIndex: "alias",
}, {
title: '唯一标识',
dataIndex: 'name',
},
{
title: '分组类型',
dataIndex: 'groupName',
filters: [
{
text: '来源',
value: '来源',
},
{
text: '数仓',
value: '数仓',
},
{
text: '应用',
value: '应用',
},
{
text: '备份',
value: '备份',
}, {
text: '其他',
value: '其他',
},
],
filterMultiple: false,
valueEnum: {
'yarn-session': {text: 'Yarn Session'},
'standalone': {text: 'Standalone'},
'yarn-per-job': {text: 'Yarn Per-Job'},
'yarn-application': {text: 'Yarn Application'},
},
},
{
title: 'URL',
dataIndex: 'url',
valueType: 'textarea',
},
{
title: '用户名',
dataIndex: 'username',
}, {
title: '版本',
sorter: true,
dataIndex: 'dbVersion',
},
{
title: '状态',
dataIndex: 'status',
filters: [
{
text: '正常',
value: 1,
},
{
text: '异常',
value: 0,
},
],
filterMultiple: false,
valueEnum: {
1: {text: '正常', status: 'Success'},
0: {text: '异常', status: 'Error'},
},
},
{
title: l('global.table.note'),
sorter: true,
valueType: 'textarea',
dataIndex: 'note',
},
{
title: l('global.table.isEnable'),
dataIndex: 'enabled',
filters: [
{
text: l('status.enabled'),
value: 1,
},
{
text: l('status.disabled'),
value: 0,
},
],
filterMultiple: false,
valueEnum: {
true: {text: l('status.enabled'), status: 'Success'},
false: {text: l('status.disabled'), status: 'Error'},
},
},
{
title: '最近的健康时间',
dataIndex: 'healthTime',
valueType: 'dateTime',
}, {
title: '最近的心跳检测时间',
dataIndex: 'heartbeatTime',
valueType: 'dateTime',
}, {
title: l('global.table.createTime'),
dataIndex: 'createTime',
valueType: 'dateTime',
},
{
title: l('global.table.lastUpdateTime'),
dataIndex: 'updateTime',
valueType: 'dateTime',
},
{
title: l('global.table.operate'),
dataIndex: 'option',
valueType: 'option',
render: (_, record) => [
<Button type="dashed" onClick={() => onModifyDataBase(record)}>
{l('button.edit')}
</Button>, <Button danger onClick={() => onDeleteDataBase(record)}>
{l('button.delete')}
</Button>
],
},];
};
const onRefreshDataBase = () => {
showDataBase(dispatch);
};
const onCreateDataBase = () => {
setValues({});
handleDBFormModalVisible(true);
};
const onModifyDataBase = (record) => {
setValues(record);
handleDBFormModalVisible(true);
};
const onDeleteDataBase = (record) => {
Modal.confirm({
title: '删除数据源',
content: `确定删除该数据源【${record.alias === "" ? record.name : record.alias}】吗?`,
okText: l('button.confirm'),
cancelText: l('button.cancel'),
onOk: async () => {
await handleRemove('api/database', [record]);
setRow({});
onRefreshDataBase();
}
});
};
return (
<>
<Tooltip title="新建数据源">
<Button
type="text"
icon={<PlusOutlined/>}
onClick={onCreateDataBase}
/>
</Tooltip>
<Tooltip title="刷新数据源">
<Button
type="text"
icon={<ReloadOutlined/>}
onClick={onRefreshDataBase}
/>
</Tooltip>
<Scrollbars style={{height: (toolHeight - 32)}}>
{database.length > 0 ? (
<Table
dataSource={database}
columns={getColumns()}
pagination={{
defaultPageSize: 10,
showSizeChanger: true,
}}
size="small"/>) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE}/>)}
<DBForm
onCancel={() => {
handleDBFormModalVisible(false);
setValues({});
}}
modalVisible={chooseDBModalVisible}
onSubmit={() => {
setRow({});
onRefreshDataBase();
}}
values={values}
/>
<Drawer
width={600}
visible={!!row?.id}
onClose={() => {
setRow(undefined);
}}
closable={false}
>
{row?.name && (
<ProDescriptions
column={2}
title={row?.name}
request={async () => ({
data: row || {},
})}
params={{
id: row?.name,
}}
columns={getAllColumns()}
/>
)}
</Drawer>
</Scrollbars>
</>
);
};
export default connect(({Studio}: { Studio: StateType }) => ({
database: Studio.database,
toolHeight: Studio.toolHeight,
}))(StudioDataBase);
......@@ -90,10 +90,10 @@ const StudioMetaData = (props: any) => {
};
const getDataBaseOptions = () => {
return <>{database.map(({id, name, alias, type, enabled}) => (
return <>{database.map(({id, name, type, enabled}) => (
<Option value={id}
label={<><Tag color={enabled ? "processing" : "error"}>{type}</Tag>{alias === "" ? name : alias}</>}>
<Tag color={enabled ? "processing" : "error"}>{type}</Tag>{alias === "" ? name : alias}
label={<><Tag color={enabled ? "processing" : "error"}>{type}</Tag>{name}</>}>
<Tag color={enabled ? "processing" : "error"}>{type}</Tag>{name}
</Option>
))}</>
};
......
......@@ -49,10 +49,6 @@ const StudioLeftTool = (props: any) => {
{/*<TabPane tab={<span><ClusterOutlined/> {l('pages.datastudio.label.cluster')}</span>} key="Cluster">*/}
{/* <StudioCluster/>*/}
{/*</TabPane>*/}
{/*<TabPane tab={<span><DatabaseOutlined/> {l('pages.datastudio.label.datasource')}</span>}*/}
{/* key="DataSource">*/}
{/* <StudioDataBase/>*/}
{/*</TabPane>*/}
<TabPane tab={<span><AppstoreOutlined/> {l('pages.datastudio.label.meta')}</span>} key="MetaData">
<StudioMetaData/>
</TabPane>
......
......@@ -57,7 +57,7 @@ const StudioSqlConfig = (props: any) => {
for (const item of database) {
if (item.type.toUpperCase() === current.task.dialect.toUpperCase()) {
const tag = (<><Tag
color={item.enabled ? "processing" : "error"}>{item.type}</Tag>{item.alias === "" ? item.name : item.alias}</>);
color={item.enabled ? "processing" : "error"}>{item.type}</Tag>{item.name}</>);
itemList.push(<Option key={item.id} value={item.id} label={tag}>
{tag}
</Option>)
......
......@@ -703,7 +703,6 @@ export default {
'pages.rc.db.Management': 'DataSource',
'pages.rc.db.name': 'Name',
'pages.rc.db.alias': 'Alias',
'pages.rc.db.groupName': 'Group Type',
'pages.rc.db.url': 'Database Connection URL',
'pages.rc.db.username': 'Username',
......@@ -714,7 +713,6 @@ export default {
'pages.rc.db.modify': 'Modify DataSource',
'pages.rc.db.delete': 'Delete DataSource',
'pages.rc.db.deleteConfirm': 'Are you sure you want to delete this data source {dbName}? ',
'pages.rc.db.aliasPlaceholder': 'Please enter alias!',
'pages.rc.db.namePlaceholder': 'Please enter name!',
'pages.rc.db.urlPlaceholder': 'Please enter a properly formatted url connection!',
'pages.rc.db.flinkConfigPlaceholder': 'Please specify the default Config of Flink With!',
......
......@@ -705,7 +705,6 @@ export default {
'pages.rc.db.Management': '数据源',
'pages.rc.db.name': '名称',
'pages.rc.db.alias': '别名',
'pages.rc.db.groupName': '分组类型',
'pages.rc.db.url': '数据库连接 URL',
'pages.rc.db.username': '用户名',
......@@ -716,7 +715,6 @@ export default {
'pages.rc.db.modify': '修改数据源',
'pages.rc.db.delete': '删除数据源',
'pages.rc.db.deleteConfirm': '确定删除该数据源{dbName}吗?',
'pages.rc.db.aliasPlaceholder': '请输入别名!',
'pages.rc.db.namePlaceholder': '请输入名称!',
'pages.rc.db.urlPlaceholder': '请输入格式正确的 url 连接!',
'pages.rc.db.flinkConfigPlaceholder': '请指定 Flink With 的默认配置!',
......
......@@ -102,7 +102,7 @@ const DBForm: React.FC<UpdateFormProps> = (props) => {
width={"40%"}
bodyStyle={{padding: '32px 40px 48px' , height: '600px', overflowY: 'auto'}}
title={values.id ? l('pages.rc.db.modify') : l('pages.rc.db.create')}
visible={modalVisible}
open={modalVisible}
onCancel={() => {
setDbType(undefined);
handleChooseDBModalVisible();
......
......@@ -47,7 +47,6 @@ const DataBaseForm: React.FC<ClickHouseFormProps> = (props) => {
const [formVals, setFormVals] = useState<Partial<DataBaseItem>>({
id: props.values.id,
name: props.values.name,
alias: props.values.alias,
groupName: props.values.groupName,
url: props.values.url,
username: props.values.username,
......@@ -85,7 +84,7 @@ const DataBaseForm: React.FC<ClickHouseFormProps> = (props) => {
form.resetFields();
};
const renderContent = (formVals) => {
const renderContent = (formVals: Partial<DataBaseItem>) => {
return (
<>
<Divider>{type}</Divider>
......@@ -95,12 +94,6 @@ const DataBaseForm: React.FC<ClickHouseFormProps> = (props) => {
rules={[{required: true, message: l('pages.rc.db.namePlaceholder')}]}>
<Input placeholder={l('pages.rc.db.namePlaceholder')}/>
</Form.Item>
<Form.Item
name="alias"
label={l('pages.rc.db.alias')}
>
<Input placeholder={l('pages.rc.db.aliasPlaceholder')}/>
</Form.Item>
<Form.Item
name="groupName"
label={l('pages.rc.db.groupName')}
......@@ -176,7 +169,6 @@ const DataBaseForm: React.FC<ClickHouseFormProps> = (props) => {
initialValues={{
id: formVals.id,
name: formVals.name,
alias: formVals.alias,
type: formVals.type,
groupName: formVals.groupName,
url: formVals.url,
......
......@@ -142,14 +142,11 @@ const DataBaseTableList: React.FC<{}> = (props: any) => {
]}
>
<Card.Meta
title={<Tag color="gray" key={row.alias}>
{row.alias}
title={<Tag color="gray" key={row.name}>
{row.name}
</Tag>}
description={(
<Space size={0}>
<Tag key={row.name}>
{row.name}
</Tag>
<Tag color="blue" key={row.groupName}>
{row.groupName}
</Tag>
......
......@@ -75,7 +75,6 @@ export type ClusterConfigurationTableListItem = {
export type DataBaseItem = {
id: number,
name: string,
alias: string,
groupName: string,
type: string,
url: 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