🐛 fix(connection-modal): 修复 MQTT 无认证用户名误判必填

This commit is contained in:
Syngnat
2026-06-14 12:59:05 +08:00
parent 8d5a24992a
commit ca9eb65fdd
2 changed files with 29 additions and 5 deletions

View File

@@ -32,15 +32,22 @@ describe('ConnectionModal data source registry', () => {
expect(source).toContain('icon: getDbIcon(item.key, undefined, 36)');
expect(source).toContain('type === "elasticsearch"');
expect(source).toContain("return '支持索引浏览、Mapping 检查、JSON DSL 和 query_string 查询';");
expect(source).toContain('const PRIMARY_USERNAME_OPTIONAL_TYPES = new Set([');
expect(source).toContain('"mqtt",');
expect(source).toContain(
'type === "clickhouse" ? "default" : (type === "redis" || type === "elasticsearch" || type === "chroma" || type === "qdrant" || type === "rocketmq" || type === "mqtt" || type === "kafka" || type === "rabbitmq") ? "" : "root";',
);
expect(source).toContain(
'placeholder={(dbType === "elasticsearch" || dbType === "chroma" || dbType === "qdrant" || dbType === "rocketmq" || dbType === "mqtt" || dbType === "kafka" || dbType === "rabbitmq") ? "未开启认证可留空" : undefined}',
);
expect(source).toContain('PRIMARY_USERNAME_OPTIONAL_TYPES.has(dbType)');
expect(source).toContain('label="显示数据库 (留空显示全部)"');
});
it('keeps MQTT username optional during test-connection validation', () => {
expect(source).toContain('"mqtt",');
expect(source).toContain('PRIMARY_USERNAME_OPTIONAL_TYPES.has(dbType)');
expect(source).toContain(': [createUriAwareRequiredRule("请输入用户名")]');
expect(source).toContain('? "未开启认证可留空"');
});
it('exposes Chroma in the create-connection picker with vector defaults', () => {
expect(source).toContain("case 'chroma':");
expect(source).toContain('return 8000;');

View File

@@ -140,6 +140,16 @@ const MAX_URI_LENGTH = 4096;
const MAX_CONNECTION_PARAMS_LENGTH = 4096;
const MAX_URI_HOSTS = 32;
const MAX_TIMEOUT_SECONDS = 3600;
const PRIMARY_USERNAME_OPTIONAL_TYPES = new Set([
"mongodb",
"elasticsearch",
"chroma",
"qdrant",
"rocketmq",
"mqtt",
"kafka",
"rabbitmq",
]);
const CONNECTION_MODAL_WIDTH = 960;
const CONNECTION_MODAL_BODY_HEIGHT = 620;
const REDIS_DEFAULT_DATABASE_COUNT = 16;
@@ -5634,13 +5644,20 @@ const ConnectionModal: React.FC<{
name="user"
label={dbType === "rocketmq" ? "Access Key" : "用户名"}
rules={
(dbType === "mongodb" || dbType === "elasticsearch" || dbType === "chroma" || dbType === "qdrant" || dbType === "rocketmq" || dbType === "kafka" || dbType === "rabbitmq")
PRIMARY_USERNAME_OPTIONAL_TYPES.has(dbType)
? []
: [createUriAwareRequiredRule("请输入用户名")]
}
style={{ marginBottom: 0 }}
>
<Input {...noAutoCapInputProps} placeholder={(dbType === "elasticsearch" || dbType === "chroma" || dbType === "qdrant" || dbType === "rocketmq" || dbType === "mqtt" || dbType === "kafka" || dbType === "rabbitmq") ? "未开启认证可留空" : undefined} />
<Input
{...noAutoCapInputProps}
placeholder={
PRIMARY_USERNAME_OPTIONAL_TYPES.has(dbType)
? "未开启认证可留空"
: undefined
}
/>
</Form.Item>
<Form.Item
name="password"