Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
474 changes: 13 additions & 461 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src-tauri/crates/mas-admin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ impl AdminService {
) -> Result<(), CoreError> {
tracing::info!(process_id = process_id, "Killing MySQL process");
let pool = self.connection_manager.get_pool(connection_id)?;
let result = sqlx::query("KILL ?")
.bind(process_id)
.execute(&pool)
.await;
let result = sqlx::query("KILL ?").bind(process_id).execute(&pool).await;
match result {
Ok(_) => {
tracing::info!(process_id = process_id, "Process killed successfully");
Expand Down
14 changes: 11 additions & 3 deletions src-tauri/crates/mas-core/src/connection/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl ConnectionManager {
"Creating connection pool"
);

let charset = profile.charset.clone().unwrap_or_else(|| "utf8mb4".to_string());
let charset = profile
.charset
.clone()
.unwrap_or_else(|| "utf8mb4".to_string());
let mut options = MySqlConnectOptions::new()
.host(&profile.host)
.port(profile.port)
Expand Down Expand Up @@ -64,7 +67,9 @@ impl ConnectionManager {
.after_connect(move |conn, _meta| {
let charset = charset_for_after_connect.clone();
Box::pin(async move {
sqlx::query(&format!("SET NAMES {}", charset)).execute(&mut *conn).await?;
sqlx::query(&format!("SET NAMES {}", charset))
.execute(&mut *conn)
.await?;
Ok(())
})
})
Expand Down Expand Up @@ -150,7 +155,10 @@ impl ConnectionManager {
) -> Result<TestConnectionResult, CoreError> {
let start = Instant::now();

let charset = profile.charset.clone().unwrap_or_else(|| "utf8mb4".to_string());
let charset = profile
.charset
.clone()
.unwrap_or_else(|| "utf8mb4".to_string());
let mut options = MySqlConnectOptions::new()
.host(&profile.host)
.port(profile.port)
Expand Down
21 changes: 15 additions & 6 deletions src-tauri/crates/mas-core/src/connection/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@ impl ConnectionStore {
db.execute("ALTER TABLE connection_profiles ADD COLUMN env TEXT", [])
.ok();
// Migration: add advanced settings columns if missing
db.execute("ALTER TABLE connection_profiles ADD COLUMN connect_timeout_secs INTEGER", [])
.ok();
db.execute("ALTER TABLE connection_profiles ADD COLUMN query_timeout_secs INTEGER", [])
.ok();
db.execute("ALTER TABLE connection_profiles ADD COLUMN charset TEXT", [])
.ok();
db.execute(
"ALTER TABLE connection_profiles ADD COLUMN connect_timeout_secs INTEGER",
[],
)
.ok();
db.execute(
"ALTER TABLE connection_profiles ADD COLUMN query_timeout_secs INTEGER",
[],
)
.ok();
db.execute(
"ALTER TABLE connection_profiles ADD COLUMN charset TEXT",
[],
)
.ok();
tracing::debug!("Connection profiles table initialized");
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/crates/mas-core/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ fn test_profile() -> ConnectionProfile {
pool_min: 1,
pool_max: 5,
read_only: false,
connect_timeout_secs: None,
query_timeout_secs: None,
charset: None,
environment: None,
created_at: Utc::now(),
updated_at: Utc::now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ fn test_profile() -> ConnectionProfile {
pool_min: 1,
pool_max: 5,
read_only: false,
connect_timeout_secs: None,
query_timeout_secs: None,
charset: None,
environment: None,
created_at: Utc::now(),
updated_at: Utc::now(),
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,9 @@ pub async fn write_file_contents(path: String, contents: String) -> Result<(), S
.ok_or_else(|| "Invalid path: missing file name".to_string())?,
)
} else {
path_buf.canonicalize().map_err(|e| format!("Invalid path: {e}"))?
path_buf
.canonicalize()
.map_err(|e| format!("Invalid path: {e}"))?
};
tokio::fs::write(&resolved, &contents).await.map_err(|e| {
tracing::error!(error = %e, path = %path, "Failed to write file");
Expand Down
4 changes: 2 additions & 2 deletions src/components/editor/__tests__/QueryToolbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ describe("QueryToolbar", () => {
expect(screen.getByText("Save").closest("button")).toBeDisabled();
});

it("shows Running state when executing", () => {
it("shows Cancel button when executing", () => {
mockIsExecuting = true;
render(<QueryToolbar />);
expect(screen.getByText("Running...")).toBeInTheDocument();
expect(screen.getByText("Cancel")).toBeInTheDocument();
expect(screen.queryByText("Run")).not.toBeInTheDocument();
});

Expand Down
15 changes: 13 additions & 2 deletions src/hooks/useGridEditing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function useGridEditing() {
setDeletes(new Set());
undoStack.current = [];
redoStack.current = [];
bumpVersion();
}, []);

const applyAction = useCallback((action: EditAction): EditAction => {
Expand All @@ -143,7 +144,11 @@ export function useGridEditing() {
const next = new Map(prev);
const rowChanges = [...(next.get(action.rowIndex) ?? [])];
const existing = rowChanges.findIndex((c) => c.column === action.column);
if (action.newValue === action.oldValue || (action.oldValue === undefined && action.newValue === action.oldValue)) {
if (existing >= 0 && action.newValue === rowChanges[existing].originalValue) {
rowChanges.splice(existing, 1);
if (rowChanges.length === 0) next.delete(action.rowIndex);
else next.set(action.rowIndex, rowChanges);
} else if (action.newValue === action.oldValue) {
if (existing >= 0) {
rowChanges.splice(existing, 1);
if (rowChanges.length === 0) next.delete(action.rowIndex);
Expand Down Expand Up @@ -172,6 +177,10 @@ export function useGridEditing() {
return { ...action, index: -1 };
}
case "deleteRow": {
if (action.rowIndex === -1) {
setInserts((prev) => prev.slice(0, -1));
return { type: "insertRow", index: 0 }; // forward action for redo
}
setDeletes((prev: Set<number>) => {
const next = new Set(prev);
if (next.has(action.rowIndex)) next.delete(action.rowIndex);
Expand All @@ -194,7 +203,9 @@ export function useGridEditing() {
const redo = useCallback(() => {
const action = redoStack.current.pop();
if (!action) return;
const reverse = applyAction(reverseAction(action));
const reverse = action.type === "insertRow"
? applyAction(action)
: applyAction(reverseAction(action));
undoStack.current.push(reverse);
bumpVersion();
}, [applyAction]);
Expand Down
31 changes: 17 additions & 14 deletions src/stores/themeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,27 @@ export const useThemeStore = create<ThemeState>((set) => ({
},
}));

// Listen for system preference changes when mode is 'system'
let mediaQuery: MediaQueryList | undefined;

const handleSystemThemeChange = () => {
const state = useThemeStore.getState();
if (state.theme === "system") {
const effective = resolveEffective("system");
applyTheme(effective);
useThemeStore.setState({ effectiveTheme: effective });
}
};
// Use a const object wrapper to persist cleanup across HMR module reloads
const _mqlState = { cleanup: null as (() => void) | null };

if (typeof window !== "undefined") {
mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
mediaQuery.addEventListener("change", handleSystemThemeChange);
_mqlState.cleanup?.();

const mql = window.matchMedia("(prefers-color-scheme: dark)");
const handler = () => {
const state = useThemeStore.getState();
if (state.theme === "system") {
const effective = resolveEffective("system");
applyTheme(effective);
useThemeStore.setState({ effectiveTheme: effective });
}
};

mql.addEventListener("change", handler);
_mqlState.cleanup = () => mql.removeEventListener("change", handler);
}

/** Removes the system theme change listener. Useful for cleanup (e.g. in tests). */
export function cleanupThemeListener() {
mediaQuery?.removeEventListener("change", handleSystemThemeChange);
_mqlState.cleanup?.();
}
Loading