diff --git a/frontend/src/components/ConnectionModal.edit-password.test.tsx b/frontend/src/components/ConnectionModal.edit-password.test.tsx index 735b666..112d093 100644 --- a/frontend/src/components/ConnectionModal.edit-password.test.tsx +++ b/frontend/src/components/ConnectionModal.edit-password.test.tsx @@ -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;'); diff --git a/frontend/src/components/ConnectionModal.tsx b/frontend/src/components/ConnectionModal.tsx index 0a65376..ee4cb48 100644 --- a/frontend/src/components/ConnectionModal.tsx +++ b/frontend/src/components/ConnectionModal.tsx @@ -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 }} > - +