Skip to content

Commit 1d07c46

Browse files
committed
fix tables route fallback when query table is missing
1 parent 6dc5ba0 commit 1d07c46

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

ui/src/routes/tables.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,46 @@ function Tables() {
4747
</Card>
4848
);
4949

50-
const tab = table
51-
? data.tables.findIndex(({ name }) => name === table).toString()
52-
: "0";
50+
const requestedTableMissing =
51+
!!table && !data.tables.some(({ name }) => name === table);
52+
53+
const tab = (() => {
54+
if (!table) return "0";
55+
const index = data.tables.findIndex(({ name }) => name === table);
56+
return (index >= 0 ? index : 0).toString();
57+
})();
5358

5459
return (
55-
<Tabs defaultValue={tab}>
56-
<TabsList>
57-
{data.tables.map((n, i) => (
58-
<TabsTrigger key={i} value={i.toString()}>
59-
<Link to="/tables" search={{ table: n.name }}>
60-
{n.name} [{n.count.toLocaleString()}]
61-
</Link>
62-
</TabsTrigger>
60+
<>
61+
{requestedTableMissing && (
62+
<Card className="mb-3">
63+
<CardHeader>
64+
<CardTitle>Table not found</CardTitle>
65+
<CardDescription>
66+
Could not find "{table}". Showing the first available table
67+
instead.
68+
</CardDescription>
69+
</CardHeader>
70+
</Card>
71+
)}
72+
73+
<Tabs defaultValue={tab}>
74+
<TabsList>
75+
{data.tables.map((n, i) => (
76+
<TabsTrigger key={i} value={i.toString()}>
77+
<Link to="/tables" search={{ table: n.name }}>
78+
{n.name} [{n.count.toLocaleString()}]
79+
</Link>
80+
</TabsTrigger>
81+
))}
82+
</TabsList>
83+
{data.tables.map(({ name }, i) => (
84+
<TabsContent key={i} value={i.toString()} className="py-4">
85+
<Table name={name} />
86+
</TabsContent>
6387
))}
64-
</TabsList>
65-
{data.tables.map(({ name }, i) => (
66-
<TabsContent key={i} value={i.toString()} className="py-4">
67-
<Table name={name} />
68-
</TabsContent>
69-
))}
70-
</Tabs>
88+
</Tabs>
89+
</>
7190
);
7291
}
7392

0 commit comments

Comments
 (0)