diff --git a/apps/tauri/public/drivers/mongodb_icon.png b/apps/tauri/public/drivers/mongodb_icon.png new file mode 100644 index 00000000..7ab42139 Binary files /dev/null and b/apps/tauri/public/drivers/mongodb_icon.png differ diff --git a/apps/tauri/public/drivers/mysql_icon.png b/apps/tauri/public/drivers/mysql_icon.png new file mode 100644 index 00000000..a501af1f Binary files /dev/null and b/apps/tauri/public/drivers/mysql_icon.png differ diff --git a/apps/tauri/public/drivers/postgresql_icon.png b/apps/tauri/public/drivers/postgresql_icon.png new file mode 100644 index 00000000..5d2b29e8 Binary files /dev/null and b/apps/tauri/public/drivers/postgresql_icon.png differ diff --git a/apps/tauri/public/drivers/redis_icon.png b/apps/tauri/public/drivers/redis_icon.png new file mode 100644 index 00000000..84b32586 Binary files /dev/null and b/apps/tauri/public/drivers/redis_icon.png differ diff --git a/apps/tauri/src/ui/NewConnectionDialog.vue b/apps/tauri/src/ui/NewConnectionDialog.vue index 7980ca75..4fdd4450 100644 --- a/apps/tauri/src/ui/NewConnectionDialog.vue +++ b/apps/tauri/src/ui/NewConnectionDialog.vue @@ -2,7 +2,12 @@ import { computed, nextTick, onUnmounted, ref, watch } from "vue"; import { open } from "@tauri-apps/plugin-dialog"; -export type ConnectionDriverChoice = "sqlite" | "postgres" | "mysql"; +export type BuiltInDriverId = + | "postgresql" + | "mysql" + | "sqlite" + | "redis" + | "mongodb"; export type SqliteConnectPayload = { driver: "sqlite"; @@ -10,49 +15,109 @@ export type SqliteConnectPayload = { path: string; }; +type Category = "all" | "sql" | "nosql"; + +type DriverChoice = { + id: BuiltInDriverId; + label: string; + category: "sql" | "nosql"; + /** Public URL under /drivers, or null → folder glyph */ + icon: string | null; +}; + +const DRIVERS: DriverChoice[] = [ + { + id: "postgresql", + label: "PostgreSQL", + category: "sql", + icon: "/drivers/postgresql_icon.png", + }, + { + id: "mysql", + label: "MySQL", + category: "sql", + icon: "/drivers/mysql_icon.png", + }, + { + id: "sqlite", + label: "SQLite", + category: "sql", + icon: null, + }, + { + id: "redis", + label: "Redis", + category: "nosql", + icon: "/drivers/redis_icon.png", + }, + { + id: "mongodb", + label: "MongoDB", + category: "nosql", + icon: "/drivers/mongodb_icon.png", + }, +]; + +const CATEGORY_ITEMS: { id: Category; label: string }[] = [ + { id: "all", label: "All databases" }, + { id: "sql", label: "SQL" }, + { id: "nosql", label: "NoSQL" }, +]; + const props = defineProps<{ open: boolean }>(); const emit = defineEmits<{ close: []; connectSqlite: [payload: SqliteConnectPayload]; }>(); -const driver = ref("sqlite"); +type Step = "pick" | "sqlite" | "stub"; + +const step = ref("pick"); +const category = ref("all"); +const search = ref(""); +const selectedId = ref(null); +const searchEl = ref(null); +const nameEl = ref(null); + const name = ref(""); const path = ref(""); -const host = ref("localhost"); -const port = ref(5432); -const database = ref(""); -const user = ref(""); -const password = ref(""); -const ssl = ref(false); +const readOnly = ref(false); const error = ref(null); -const busy = ref(false); -const nameEl = ref(null); +const stubDriver = ref(null); -const stubDrivers = computed( - () => driver.value === "postgres" || driver.value === "mysql", -); +const categoryDrivers = computed(() => { + if (category.value === "all") return DRIVERS; + return DRIVERS.filter((d) => d.category === category.value); +}); -const canSave = computed(() => { - if (busy.value) return false; - if (driver.value === "sqlite") { - return path.value.trim().length > 0; - } - return false; +const filteredDrivers = computed(() => { + const q = search.value.trim().toLowerCase(); + if (!q) return categoryDrivers.value; + return categoryDrivers.value.filter((d) => + d.label.toLowerCase().includes(q), + ); }); +const selected = computed( + () => DRIVERS.find((d) => d.id === selectedId.value) ?? null, +); + +const canNext = computed(() => selected.value != null); + +const canSaveSqlite = computed( + () => name.value.trim().length > 0 && path.value.trim().length > 0, +); + function reset() { - driver.value = "sqlite"; + step.value = "pick"; + category.value = "all"; + search.value = ""; + selectedId.value = null; name.value = ""; path.value = ""; - host.value = "localhost"; - port.value = 5432; - database.value = ""; - user.value = ""; - password.value = ""; - ssl.value = false; + readOnly.value = false; error.value = null; - busy.value = false; + stubDriver.value = null; } watch( @@ -61,37 +126,66 @@ watch( if (!v) return; reset(); await nextTick(); - nameEl.value?.focus(); + searchEl.value?.focus(); }, ); -watch(driver, (d) => { - error.value = null; - if (d === "postgres") { - port.value = 5432; - user.value = "postgres"; - } else if (d === "mysql") { - port.value = 3306; - user.value = "root"; +watch([category, search], () => { + if ( + selectedId.value && + !filteredDrivers.value.some((d) => d.id === selectedId.value) + ) { + selectedId.value = null; } }); +function selectDriver(id: BuiltInDriverId) { + selectedId.value = id; +} + +function onCategoryChange(v: string) { + category.value = (v as Category) || "all"; +} + +function onTypeChange(v: string) { + selectedId.value = (v as BuiltInDriverId) || null; +} + +function goNext() { + const choice = selected.value; + if (!choice) return; + error.value = null; + if (choice.id === "sqlite") { + step.value = "sqlite"; + void nextTick(() => nameEl.value?.focus()); + return; + } + stubDriver.value = choice; + step.value = "stub"; +} + +function goBack() { + error.value = null; + step.value = "pick"; + stubDriver.value = null; +} + async function browseSqlite() { try { - const selected = await open({ + const selectedPath = await open({ multiple: false, directory: false, title: "Select SQLite database", filters: [ - { name: "SQLite", extensions: ["db", "sqlite", "sqlite3"] }, + { name: "SQLite", extensions: ["db", "sqlite", "sqlite3", "db3"] }, { name: "All files", extensions: ["*"] }, ], }); - if (!selected || Array.isArray(selected)) return; - path.value = selected; + if (!selectedPath || Array.isArray(selectedPath)) return; + path.value = selectedPath; if (!name.value.trim()) { - const base = selected.split(/[/\\]/).pop() ?? selected; - name.value = base.replace(/\.(db|sqlite3?)$/i, "") || base; + const base = selectedPath.split(/[/\\]/).pop() ?? selectedPath; + name.value = base.replace(/\.(db|sqlite3?|db3)$/i, "") || base; } } catch (err) { if (String(err).includes("cancel")) return; @@ -99,38 +193,32 @@ async function browseSqlite() { } } -function fileName(p: string): string { - const parts = p.split(/[/\\]/); - return parts[parts.length - 1] || p; -} - -function submit() { +function submitSqlite() { error.value = null; - if (driver.value === "sqlite") { - const p = path.value.trim(); - if (!p) { - error.value = "Choose a database file"; - return; - } - const n = name.value.trim() || fileName(p); - emit("connectSqlite", { driver: "sqlite", name: n, path: p }); - emit("close"); + const p = path.value.trim(); + const n = name.value.trim(); + if (!n) { + error.value = "Connection name is required."; + return; + } + if (!p) { + error.value = "Database file path is required."; return; } - error.value = - driver.value === "postgres" - ? "PostgreSQL connect lands with the driver epic — fields are ready for wiring." - : "MySQL connect lands with the driver epic — fields are ready for wiring."; + emit("connectSqlite", { driver: "sqlite", name: n, path: p }); + emit("close"); } function onKey(e: KeyboardEvent) { if (!props.open) return; if (e.key === "Escape") { e.preventDefault(); - emit("close"); + if (step.value !== "pick") goBack(); + else emit("close"); } else if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); - submit(); + if (step.value === "pick" && canNext.value) goNext(); + else if (step.value === "sqlite" && canSaveSqlite.value) submitSqlite(); } } @@ -152,151 +240,220 @@ onUnmounted(() => window.removeEventListener("keydown", onKey, true)); data-testid="new-connection-dialog" @click.self="emit('close')" > + + +
+ - +
+ + + + + + + @@ -315,8 +472,6 @@ onUnmounted(() => window.removeEventListener("keydown", onKey, true)); } .dialog { - width: min(520px, 100%); - max-height: min(640px, 92vh); display: flex; flex-direction: column; border-radius: 14px; @@ -327,92 +482,252 @@ onUnmounted(() => window.removeEventListener("keydown", onKey, true)); overflow: hidden; } +.dialog.pick { + width: min(860px, 100%); + height: min(680px, 85vh); + min-height: min(320px, 85vh); +} + +.dialog.form { + width: min(520px, 100%); + max-height: min(640px, 92vh); +} + .hdr { + flex: 0 0 auto; + padding: 20px 24px 8px; display: flex; - align-items: center; - justify-content: space-between; - padding: 14px 16px 10px 18px; - border-bottom: 1px solid color-mix(in srgb, var(--q-border) 40%, transparent); + flex-direction: column; + gap: 0; +} + +.form-hdr { + padding-bottom: 4px; } h2 { margin: 0; - font-size: 15px; + font-size: 17px; font-weight: 650; + letter-spacing: -0.01em; } -.x { - appearance: none; +.sub { + margin: 6px 0 0; + font-size: 12.5px; + line-height: 1.45; + color: var(--q-muted-foreground); +} + +.search { + margin-top: 12px; + height: 36px; + display: flex; + align-items: center; + gap: 8px; + padding: 0 12px; + border-radius: 8px; + border: 1px solid color-mix(in srgb, var(--q-border) 55%, transparent); + background: color-mix(in srgb, var(--q-muted-foreground) 10%, transparent); +} + +.search:focus-within { + border-color: color-mix(in srgb, var(--q-primary) 55%, transparent); +} + +.search-ico { + color: var(--q-muted-foreground); + font-size: 14px; + line-height: 1; +} + +.search input { + flex: 1; + min-width: 0; border: 0; background: transparent; - width: 28px; - height: 28px; - border-radius: 6px; + color: var(--q-foreground); + font: inherit; + font-size: 13px; + outline: none; +} + +.filters { + margin-top: 12px; + display: grid; + grid-template-columns: 1fr 1fr; + gap: 12px; +} + +@media (max-width: 520px) { + .filters { + grid-template-columns: 1fr; + } +} + +.filter { + display: flex; + flex-direction: column; + gap: 4px; + font-size: 12px; color: var(--q-muted-foreground); - cursor: pointer; } -.x:hover { - background: var(--q-accent); +.filter select { + height: 36px; + border-radius: 8px; + border: 1px solid var(--q-border); + background: var(--q-sidebar-bg); color: var(--q-foreground); + padding: 0 10px; + font: inherit; + font-size: 13px; +} + +.grid-wrap { + flex: 1; + min-height: 0; + overflow: auto; + padding: 16px; } -.drivers { +.empty { + margin: 40px 0; + text-align: center; + font-size: 13px; + color: var(--q-muted-foreground); +} + +.grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); + gap: 12px; +} + +@media (min-width: 700px) { + .grid { + grid-template-columns: repeat(4, 1fr); + } +} + +@media (min-width: 520px) and (max-width: 699px) { + .grid { + grid-template-columns: repeat(3, 1fr); + } +} + +.card { + appearance: none; display: flex; + flex-direction: column; + align-items: stretch; gap: 6px; - padding: 12px 16px 0; + min-height: 138px; + padding: 10px 8px; + border-radius: 10px; + border: 1px solid color-mix(in srgb, var(--q-border) 35%, transparent); + background: color-mix(in srgb, var(--q-muted-foreground) 8%, transparent); + color: var(--q-foreground); + cursor: pointer; + font: inherit; + transition: + background 0.12s ease, + border-color 0.12s ease; } -.drv { - appearance: none; - border: 1px solid var(--q-border); - background: transparent; +.card:hover { + background: color-mix(in srgb, var(--q-muted-foreground) 22%, transparent); +} + +.card.on { + background: color-mix(in srgb, var(--q-muted-foreground) 28%, transparent); + border-color: color-mix(in srgb, var(--q-primary) 60%, transparent); + border-width: 1.5px; + padding: 9.5px 7.5px; +} + +.card-icon { + flex: 1; + display: grid; + place-items: center; + min-height: 64px; +} + +.card-icon img { + width: 52px; + height: 52px; + object-fit: contain; + pointer-events: none; +} + +.glyph { + font-size: 28px; + font-weight: 700; + line-height: 1; color: var(--q-muted-foreground); - border-radius: 999px; - padding: 5px 12px; - font: inherit; - font-size: 12px; - cursor: pointer; } -.drv.on { - background: color-mix(in srgb, var(--q-primary) 16%, transparent); - border-color: transparent; +.glyph.folder { color: var(--q-primary); + display: grid; + place-items: center; +} + +.card-label { + height: 38px; + display: flex; + align-items: center; + justify-content: center; + text-align: center; + font-size: 13px; font-weight: 600; + line-height: 1.2; } .body { flex: 1; min-height: 0; overflow: auto; - padding: 14px 18px 8px; + padding: 12px 24px 8px; display: flex; flex-direction: column; - gap: 12px; + gap: 16px; +} + +.stub-body { + align-items: center; + text-align: center; + padding-top: 24px; + padding-bottom: 24px; +} + +.stub-icon img { + object-fit: contain; } .field { display: flex; flex-direction: column; - gap: 5px; + gap: 8px; font-size: 12px; + font-weight: 600; } .field input { - height: 32px; - border-radius: 6px; + height: 36px; + border-radius: 8px; border: 1px solid var(--q-border); background: var(--q-sidebar-bg); color: var(--q-foreground); - padding: 0 10px; + padding: 0 12px; font: inherit; - font-size: 12px; + font-size: 13px; + font-weight: 400; } .path-row { display: flex; - gap: 8px; + gap: 10px; } .path-row input { @@ -420,31 +735,23 @@ h2 { min-width: 0; } -.grid2 { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 10px; -} - .switch { display: flex; align-items: center; gap: 8px; - font-size: 12px; + font-size: 13px; + font-weight: 400; cursor: pointer; } .hint { margin: 0; - font-size: 11px; - line-height: 1.4; + max-width: 36ch; + font-size: 13px; + line-height: 1.45; color: var(--q-muted-foreground); } -.hint.warn { - color: color-mix(in srgb, var(--q-warning, #d97706) 85%, var(--q-foreground)); -} - .err { margin: 0; font-size: 12px; @@ -452,23 +759,24 @@ h2 { } footer { + flex: 0 0 auto; display: flex; justify-content: flex-end; - gap: 8px; - padding: 12px 16px 14px; - border-top: 1px solid color-mix(in srgb, var(--q-border) 40%, transparent); + gap: 12px; + padding: 14px 24px; + border-top: 1px solid color-mix(in srgb, var(--q-border) 30%, transparent); } .btn { appearance: none; - height: 32px; - padding: 0 14px; - border-radius: 6px; + height: 36px; + padding: 0 16px; + border-radius: 8px; border: 1px solid var(--q-border); background: var(--q-surface); color: var(--q-foreground); font: inherit; - font-size: 12px; + font-size: 13px; cursor: pointer; white-space: nowrap; } @@ -482,6 +790,15 @@ footer { cursor: default; } +.btn.ghost { + border-color: transparent; + background: transparent; +} + +.btn.ghost:hover:not(:disabled) { + background: var(--q-accent); +} + .btn.primary { background: var(--q-primary); border-color: transparent;