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
2 changes: 1 addition & 1 deletion apps/tauri/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pnpm install
pnpm tauri dev
```

You should get the shell chrome and an `app_info` status line. **Open SQLite…** uses the native file dialog and `db_connect_sqlite` IPC (live connection list in the sidebar).
UI-core first: empty hero → **Demo** (offline catalog) or Open SQLite → connection **Overview** → click a table for **Data** grid. SQL is parked on the connection home SQL tab. Live DB commands remain for later slices.

### Scripts

Expand Down
57 changes: 18 additions & 39 deletions apps/tauri/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@ import { open } from "@tauri-apps/plugin-dialog";
import { storeToRefs } from "pinia";
import { useShellStore } from "./stores/shell";
import { useShellStatusStore } from "./stores/shellStatus";
import { useWorkspaceStore } from "./stores/workspace";
import { useConnectionsStore } from "./stores/connections";
import { useShellNavStore } from "./stores/shellNav";
import { initTheme } from "./theme/queryaTheme";
import { provideQueryaMotion } from "./motion";
import TitleBar from "./ui/TitleBar.vue";
import ConnectionsPanel from "./ui/ConnectionsPanel.vue";
import TabStrip from "./ui/TabStrip.vue";
import StatusBar from "./ui/StatusBar.vue";
import WorkspaceEmptyHero from "./ui/WorkspaceEmptyHero.vue";
import QueryaDivider from "./ui/QueryaDivider.vue";
import SqlWorkspace from "./ui/SqlWorkspace.vue";
import ConnectionHome from "./ui/ConnectionHome.vue";
import TableObjectView from "./ui/TableObjectView.vue";

const shell = useShellStore();
const status = useShellStatusStore();
const workspace = useWorkspaceStore();
const connections = useConnectionsStore();
const { activeTab } = storeToRefs(workspace);
const nav = useShellNavStore();
const { surface } = storeToRefs(nav);
provideQueryaMotion();

const showEmpty = computed(
() => !connections.active && activeTab.value?.kind === "welcome",
);

const showSql = computed(() => activeTab.value?.kind === "sql");
const showEmpty = computed(() => surface.value === "empty");
const showHome = computed(() => surface.value === "connectionHome");
const showTable = computed(() => surface.value === "tableObject");

async function onOpenSqlite() {
try {
Expand All @@ -42,20 +40,23 @@ async function onOpenSqlite() {
],
});
if (!selected || Array.isArray(selected)) return;
const conn = await connections.connectSqlite(selected);
workspace.addTab({ title: conn.name, kind: "sql" });
await connections.connectSqlite(selected);
} catch (err) {
if (String(err).includes("cancel")) return;
}
}

function onNewConnection() {
status.setQueryMetrics({
message: "Connection form will land with keyring/profiles",
message: "Connection form UI next — use Demo or Open SQLite for now",
busy: false,
});
}

function onLaunchDemo() {
connections.launchDemo();
}

function onOpenTour() {
status.setQueryMetrics({ message: "Tour stub", busy: false });
}
Expand All @@ -80,7 +81,7 @@ onMounted(async () => {
os?: string;
}>("app_info");
status.setQueryMetrics({
message: `${info.name} ${info.version} · ${info.stack}${info.os ? ` · ${info.os}` : ""}`,
message: `${info.name} ${info.version} · UI core · ${info.stack}${info.os ? ` · ${info.os}` : ""}`,
});
} catch {
status.setQueryMetrics({ message: "IPC unavailable" });
Expand All @@ -104,21 +105,16 @@ onUnmounted(() => {
@new-connection="onNewConnection"
/>
<main class="workspace">
<TabStrip />
<div class="workspace-body">
<WorkspaceEmptyHero
v-if="showEmpty"
@new-connection="onNewConnection"
@open-sqlite="onOpenSqlite"
@launch-demo="onLaunchDemo"
@open-tour="onOpenTour"
/>
<SqlWorkspace v-else-if="showSql" />
<div v-else class="tab-placeholder" data-testid="tab-placeholder">
<h2>{{ activeTab?.title }}</h2>
<p v-if="connections.active">
Connected: {{ connections.active.path }}
</p>
</div>
<ConnectionHome v-else-if="showHome" />
<TableObjectView v-else-if="showTable" />
</div>
</main>
</div>
Expand Down Expand Up @@ -160,21 +156,4 @@ onUnmounted(() => {
display: flex;
flex-direction: column;
}

.tab-placeholder {
height: 100%;
display: grid;
place-content: center;
justify-items: center;
gap: var(--q-space-2);
padding: var(--q-space-8);
text-align: center;
color: var(--q-muted-foreground);
}

.tab-placeholder h2 {
margin: 0;
color: var(--q-foreground);
font-size: var(--q-text-lg);
}
</style>
101 changes: 101 additions & 0 deletions apps/tauri/src/mock/demoCatalog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/** Offline demo catalog for UI-core review (no live DB). */

export type DemoColumn = {
name: string;
data_type: string;
is_primary_key: boolean;
is_nullable: boolean;
};

export type DemoObject = {
name: string;
kind: "table" | "view";
columns: DemoColumn[];
rows: unknown[][];
};

export type DemoConnection = {
id: string;
name: string;
driver: "sqlite";
path: string;
objects: DemoObject[];
};

const users: DemoObject = {
name: "users",
kind: "table",
columns: [
{ name: "id", data_type: "INTEGER", is_primary_key: true, is_nullable: false },
{ name: "username", data_type: "TEXT", is_primary_key: false, is_nullable: false },
{ name: "email", data_type: "TEXT", is_primary_key: false, is_nullable: false },
{ name: "full_name", data_type: "TEXT", is_primary_key: false, is_nullable: true },
{ name: "city", data_type: "TEXT", is_primary_key: false, is_nullable: true },
{ name: "is_active", data_type: "INTEGER", is_primary_key: false, is_nullable: false },
{ name: "created_at", data_type: "DATETIME", is_primary_key: false, is_nullable: false },
],
rows: [
[1, "ada", "ada@ex.com", "Ada Lovelace", "London", 1, "2024-01-02 10:00:00"],
[2, "bob", "bob@ex.com", "Bob Builder", "Berlin", 1, "2024-02-11 12:30:00"],
[3, "cara", "cara@ex.com", null, "Oslo", 0, "2024-03-05 09:15:00"],
[4, "dan", "dan@ex.com", "Dan Park", "Tokyo", 1, "2024-04-18 18:45:00"],
[5, "eve", "eve@ex.com", "Eve North", "Seoul", 1, "2024-05-01 08:00:00"],
],
};

const products: DemoObject = {
name: "products",
kind: "table",
columns: [
{ name: "id", data_type: "INTEGER", is_primary_key: true, is_nullable: false },
{ name: "sku", data_type: "TEXT", is_primary_key: false, is_nullable: false },
{ name: "title", data_type: "TEXT", is_primary_key: false, is_nullable: false },
{ name: "price", data_type: "REAL", is_primary_key: false, is_nullable: false },
],
rows: [
[10, "SKU-1", "Notebook", 12.5],
[11, "SKU-2", "Pen set", 4.2],
[12, "SKU-3", "Desk lamp", 39.0],
],
};

const orders: DemoObject = {
name: "orders",
kind: "table",
columns: [
{ name: "id", data_type: "INTEGER", is_primary_key: true, is_nullable: false },
{ name: "user_id", data_type: "INTEGER", is_primary_key: false, is_nullable: false },
{ name: "total", data_type: "REAL", is_primary_key: false, is_nullable: false },
{ name: "status", data_type: "TEXT", is_primary_key: false, is_nullable: false },
],
rows: [
[100, 1, 44.5, "paid"],
[101, 2, 12.5, "pending"],
[102, 1, 39.0, "paid"],
],
};

const customerSpending: DemoObject = {
name: "customer_spending",
kind: "view",
columns: [
{ name: "username", data_type: "TEXT", is_primary_key: false, is_nullable: false },
{ name: "spent", data_type: "REAL", is_primary_key: false, is_nullable: false },
],
rows: [
["ada", 83.5],
["bob", 12.5],
],
};

export const DEMO_CONNECTION: DemoConnection = {
id: "demo-sqlite",
name: "Demo SQLite",
driver: "sqlite",
path: "mock://demo",
objects: [users, products, orders, customerSpending],
};

export function findDemoObject(name: string): DemoObject | undefined {
return DEMO_CONNECTION.objects.find((o) => o.name === name);
}
89 changes: 71 additions & 18 deletions apps/tauri/src/stores/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,68 @@ import {
dbDisconnect,
formatConnectionError,
} from "../api/connection";
import { DEMO_CONNECTION } from "../mock/demoCatalog";
import { useShellNavStore } from "./shellNav";
import { useShellStatusStore } from "./shellStatus";

export type LiveConnection = {
id: string;
driver: "sqlite";
name: string;
path: string;
/** Offline UI demo — no Rust session. */
mock?: boolean;
};

function fileName(path: string): string {
const parts = path.split(/[/\\]/);
return parts[parts.length - 1] || path;
}

/** Live DB sessions opened in this app process. */
/** Saved / live sessions shown in SERVERS (Flutter connections list). */
export const useConnectionsStore = defineStore("connections", () => {
const items = ref<LiveConnection[]>([]);
const activeId = ref<string | null>(null);

const active = computed(
() => items.value.find((c) => c.id === activeId.value) ?? null,
);
const byId = computed(() => {
const map = new Map<string, LiveConnection>();
for (const c of items.value) map.set(c.id, c);
return map;
});

function upsert(conn: LiveConnection) {
const rest = items.value.filter((c) => c.id !== conn.id);
items.value = [...rest, conn];
}

/** Flutter-style Demo — full UI without opening a real file. */
function launchDemo() {
const nav = useShellNavStore();
const status = useShellStatusStore();
const conn: LiveConnection = {
id: DEMO_CONNECTION.id,
driver: "sqlite",
name: DEMO_CONNECTION.name,
path: DEMO_CONNECTION.path,
mock: true,
};
upsert(conn);
nav.setExpanded(conn.id, true);
nav.selectConnection(conn.id);
status.setConnection(conn.name, "Demo (offline)");
status.setQueryMetrics({
message: "Demo catalog · UI core (no live DB)",
busy: false,
});
return conn;
}

async function connectSqlite(path: string) {
const status = useShellStatusStore();
status.setQueryMetrics({ busy: true, message: `Opening ${fileName(path)}…` });
const nav = useShellNavStore();
status.setQueryMetrics({
busy: true,
message: `Opening ${fileName(path)}…`,
});
try {
const id = await dbConnectSqlite(path);
const conn: LiveConnection = {
Expand All @@ -39,8 +75,9 @@ export const useConnectionsStore = defineStore("connections", () => {
name: fileName(path),
path,
};
items.value = [...items.value, conn];
activeId.value = id;
upsert(conn);
nav.setExpanded(id, true);
nav.selectConnection(id);
status.setConnection(conn.name, path);
status.setQueryMetrics({
busy: false,
Expand All @@ -56,30 +93,46 @@ export const useConnectionsStore = defineStore("connections", () => {

async function disconnect(id: string) {
const status = useShellStatusStore();
const nav = useShellNavStore();
const conn = byId.value.get(id);
try {
await dbDisconnect(id);
if (conn && !conn.mock) await dbDisconnect(id);
} finally {
items.value = items.value.filter((c) => c.id !== id);
if (activeId.value === id) {
activeId.value = items.value[0]?.id ?? null;
const next = active.value;
if (nav.selectedConnectionId === id) {
const next = items.value[0] ?? null;
if (next) nav.selectConnection(next.id);
else nav.reset();
status.setConnection(next?.name ?? null, next?.path ?? null);
status.setQueryMetrics({
message: next ? `Connected · ${next.name}` : "Disconnected",
message: next ? `Connected · ${next.name}` : "No connection",
busy: false,
});
}
}
}

function select(id: string) {
const conn = items.value.find((c) => c.id === id);
const conn = byId.value.get(id);
if (!conn) return;
activeId.value = id;
const nav = useShellNavStore();
const status = useShellStatusStore();
status.setConnection(conn.name, conn.path);
status.setQueryMetrics({ message: `Connected · ${conn.name}`, busy: false });
nav.selectConnection(id);
status.setConnection(conn.name, conn.mock ? "Demo (offline)" : conn.path);
status.setQueryMetrics({
message: conn.mock
? "Demo catalog · UI core (no live DB)"
: `Connected · ${conn.name}`,
busy: false,
});
}

return { items, activeId, active, connectSqlite, disconnect, select };
return {
items,
byId,
launchDemo,
connectSqlite,
disconnect,
select,
};
});
Loading
Loading