Skip to content

Commit decc7f3

Browse files
committed
[feature] introduce catalog frondend.
1 parent 2d51eb0 commit decc7f3

File tree

5 files changed

+209
-0
lines changed

5 files changed

+209
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { defHttp } from '/@/utils/http/axios';
2+
import { CatalogParams, DatabaseParams, TableParams } from './catalog.type';
3+
4+
enum API {
5+
CATALOG_LIST = '/flink/catalog/list',
6+
CATALOG_CREATE = '/flink/catalog/create',
7+
CATALOG_DELETE = '/flink/catalog/delete',
8+
DATABASE_LIST = '/flink/database/list',
9+
DATABASE_CREATE = '/flink/database/create',
10+
DATABASE_DELETE = '/flink/database/delete',
11+
TABLE_LIST = '/flink/table/list',
12+
TABLE_CREATE = '/flink/table/create',
13+
TABLE_DELETE = '/flink/table/delete',
14+
}
15+
16+
17+
export function fetchCatalogList(params?: any) {
18+
return defHttp.post({ url: API.CATALOG_LIST, params });
19+
}
20+
21+
export function fetchCreateCatalog(data: CatalogParams) {
22+
return defHttp.post({ url: API.CATALOG_CREATE, data });
23+
}
24+
25+
export function fetchRemoveCatalog(id: string) {
26+
return defHttp.post({ url: API.CATALOG_DELETE, data: { id } });
27+
}
28+
29+
30+
export function fetchDatabaseList(params: { catalogId: string }) {
31+
return defHttp.post({ url: API.DATABASE_LIST, params });
32+
}
33+
34+
export function fetchCreateDatabase(data: DatabaseParams) {
35+
return defHttp.post({ url: API.DATABASE_CREATE, data });
36+
}
37+
38+
export function fetchRemoveDatabase(data: { catalogId: string; name: string }) {
39+
return defHttp.post({ url: API.DATABASE_DELETE, data });
40+
}
41+
42+
43+
export function fetchTableList(params: { catalogId: string; databaseName: string }) {
44+
return defHttp.post({ url: API.TABLE_LIST, params });
45+
}
46+
47+
export function fetchCreateTable(data: TableParams) {
48+
return defHttp.post({ url: API.TABLE_CREATE, data });
49+
}
50+
51+
export function fetchRemoveTable(data: { catalogId: string; databaseName: string; name: string }) {
52+
return defHttp.post({ url: API.TABLE_DELETE, data });
53+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export interface CatalogParams {
2+
catalogName: string;
3+
catalogType: string;
4+
description?: string;
5+
config?: Record<string, string>;
6+
}
7+
8+
export interface CatalogRecord {
9+
id: string;
10+
catalogName: string;
11+
catalogType: string;
12+
createTime: string;
13+
updateTime: string;
14+
}
15+
16+
export interface DatabaseParams {
17+
name: string;
18+
catalogId: string;
19+
catalogName?: string;
20+
description?: string;
21+
ignoreIfExits?: boolean;
22+
}
23+
24+
export interface DatabaseRecord {
25+
name: string;
26+
catalogId: string;
27+
catalogName: string;
28+
description?: string;
29+
}
30+
31+
export interface TableColumn {
32+
name: string;
33+
type: string;
34+
comment?: string;
35+
}
36+
37+
export interface TableParams {
38+
catalogId: string;
39+
catalogName?: string;
40+
databaseName: string;
41+
name: string;
42+
description?: string;
43+
tableColumns?: TableColumn[];
44+
partitionKey?: string[];
45+
tableOptions?: Record<string, string>;
46+
}
47+
48+
export interface TableRecord {
49+
name: string;
50+
catalogId: string;
51+
catalogName: string;
52+
databaseName: string;
53+
description?: string;
54+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
browser: 'Catalog Browser',
3+
tableInfo: 'Table Information',
4+
tableName: 'Table Name',
5+
tableList: 'Table List',
6+
selectDbHint: 'Please select a database from the left tree',
7+
catalogName: 'Catalog Name',
8+
databaseName: 'Database Name',
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
browser: 'Catalog 浏览',
3+
tableInfo: '表信息',
4+
tableName: '表名称',
5+
tableList: '表列表',
6+
selectDbHint: '请从左侧树中选择一个数据库',
7+
catalogName: 'Catalog 名称',
8+
databaseName: '数据库名称',
9+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<script lang="ts" setup name="CatalogView">
2+
import { ref, onMounted } from 'vue';
3+
import { PageWrapper } from '/@/components/Page';
4+
import { BasicTable, useTable } from '/@/components/Table';
5+
import { Card, Empty } from 'ant-design-vue';
6+
import { BasicTree } from '/@/components/Tree';
7+
import { fetchCatalogList, fetchDatabaseList, fetchTableList } from '/@/api/flink/catalog';
8+
import { useI18n } from '/@/hooks/web/useI18n';
9+
10+
const { t } = useI18n();
11+
const treeData = ref<any[]>([]);
12+
const currentCatalogId = ref<string>('');
13+
const currentDatabaseName = ref<string>('');
14+
15+
const [registerTable, { reload, setColumns }] = useTable({
16+
title: t('flink.catalog.tableList'),
17+
api: fetchTableList,
18+
columns: [
19+
{ dataIndex: 'name', title: t('flink.catalog.tableName') },
20+
{ dataIndex: 'description', title: t('common.description') },
21+
],
22+
beforeFetch: (params) => {
23+
params.catalogId = currentCatalogId.value;
24+
params.databaseName = currentDatabaseName.value;
25+
return params;
26+
},
27+
immediate: false,
28+
useSearchForm: false,
29+
showTableSetting: true,
30+
canResize: true,
31+
});
32+
33+
async function loadTree() {
34+
const catalogs = await fetchCatalogList();
35+
if (!catalogs) return;
36+
37+
treeData.value = await Promise.all(
38+
catalogs.map(async (catalog) => {
39+
const dbs = await fetchDatabaseList({ catalogId: catalog.id });
40+
return {
41+
title: catalog.catalogName,
42+
key: catalog.id,
43+
children: dbs?.map((db) => ({
44+
title: db.name,
45+
key: `${catalog.id}:${db.name}`,
46+
isLeaf: true,
47+
catalogId: catalog.id,
48+
dbName: db.name,
49+
})),
50+
};
51+
}),
52+
);
53+
}
54+
55+
function handleSelect(keys: string[], { node }) {
56+
if (keys.length === 0) return;
57+
if (node.dataRef.children) {
58+
// It's a catalog, maybe expand?
59+
return;
60+
}
61+
// It's a database
62+
currentCatalogId.value = node.dataRef.catalogId;
63+
currentDatabaseName.value = node.dataRef.dbName;
64+
reload();
65+
}
66+
67+
onMounted(() => {
68+
loadTree();
69+
});
70+
</script>
71+
72+
<template>
73+
<PageWrapper contentFullHeight class="flex p-4">
74+
<Card class="w-1/4 mr-4 !h-full overflow-auto" :title="t('flink.catalog.browser')">
75+
<BasicTree :treeData="treeData" @select="handleSelect" defaultExpandAll />
76+
</Card>
77+
<Card class="w-3/4 !h-full" :title="t('flink.catalog.tableInfo')">
78+
<div v-if="!currentDatabaseName" class="flex justify-center items-center h-full">
79+
<Empty :description="t('flink.catalog.selectDbHint')" />
80+
</div>
81+
<BasicTable v-else @register="registerTable" />
82+
</Card>
83+
</PageWrapper>
84+
</template>

0 commit comments

Comments
 (0)