From ca9eb65fddaa0dfd7d7f89e3b7c0d2f20073f4bf Mon Sep 17 00:00:00 2001 From: Syngnat Date: Sun, 14 Jun 2026 12:59:05 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(connection-modal):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20MQTT=20=E6=97=A0=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E8=AF=AF=E5=88=A4=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConnectionModal.edit-password.test.tsx | 13 +++++++++--- frontend/src/components/ConnectionModal.tsx | 21 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) 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 }} > - +