Skip to content

Commit 2c4f31e

Browse files
committed
refactor: enhance ServerConfigDialog and update client naming conventions
- Refactored ServerConfigDialog to utilize new components for better organization and readability. - Replaced local storage draft management with hooks for improved state handling. - Updated naming from `appName` to `clientName` across multiple files for consistency. - Removed unused code and streamlined the configuration submission process. - Enhanced UI components for better user experience in server configuration management.
1 parent 8572ee5 commit 2c4f31e

File tree

13 files changed

+413
-219
lines changed

13 files changed

+413
-219
lines changed

src-tauri/src/app.rs renamed to src-tauri/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use std::path::{Path, PathBuf};
22
use dirs::home_dir;
33

44
#[allow(dead_code)]
5-
pub struct AppConfig {
5+
pub struct ClientConfig {
66
pub name: String,
77
pub path: PathBuf,
88
}
99

10-
impl AppConfig {
10+
impl ClientConfig {
1111
pub fn new(name: &str, path: Option<&str>) -> Self {
1212
let home = home_dir().unwrap().to_str().unwrap().to_string();
1313
let path = match (name, path) {

src-tauri/src/cmd.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use crate::app::AppConfig;
1+
use crate::client::ClientConfig;
22
use crate::json_manager::JsonManager;
33
use serde_json::Value;
44

55
#[tauri::command]
6-
pub async fn read_json_file(app_name: String, path: Option<String>) -> Result<Value, String> {
7-
let app_config = AppConfig::new(&app_name, path.as_deref());
6+
pub async fn read_json_file(client_name: String, path: Option<String>) -> Result<Value, String> {
7+
let app_config = ClientConfig::new(&client_name, path.as_deref());
88
let file_path = app_config.get_path();
99

10-
if !file_path.exists() && app_name != "claude" {
10+
if !file_path.exists() && client_name != "claude" {
1111
return Err(format!("File not found: {}", file_path.display()));
1212
}
1313

@@ -16,57 +16,57 @@ pub async fn read_json_file(app_name: String, path: Option<String>) -> Result<Va
1616

1717
#[tauri::command]
1818
pub async fn write_json_file(
19-
app_name: String,
19+
client_name: String,
2020
path: Option<String>,
2121
content: Value,
2222
) -> Result<(), String> {
23-
let app_config = AppConfig::new(&app_name, path.as_deref());
23+
let app_config = ClientConfig::new(&client_name, path.as_deref());
2424
let file_path = app_config.get_path();
2525

2626
JsonManager::write_json_file(file_path, &content)
2727
}
2828

2929
#[tauri::command]
30-
pub async fn get_app_path(app_name: String, path: Option<String>) -> Result<String, String> {
31-
let app_config = AppConfig::new(&app_name, path.as_deref());
30+
pub async fn get_app_path(client_name: String, path: Option<String>) -> Result<String, String> {
31+
let app_config = ClientConfig::new(&client_name, path.as_deref());
3232
let file_path = app_config.get_path();
3333

3434
Ok(file_path.to_string_lossy().to_string())
3535
}
3636

3737
#[tauri::command]
3838
pub async fn add_mcp_server(
39-
app_name: String,
39+
client_name: String,
4040
path: Option<String>,
4141
server_name: String,
4242
server_config: Value,
4343
) -> Result<Value, String> {
44-
let app_config = AppConfig::new(&app_name, path.as_deref());
44+
let app_config = ClientConfig::new(&client_name, path.as_deref());
4545
let file_path = app_config.get_path();
4646

4747
JsonManager::add_mcp_server(file_path, &server_name, server_config)
4848
}
4949

5050
#[tauri::command]
5151
pub async fn remove_mcp_server(
52-
app_name: String,
52+
client_name: String,
5353
path: Option<String>,
5454
server_name: String,
5555
) -> Result<Value, String> {
56-
let app_config = AppConfig::new(&app_name, path.as_deref());
56+
let app_config = ClientConfig::new(&client_name, path.as_deref());
5757
let file_path = app_config.get_path();
5858

5959
JsonManager::remove_mcp_server(file_path, &server_name)
6060
}
6161

6262
#[tauri::command]
6363
pub async fn update_mcp_server(
64-
app_name: String,
64+
client_name: String,
6565
path: Option<String>,
6666
server_name: String,
6767
server_config: Value,
6868
) -> Result<Value, String> {
69-
let app_config = AppConfig::new(&app_name, path.as_deref());
69+
let app_config = ClientConfig::new(&client_name, path.as_deref());
7070
let file_path = app_config.get_path();
7171

7272
JsonManager::update_mcp_server(file_path, &server_name, server_config)

src-tauri/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Config {
1515
mcp_servers: Value, // 允许动态 JSON 结构
1616
}
1717

18-
mod app;
18+
mod client;
1919
mod cmd;
2020
mod installer;
2121
mod json_manager;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ArgsTextarea.tsx
2+
import { Label } from "@/components/ui/label";
3+
import { Textarea } from "@/components/ui/textarea";
4+
5+
interface ArgsTextareaProps {
6+
args: string[];
7+
onChange: (value: string) => void;
8+
}
9+
10+
export const ArgsTextarea = ({ args, onChange }: ArgsTextareaProps) => {
11+
return (
12+
<div className="grid gap-2">
13+
<Label className="text-foreground dark:text-gray-200">
14+
args
15+
</Label>
16+
<Textarea
17+
value={args.join(" ")}
18+
onChange={(e) => onChange(e.target.value)}
19+
className="dark:bg-gray-800 dark:border-gray-500 dark:text-white"
20+
/>
21+
</div>
22+
);
23+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// CommandInput.tsx
2+
import { Input } from "@/components/ui/input";
3+
import { Label } from "@/components/ui/label";
4+
5+
interface CommandInputProps {
6+
command: string;
7+
onChange: (value: string) => void;
8+
}
9+
10+
export const CommandInput = ({ command, onChange }: CommandInputProps) => {
11+
return (
12+
<div className="grid gap-2">
13+
<Label className="text-foreground dark:text-gray-200">
14+
Command
15+
</Label>
16+
<Input
17+
value={command || ""}
18+
onChange={(e) => onChange(e.target.value)}
19+
className="dark:bg-gray-800 dark:border-gray-500 dark:text-white"
20+
/>
21+
</div>
22+
);
23+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ConfigTabs.tsx
2+
import { Button } from "@/components/ui/button";
3+
import type { ServerConfig } from "@/types";
4+
5+
interface ConfigTabsProps {
6+
configs: ServerConfig[];
7+
curIndex: number;
8+
onConfigChange: (config: ServerConfig, index: number) => void;
9+
}
10+
11+
export const ConfigTabs = ({ configs, curIndex, onConfigChange }: ConfigTabsProps) => {
12+
return (
13+
<div className="flex gap-2">
14+
{configs.map((c, index) => (
15+
<Button
16+
key={`${c.command}-${index}-${Math.random()}`}
17+
onClick={() => onConfigChange(c, index)}
18+
variant={`${curIndex == index ? "default" : "outline"}`}
19+
aria-label={`Select ${c.command} configuration`}
20+
>
21+
{c.command}
22+
</Button>
23+
))}
24+
</div>
25+
);
26+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// EnvEditor.tsx
2+
import { Input } from "@/components/ui/input";
3+
import { Label } from "@/components/ui/label";
4+
5+
interface EnvEditorProps {
6+
env: Record<string, string>;
7+
envValues: Record<string, string>;
8+
setEnvValues: (values: Record<string, string>) => void;
9+
onEnvChange: (key: string, value: string) => void;
10+
}
11+
12+
export const EnvEditor = ({
13+
env,
14+
envValues,
15+
setEnvValues,
16+
onEnvChange,
17+
}: EnvEditorProps) => {
18+
return (
19+
<div className="grid gap-2">
20+
<h2 className="text-foreground dark:text-gray-200">env</h2>
21+
<div className="space-y-2">
22+
{Object.entries(env).map(([key, value], envIndex) => (
23+
<div
24+
key={envIndex}
25+
className="grid grid-cols-2 items-center gap-2"
26+
>
27+
<Label className="col-span-1 text-foreground dark:text-gray-200">
28+
{key}
29+
</Label>
30+
<Input
31+
className="col-span-3 dark:bg-gray-800 dark:border-gray-500 dark:text-white"
32+
value={envValues[key] || ""}
33+
placeholder={value}
34+
onChange={(e) => {
35+
setEnvValues((prev) => ({
36+
...prev,
37+
[key]: e.target.value,
38+
}));
39+
onEnvChange(key, e.target.value || value);
40+
}}
41+
required
42+
/>
43+
</div>
44+
))}
45+
</div>
46+
</div>
47+
);
48+
};

0 commit comments

Comments
 (0)