Skip to content

Commit

Permalink
feat: update url based on table
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Jun 16, 2024
1 parent 37ba292 commit 9488f51
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ui/src/routes/tables.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
TableProperties,
Table as TableIcon,
} from "lucide-react";
import { z } from "zod";
import DataGrid from "react-data-grid";
import { CodeBlock } from "react-code-blocks";
import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
import { createFileRoute } from "@tanstack/react-router";
import { Link, createFileRoute } from "@tanstack/react-router";

import { fetchTable, fetchTables, fetchTableData } from "@/api";

Expand All @@ -21,17 +22,25 @@ export const Route = createFileRoute("/tables")({
component: Tables,
loader: () => fetchTables(),
pendingComponent: TablesSkeleton,
validateSearch: z.object({ table: z.string().optional() }),
});

function Tables() {
const data = Route.useLoaderData();
const { table } = Route.useSearch();

const tab = table
? data.tables.findIndex(({ name }) => name === table).toString()
: "0";

return (
<Tabs defaultValue="0">
<Tabs defaultValue={tab}>
<TabsList>
{data.tables.map((n, i) => (
<TabsTrigger key={i} value={i.toString()}>
{n.name} ({n.count.toLocaleString()})
<Link search={{ table: n.name }}>
{n.name} ({n.count.toLocaleString()})
</Link>
</TabsTrigger>
))}
</TabsList>
Expand Down

0 comments on commit 9488f51

Please sign in to comment.