Skip to content

Commit dfef076

Browse files
authored
fix tables route fallback when query table is missing (#69)
* fix tables route fallback when query table is missing * address PR feedback on tables tab sync
1 parent 6dc5ba0 commit dfef076

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

ui/src/routes/tables.tsx

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

50-
const tab = table
51-
? data.tables.findIndex(({ name }) => name === table).toString()
52-
: "0";
50+
const requestedTableIndex = table
51+
? data.tables.findIndex(({ name }) => name === table)
52+
: -1;
53+
54+
const requestedTableMissing = !!table && requestedTableIndex < 0;
55+
const tab = String(Math.max(requestedTableIndex, 0));
5356

5457
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>
58+
<>
59+
{requestedTableMissing && (
60+
<Card className="mb-3">
61+
<CardHeader>
62+
<CardTitle>Table not found</CardTitle>
63+
<CardDescription>
64+
Could not find "{table}". Showing the first available table
65+
instead.
66+
</CardDescription>
67+
</CardHeader>
68+
</Card>
69+
)}
70+
71+
<Tabs key={tab} defaultValue={tab}>
72+
<TabsList>
73+
{data.tables.map((n, i) => (
74+
<TabsTrigger key={i} value={i.toString()}>
75+
<Link to="/tables" search={{ table: n.name }}>
76+
{n.name} [{n.count.toLocaleString()}]
77+
</Link>
78+
</TabsTrigger>
79+
))}
80+
</TabsList>
81+
{data.tables.map(({ name }, i) => (
82+
<TabsContent key={i} value={i.toString()} className="py-4">
83+
<Table name={name} />
84+
</TabsContent>
6385
))}
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>
86+
</Tabs>
87+
</>
7188
);
7289
}
7390

0 commit comments

Comments
 (0)