fix: make port field editable

This commit is contained in:
Tianzhou Chen
2023-05-21 15:22:28 +08:00
parent a994013fcd
commit ad31e18ea2

View File

@ -37,33 +37,26 @@ const SSLTypeOptions = [
}, },
]; ];
const defaultPort = {
[Engine.MySQL]: "3306",
[Engine.PostgreSQL]: "5432",
[Engine.MSSQL]: "1433",
[Engine.TiDBServerless]: "4000",
};
const engines = [ const engines = [
{ {
type: Engine.MySQL, type: Engine.MySQL,
name: "MySQL", name: "MySQL",
defualtPort: "3306", defaultPort: "3306",
}, },
{ {
type: Engine.PostgreSQL, type: Engine.PostgreSQL,
name: "PostgreSQL", name: "PostgreSQL",
defualtPort: "5432", defaultPort: "5432",
}, },
{ {
type: Engine.MSSQL, type: Engine.MSSQL,
name: "SQL Server", name: "SQL Server",
defualtPort: "1433", defaultPort: "1433",
}, },
{ {
type: Engine.TiDBServerless, type: Engine.TiDBServerless,
name: "TiDB Serverless", name: "TiDB Serverless",
defualtPort: "4000", defaultPort: "4000",
}, },
]; ];
@ -72,7 +65,7 @@ const defaultConnection: Connection = {
title: "", title: "",
engineType: Engine.MySQL, engineType: Engine.MySQL,
host: "", host: "",
port: defaultPort[Engine.MySQL], port: "3306",
username: "", username: "",
password: "", password: "",
}; };
@ -126,7 +119,6 @@ const CreateConnectionModal = (props: Props) => {
setConnection({ setConnection({
...connection, ...connection,
...state, ...state,
port: defaultPort[state.engineType || Engine.MySQL],
}); });
}; };
@ -249,7 +241,7 @@ const CreateConnectionModal = (props: Props) => {
<Radio <Radio
value={engine.type} value={engine.type}
checked={connection.engineType === engine.type} checked={connection.engineType === engine.type}
onChange={(value) => setPartialConnection({ engineType: value as Engine })} onChange={(value) => setPartialConnection({ engineType: value as Engine, port: engine.defaultPort as string })}
/> />
<EngineIcon className="h-8 w-8 rounded-full" engine={engine.type} /> <EngineIcon className="h-8 w-8 rounded-full" engine={engine.type} />
<label htmlFor={engine.type} className="ml-3 block text-sm font-medium leading-6 text-gray-900"> <label htmlFor={engine.type} className="ml-3 block text-sm font-medium leading-6 text-gray-900">