import { Link, Outlet, useNavigate } from "react-router"; import { PlusIcon } from "@heroicons/react/24/outline"; import { useInsightsHistory, useInsightsQueries } from "../lib/queries"; import { timeAgo } from "../lib/time"; import type { PaginatedSavedQueryList, PaginatedHistoryEntryList } from "@qltysh/fabro-api-client"; export function meta({}: any) { return [{ title: "Insights — Fabro" }]; } export const handle = { wide: true, }; // ── Types ── export interface SavedQuery { id: string; name: string; sql: string; } export interface HistoryEntry { id: string; sql: string; timestamp: string; elapsed: number; rowsReturned: number; } function mapSavedQueries(result: PaginatedSavedQueryList | undefined): SavedQuery[] { return (result?.data ?? []).map((q) => ({ id: q.id, name: q.name, sql: q.sql, })); } function mapHistoryEntries(result: PaginatedHistoryEntryList | undefined): HistoryEntry[] { return (result?.data ?? []).map((h) => ({ id: h.id, sql: h.sql, timestamp: h.timestamp, elapsed: h.elapsed, rowsReturned: h.row_count, })); } export default function InsightsLayout() { const savedQueriesQuery = useInsightsQueries(); const historyQuery = useInsightsHistory(); const savedQueries = mapSavedQueries(savedQueriesQuery.data as PaginatedSavedQueryList | undefined); const historyEntries = mapHistoryEntries(historyQuery.data as PaginatedHistoryEntryList | undefined); const navigate = useNavigate(); return (
{/* ── Sidebar ── */}
New Query

Saved Queries

{savedQueries.map((q) => ( ))}

History

{historyEntries.map((entry) => ( ))}
{/* ── Main content ── */}
); }