mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-29 21:41:27 +08:00
♻️ refactor(connection): 拆分连接类型目录配置
- 抽出连接类型分组、默认端口和提示文案到独立 catalog - ConnectionModal 仅负责渲染数据源图标和选择流程 - 补充 catalog 单元测试并更新连接弹窗源码快照测试
This commit is contained in:
53
frontend/src/utils/connectionTypeCatalog.test.ts
Normal file
53
frontend/src/utils/connectionTypeCatalog.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
CONNECTION_TYPE_GROUPS,
|
||||
getAllConnectionTypeCatalogItems,
|
||||
getConnectionTypeDefaultPort,
|
||||
getConnectionTypeHint,
|
||||
} from './connectionTypeCatalog';
|
||||
|
||||
describe('connectionTypeCatalog', () => {
|
||||
it('keeps supported connection types grouped for the creation modal', () => {
|
||||
expect(CONNECTION_TYPE_GROUPS.map((group) => group.label)).toEqual([
|
||||
'关系型数据库',
|
||||
'国产数据库',
|
||||
'NoSQL',
|
||||
'时序数据库',
|
||||
'其他',
|
||||
]);
|
||||
|
||||
const keys = getAllConnectionTypeCatalogItems().map((item) => item.key);
|
||||
expect(keys).toContain('mysql');
|
||||
expect(keys).toContain('oceanbase');
|
||||
expect(keys).toContain('mongodb');
|
||||
expect(keys).toContain('redis');
|
||||
expect(keys).toContain('elasticsearch');
|
||||
expect(keys).toContain('jvm');
|
||||
expect(keys).toContain('custom');
|
||||
expect(new Set(keys).size).toBe(keys.length);
|
||||
});
|
||||
|
||||
it('returns the existing default port mapping for supported connection types', () => {
|
||||
expect(getConnectionTypeDefaultPort('mysql')).toBe(3306);
|
||||
expect(getConnectionTypeDefaultPort('oceanbase')).toBe(2881);
|
||||
expect(getConnectionTypeDefaultPort('diros')).toBe(9030);
|
||||
expect(getConnectionTypeDefaultPort('postgres')).toBe(5432);
|
||||
expect(getConnectionTypeDefaultPort('redis')).toBe(6379);
|
||||
expect(getConnectionTypeDefaultPort('oracle')).toBe(1521);
|
||||
expect(getConnectionTypeDefaultPort('mongodb')).toBe(27017);
|
||||
expect(getConnectionTypeDefaultPort('elasticsearch')).toBe(9200);
|
||||
expect(getConnectionTypeDefaultPort('sqlite')).toBe(0);
|
||||
expect(getConnectionTypeDefaultPort('duckdb')).toBe(0);
|
||||
expect(getConnectionTypeDefaultPort('unknown')).toBe(3306);
|
||||
});
|
||||
|
||||
it('keeps concise localized hints for special connection types', () => {
|
||||
expect(getConnectionTypeHint('redis')).toBe('单机 / 集群');
|
||||
expect(getConnectionTypeHint('mongodb')).toBe('单机 / 副本集');
|
||||
expect(getConnectionTypeHint('elasticsearch')).toContain('Mapping');
|
||||
expect(getConnectionTypeHint('oceanbase')).toBe('MySQL / Oracle 租户');
|
||||
expect(getConnectionTypeHint('duckdb')).toBe('本地文件连接');
|
||||
expect(getConnectionTypeHint('mysql')).toBe('标准连接配置');
|
||||
});
|
||||
});
|
||||
137
frontend/src/utils/connectionTypeCatalog.ts
Normal file
137
frontend/src/utils/connectionTypeCatalog.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
export type ConnectionTypeCatalogItem = {
|
||||
key: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type ConnectionTypeCatalogGroup = {
|
||||
label: string;
|
||||
items: ConnectionTypeCatalogItem[];
|
||||
};
|
||||
|
||||
export const CONNECTION_TYPE_GROUPS: ConnectionTypeCatalogGroup[] = [
|
||||
{
|
||||
label: '关系型数据库',
|
||||
items: [
|
||||
{ key: 'mysql', name: 'MySQL' },
|
||||
{ key: 'mariadb', name: 'MariaDB' },
|
||||
{ key: 'diros', name: 'Doris' },
|
||||
{ key: 'starrocks', name: 'StarRocks' },
|
||||
{ key: 'sphinx', name: 'Sphinx' },
|
||||
{ key: 'clickhouse', name: 'ClickHouse' },
|
||||
{ key: 'postgres', name: 'PostgreSQL' },
|
||||
{ key: 'sqlserver', name: 'SQL Server' },
|
||||
{ key: 'iris', name: 'InterSystems IRIS' },
|
||||
{ key: 'sqlite', name: 'SQLite' },
|
||||
{ key: 'duckdb', name: 'DuckDB' },
|
||||
{ key: 'oracle', name: 'Oracle' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '国产数据库',
|
||||
items: [
|
||||
{ key: 'oceanbase', name: 'OceanBase' },
|
||||
{ key: 'dameng', name: 'Dameng (达梦)' },
|
||||
{ key: 'kingbase', name: 'Kingbase (人大金仓)' },
|
||||
{ key: 'highgo', name: 'HighGo (瀚高)' },
|
||||
{ key: 'vastbase', name: 'Vastbase (海量)' },
|
||||
{ key: 'opengauss', name: 'OpenGauss' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'NoSQL',
|
||||
items: [
|
||||
{ key: 'mongodb', name: 'MongoDB' },
|
||||
{ key: 'redis', name: 'Redis' },
|
||||
{ key: 'elasticsearch', name: 'Elasticsearch' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '时序数据库',
|
||||
items: [
|
||||
{ key: 'tdengine', name: 'TDengine' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '其他',
|
||||
items: [
|
||||
{ key: 'jvm', name: 'JVM Runtime' },
|
||||
{ key: 'custom', name: 'Custom (自定义)' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const getConnectionTypeDefaultPort = (type: string): number => {
|
||||
switch (String(type || '').trim().toLowerCase()) {
|
||||
case 'jvm':
|
||||
return 9010;
|
||||
case 'mysql':
|
||||
return 3306;
|
||||
case 'oceanbase':
|
||||
return 2881;
|
||||
case 'doris':
|
||||
case 'diros':
|
||||
case 'starrocks':
|
||||
return 9030;
|
||||
case 'sphinx':
|
||||
return 9306;
|
||||
case 'clickhouse':
|
||||
return 9000;
|
||||
case 'postgres':
|
||||
case 'opengauss':
|
||||
return 5432;
|
||||
case 'redis':
|
||||
return 6379;
|
||||
case 'tdengine':
|
||||
return 6041;
|
||||
case 'oracle':
|
||||
return 1521;
|
||||
case 'dameng':
|
||||
return 5236;
|
||||
case 'kingbase':
|
||||
return 54321;
|
||||
case 'sqlserver':
|
||||
return 1433;
|
||||
case 'iris':
|
||||
return 1972;
|
||||
case 'mongodb':
|
||||
return 27017;
|
||||
case 'elasticsearch':
|
||||
return 9200;
|
||||
case 'highgo':
|
||||
return 5866;
|
||||
case 'mariadb':
|
||||
return 3306;
|
||||
case 'vastbase':
|
||||
return 5432;
|
||||
case 'sqlite':
|
||||
case 'duckdb':
|
||||
return 0;
|
||||
default:
|
||||
return 3306;
|
||||
}
|
||||
};
|
||||
|
||||
export const getConnectionTypeHint = (type: string): string => {
|
||||
switch (String(type || '').trim().toLowerCase()) {
|
||||
case 'jvm':
|
||||
return 'JMX / Endpoint / Agent';
|
||||
case 'custom':
|
||||
return '自定义驱动与 DSN';
|
||||
case 'redis':
|
||||
return '单机 / 集群';
|
||||
case 'mongodb':
|
||||
return '单机 / 副本集';
|
||||
case 'elasticsearch':
|
||||
return '支持索引浏览、Mapping 检查、JSON DSL 和 query_string 查询';
|
||||
case 'oceanbase':
|
||||
return 'MySQL / Oracle 租户';
|
||||
case 'sqlite':
|
||||
case 'duckdb':
|
||||
return '本地文件连接';
|
||||
default:
|
||||
return '标准连接配置';
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllConnectionTypeCatalogItems = (): ConnectionTypeCatalogItem[] =>
|
||||
CONNECTION_TYPE_GROUPS.flatMap((group) => group.items);
|
||||
Reference in New Issue
Block a user