Files
MyGoNavi/frontend/src/utils/customConnectionDsn.ts
tianqijiuyun-latiao 255cc14bf6 🐛 fix(config-secret-storage): 修复密文编辑与状态残留问题
- 修复自定义连接编辑时已保存 DSN 无法留空沿用的问题
- 重置 AI 供应商编辑态与清空密钥开关,避免关闭后状态残留
- 对齐浏览器 mock 复制连接的 config.id 语义并补充回归测试
2026-04-05 11:59:38 +08:00

28 lines
766 B
TypeScript

export interface CustomConnectionDsnState {
dsnInput: unknown;
hasStoredSecret?: boolean;
clearStoredSecret?: boolean;
}
export const getCustomConnectionDsnValidationMessage = ({
dsnInput,
hasStoredSecret,
clearStoredSecret,
}: CustomConnectionDsnState): string | null => {
const dsnText = String(dsnInput ?? '').trim();
if (dsnText !== '') {
return null;
}
if (hasStoredSecret && !clearStoredSecret) {
return null;
}
if (hasStoredSecret && clearStoredSecret) {
return '请输入新的连接字符串,或取消清除已保存 DSN';
}
return '请输入连接字符串';
};
export const shouldAllowBlankCustomDsn = (state: CustomConnectionDsnState): boolean => (
getCustomConnectionDsnValidationMessage(state) === null
);