Skip to content

Commit 60fd483

Browse files
author
lhy
committed
feat(配置): 添加PawSQL版本选择功能
在配置表单中新增版本选择功能,支持选择Cloud、社区版和企业版。根据选择的版本自动设置默认值和字段状态,以提升用户体验。
1 parent 3d496d5 commit 60fd483

9 files changed

Lines changed: 76 additions & 5 deletions

File tree

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@
133133
"title": "%config.initialization.email.title%",
134134
"order": 3
135135
},
136+
"pawsql.version": {
137+
"type": "string",
138+
"default": "",
139+
"title": "%config.initialization.version.title%",
140+
"order": 0
141+
},
136142
"pawsql.backendUrl": {
137143
"type": "string",
138144
"default": "",

package.nls.en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"commands.setDefaultWorkspace": "Set as Default Workspace",
88

99
"config.initialization.title": "PawSQL Setup",
10+
"config.initialization.version.title": "PawSQL Version",
1011
"config.initialization.backendUrl.title": "PawSQL Server",
1112
"config.initialization.email.title": "PawSQL Account",
1213
"config.initialization.apiKey.title": "ApiKey",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"commands.createWorkspace": "创建工作空间",
77
"commands.setDefaultWorkspace": "设置为默认工作空间",
88
"config.initialization.title": "PawSQL Client",
9+
"config.initialization.version.title": "PawSQL 版本",
910
"config.initialization.backendUrl.title": "PawSQL 服务器",
1011
"config.initialization.frontendUrl.title": "PawSQL 网站",
1112
"config.initialization.email.title": "PawSQL 账号",

src/configurationService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export const ConfigurationService = {
1717
getBackendUrl(): string | undefined {
1818
return this.config.get("backendUrl"); // 返回值为 string 或 undefined
1919
},
20+
getVersion(): string | undefined {
21+
return this.config.get("version"); // 返回值为 string 或 undefined
22+
},
2023

2124
getUserDefaultWorkspace(): WorkspaceItem | undefined {
2225
return this.config.get<WorkspaceItem>("defaultWorkspace"); // 返回值为 WorkspaceItem 或 undefined

src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"form.config.email.label": "PawSQL Account",
5252
"form.config.password.label": "Password",
5353
"form.config.backendUrl.label": "PawSQL Server",
54+
"form.config.version.label": "PawSQL Version",
5455
"form.config.joinPawSQL": "Join PawSQL",
5556
"form.config.description": "PawSQL VSCode helps you to optimize your SQL quries directly within VSCode enviroment. PawSQL provides sophisticated SQL optimization features including smart index recommendations and query rewrites. More about PawSQL, please visit ",
5657
"form.config.documentation.link": "docs.pawsql.com",

src/i18n/zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"form.config.email.label": "PawSQL 账号",
5353
"form.config.password.label": "密码",
5454
"form.config.backendUrl.label": "PawSQL 服务器",
55+
"form.config.version.label": "PawSQL 版本",
5556
"form.config.joinPawSQL": "加入PawSQL",
5657
"form.config.description": "PawSQL Client 让开发者能够在VSCode开发环境中直接使用PawSQL优化引擎的强大功能,包括智能索引推荐、查询重写建议、自动化性能验证等。想要了解更多关于PawSQL的优化能力,请参考",
5758
"form.config.documentation.link": "PawSQL官方文档",

src/webview/components/ConfigForm.tsx

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ import LockIcon from "@mui/icons-material/Lock";
1515
import { FormattedMessage, useIntl } from "react-intl";
1616
import PawIconWithText from "./PawIconWithText";
1717

18+
type VersionType = "cloud" | "community" | "enterprise";
19+
1820
interface Config {
1921
email: string;
2022
password: string;
2123
backendUrl: string;
24+
version?: VersionType;
2225
}
2326

2427
interface ConfigFormProps {
@@ -74,12 +77,36 @@ const ConfigForm: React.FC<ConfigFormProps> = ({
7477
}
7578
}, [refresh]);
7679

77-
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
80+
const handleInputChange = (
81+
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
82+
) => {
7883
const { name, value } = event.target;
79-
setFormState((prev) => ({
80-
...prev,
81-
[name]: value,
82-
}));
84+
setFormState((prev) => {
85+
let newState = { ...prev, [name]: value };
86+
87+
// 根据版本类型设置默认值和字段状态
88+
if (name === "version") {
89+
switch (value as VersionType) {
90+
case "cloud":
91+
newState.backendUrl = "https://www.pawsql.com";
92+
newState.email = "";
93+
newState.password = "";
94+
break;
95+
case "community":
96+
newState.backendUrl = "";
97+
newState.email = "community@pawsql.com";
98+
newState.password = "community@pawsql.com";
99+
break;
100+
case "enterprise":
101+
newState.backendUrl = "";
102+
newState.email = "";
103+
newState.password = "";
104+
break;
105+
}
106+
}
107+
108+
return newState;
109+
});
83110
};
84111

85112
return (
@@ -128,6 +155,25 @@ const ConfigForm: React.FC<ConfigFormProps> = ({
128155
</a>
129156
</Typography>
130157
</div>
158+
<TextField
159+
select
160+
fullWidth
161+
name="version"
162+
label={formatMessage({ id: "form.config.version.label" })}
163+
variant="outlined"
164+
margin="normal"
165+
value={formState.version}
166+
onChange={handleInputChange}
167+
SelectProps={{
168+
native: true,
169+
}}
170+
sx={{ mb: 2 }}
171+
>
172+
<option value="cloud">Cloud 版本</option>
173+
<option value="community">社区版</option>
174+
<option value="enterprise">企业版</option>
175+
</TextField>
176+
131177
<TextField
132178
fullWidth
133179
name="backendUrl"
@@ -136,6 +182,7 @@ const ConfigForm: React.FC<ConfigFormProps> = ({
136182
margin="normal"
137183
value={formState.backendUrl}
138184
onChange={handleInputChange}
185+
disabled={formState.version === "cloud"}
139186
InputProps={{
140187
startAdornment: (
141188
<InputAdornment position="start">
@@ -154,6 +201,7 @@ const ConfigForm: React.FC<ConfigFormProps> = ({
154201
margin="normal"
155202
value={formState.email}
156203
onChange={handleInputChange}
204+
disabled={formState.version === "community"}
157205
InputProps={{
158206
startAdornment: (
159207
<InputAdornment position="start">
@@ -172,6 +220,7 @@ const ConfigForm: React.FC<ConfigFormProps> = ({
172220
margin="normal"
173221
value={formState.password}
174222
onChange={handleInputChange}
223+
disabled={formState.version === "community"}
175224
InputProps={{
176225
startAdornment: (
177226
<InputAdornment position="start">

src/webview/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ interface Config {
1919
email: string;
2020
password: string;
2121
backendUrl: string;
22+
version?: "cloud" | "community" | "enterprise";
2223
}
2324

2425
const App: React.FC = () => {
2526
const [config, setConfig] = React.useState<Config>({
2627
email: "",
2728
password: "",
2829
backendUrl: "",
30+
version: undefined,
2931
});
3032

3133
const [locale, setLocale] = React.useState<"en" | "zh-cn">("en"); // 使用字面量类型
@@ -58,6 +60,7 @@ const App: React.FC = () => {
5860
email: message.email || "",
5961
password: message.password || "",
6062
backendUrl: message.backendUrl || "",
63+
version: message.version || "enterprise", // 默认为 "enterprise"
6164
};
6265
console.log("Updating config:", newConfig);
6366
setConfig(newConfig);

src/webviewProvider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class WebviewProvider {
112112
password,
113113
backendUrl:
114114
vscode.workspace.getConfiguration("pawsql").get("backendUrl") || "",
115+
version: vscode.workspace.getConfiguration("pawsql").get("version") || "",
115116
};
116117

117118
panel.webview.postMessage({ command: "configResponse", ...config });
@@ -123,6 +124,7 @@ export class WebviewProvider {
123124
email: string;
124125
password: string;
125126
backendUrl: string;
127+
version: string;
126128
}
127129
) {
128130
try {
@@ -133,6 +135,10 @@ export class WebviewProvider {
133135
await vscode.workspace
134136
.getConfiguration("pawsql")
135137
.update("backendUrl", config.backendUrl, true);
138+
await vscode.workspace
139+
.getConfiguration("pawsql")
140+
.update("version", config.version, true);
141+
136142
await this.treeProvider.updateApikey(config);
137143
await this.passwordManager.storePassword(config.password);
138144

0 commit comments

Comments
 (0)