Skip to content

Commit bb2d169

Browse files
authored
Merge pull request #218 from tablelandnetwork/staging
Staging
2 parents a72a941 + 9596941 commit bb2d169

File tree

11 files changed

+99
-54
lines changed

11 files changed

+99
-54
lines changed

packages/cli/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ SESSION_COOKIE_NAME="STUDIO_SESSION"
66
SESSION_COOKIE_PASS="secure password secure password secure password secure password secure password secure password secure password"
77
DATA_SEAL_PASS="secure password secure password secure password secure password secure password secure password secure password"
88
POSTMARK_API_KEY=fillme(optional)
9+
NEXT_PUBLIC_API_ROUTER_INFURA_KEY="api key"
10+
NEXT_PUBLIC_API_ROUTER_QUICK_NODE_KEY="api key"

packages/web/app/[team]/[project]/(project)/deployments/[[...slug]]/_components/data-table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
TableHeader,
2626
TableRow,
2727
} from "@/components/ui/table";
28+
import { objectToTableData } from "@/lib/utils";
2829

2930
interface DataTableProps<TData, TValue> {
3031
columns: Array<ColumnDef<TData, TValue>>;
@@ -39,7 +40,7 @@ export function DataTable<TData, TValue>({
3940
React.useState<VisibilityState>({});
4041

4142
const table = useReactTable({
42-
data,
43+
data: objectToTableData<TData>(data),
4344
columns,
4445
getCoreRowModel: getCoreRowModel(),
4546
getPaginationRowModel: getPaginationRowModel(),

packages/web/app/sql-log/page.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default async function TxnPage({
6060
<div className="flex flex-col">
6161
<HashDisplay
6262
hash={log.txHash}
63-
name="txn hash"
63+
hashDesc="txn hash"
6464
numCharacters={8}
6565
copy
6666
className={cn(
@@ -81,18 +81,20 @@ export default async function TxnPage({
8181
)}
8282
</div>
8383
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
84-
<MetricCard>
85-
<MetricCardHeader>
86-
<MetricCardTitle>Sent by</MetricCardTitle>
87-
</MetricCardHeader>
88-
<MetricCardContent>
89-
<HashDisplay
90-
hash={log.caller}
91-
copy
92-
className="text-3xl text-foreground"
93-
/>
94-
</MetricCardContent>
95-
</MetricCard>
84+
{log.caller && (
85+
<MetricCard>
86+
<MetricCardHeader>
87+
<MetricCardTitle>Sent by</MetricCardTitle>
88+
</MetricCardHeader>
89+
<MetricCardContent>
90+
<HashDisplay
91+
hash={log.caller}
92+
copy
93+
className="text-3xl text-foreground"
94+
/>
95+
</MetricCardContent>
96+
</MetricCard>
97+
)}
9698
<MetricCard>
9799
<MetricCardHeader>
98100
<MetricCardTitle>Timestamp</MetricCardTitle>

packages/web/components/nav-new-table.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ export default function NavNewTable({
1313
project: string;
1414
}>();
1515

16-
const team = api.teams.teamBySlug.useQuery({ slug: teamSlug });
17-
const project = api.projects.projectBySlug.useQuery(
18-
{ teamId: team.data!.id, slug: projectSlug },
19-
{ enabled: !!team.data },
16+
const { data: team } = api.teams.teamBySlug.useQuery({ slug: teamSlug });
17+
const teamId = team?.id;
18+
const { data: project } = api.projects.projectBySlug.useQuery(
19+
{ teamId, slug: projectSlug },
20+
{ enabled: !!teamId },
2021
);
2122

22-
if (!team.data || !project.data) {
23+
if (!team || !project) {
2324
return null;
2425
}
2526

@@ -28,10 +29,10 @@ export default function NavNewTable({
2829
<Crumb
2930
title={crumbTitle}
3031
items={[
31-
{ label: team.data.name, href: `/${team.data.slug}` },
32+
{ label: team.name, href: `/${team.slug}` },
3233
{
33-
label: project.data.name,
34-
href: `/${team.data.slug}/${project.data.slug}`,
34+
label: project.name,
35+
href: `/${team.slug}/${project.slug}`,
3536
},
3637
]}
3738
/>

packages/web/components/nav-table.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,31 @@ export default function NavNewTable({
1818
}>();
1919

2020
// TODO: Create a single endpoint for this.
21-
const team = api.teams.teamBySlug.useQuery({ slug: teamSlug });
22-
const project = api.projects.projectBySlug.useQuery(
23-
{ teamId: team.data!.id, slug: projectSlug },
24-
{ enabled: !!team.data },
21+
const { data: team } = api.teams.teamBySlug.useQuery({ slug: teamSlug });
22+
const teamId = team?.id;
23+
const { data: project } = api.projects.projectBySlug.useQuery(
24+
{ teamId, slug: projectSlug },
25+
{ enabled: !!teamId },
2526
);
26-
const table = api.tables.tableByProjectIdAndSlug.useQuery(
27-
{ projectId: project.data!.id, slug: tableSlug },
28-
{ enabled: !!project.data },
27+
const projectId = project?.id;
28+
const { data: table } = api.tables.tableByProjectIdAndSlug.useQuery(
29+
{ projectId: projectId!, slug: tableSlug },
30+
{ enabled: !!projectId },
2931
);
3032

31-
if (!team.data || !project.data || !table.data) {
33+
if (!team || !project || !table) {
3234
return null;
3335
}
3436

3537
return (
3638
<div className={className}>
3739
<Crumb
38-
title={table.data.name}
40+
title={table.name}
3941
items={[
40-
{ label: team.data.name, href: `/${team.data.slug}` },
42+
{ label: team.name, href: `/${team.slug}` },
4143
{
42-
label: project.data.name,
43-
href: `/${team.data.slug}/${project.data.slug}`,
44+
label: project.name,
45+
href: `/${team.slug}/${project.slug}`,
4446
},
4547
]}
4648
/>

packages/web/components/sql-logs.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,28 @@ export default function SQLLogs({
6666
Refresh
6767
</Button>
6868
{error && <div className="text-red-500">{error}</div>}
69-
{logs.slice(offset, offset + pageSize).map((log) => (
70-
<Link
71-
key={`${log.txHash}-${log.eventIndex}`}
72-
className={cn(
73-
"flex items-center gap-4 rounded-sm border border-gray-200 p-2 transition-all",
74-
log.error ? "bg-red-200 hover:bg-red-300" : "hover:bg-accent",
75-
)}
76-
href={`/sql-log?chainId=${chain}&txnHash=${log.txHash}&index=${log.eventIndex}`}
77-
target="_blank"
78-
>
79-
{log.error && <AlertCircle className="shrink-0" />}
80-
<div className="shrink-0 text-sm text-muted-foreground">
81-
{new Date(log.timestamp * 1000).toLocaleString()}
69+
<div className="w-full">
70+
{logs.slice(offset, offset + pageSize).map((log) => (
71+
<div className="mb-4" key={`${log.txHash}-${log.eventIndex}`}>
72+
<Link
73+
className={cn(
74+
"flex items-center rounded-sm border border-gray-200 p-2 transition-all",
75+
log.error ? "bg-red-200 hover:bg-red-300" : "hover:bg-accent",
76+
)}
77+
href={`/sql-log?chainId=${chain}&txnHash=${log.txHash}&index=${log.eventIndex}`}
78+
target="_blank"
79+
>
80+
{log.error && <AlertCircle className="shrink-0" />}
81+
<div className="px-2 text-sm text-muted-foreground">
82+
{new Date(log.timestamp * 1000).toLocaleString()}
83+
</div>
84+
<div className="break-all font-mono text-sm">
85+
<div>{log.statement}</div>
86+
</div>
87+
</Link>
8288
</div>
83-
<div className="font-mono text-sm">{log.statement}</div>
84-
</Link>
85-
))}
89+
))}
90+
</div>
8691
<Paginator
8792
numItems={logs.length}
8893
page={page}

packages/web/components/tag-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const TagInput = forwardRef<HTMLDivElement, Props>(
6666
<div
6767
id={id}
6868
ref={ref}
69-
className="flex w-full max-w-full flex-wrap space-x-1 overflow-scroll rounded-md border pl-1 focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2"
69+
className="flex w-full max-w-full flex-wrap space-x-1 rounded-md border pl-1 focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2"
7070
>
7171
{tags.map((tag, i) => (
7272
<div

packages/web/components/wagmi-provider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const { chains, publicClient, webSocketPublicClient } = configuredChains(
88
typeof window !== "undefined" &&
99
(window.location?.hostname === "localhost" ||
1010
window.location?.hostname === "127.0.0.1"),
11+
{
12+
infura: process.env.NEXT_PUBLIC_API_ROUTER_INFURA_KEY ?? "",
13+
quickNode: process.env.NEXT_PUBLIC_API_ROUTER_QUICK_NODE_KEY ?? "",
14+
},
1115
);
1216

1317
const config = createConfig({

packages/web/lib/api-router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export const apiRouter = appRouter(
1111
(seal) => `${baseUrl}/invite?seal=${seal}`,
1212
process.env.DATA_SEAL_PASS!,
1313
process.env.NODE_ENV === "development",
14-
process.env.API_ROUTER_INFURA_KEY ?? "",
15-
process.env.API_ROUTER_QUICK_NODE_KEY ?? "",
14+
process.env.NEXT_PUBLIC_API_ROUTER_INFURA_KEY ?? "",
15+
process.env.NEXT_PUBLIC_API_ROUTER_QUICK_NODE_KEY ?? "",
1616
);

packages/web/lib/utils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
import { clsx, type ClassValue } from "clsx";
22
import { twMerge } from "tailwind-merge";
3+
import * as z from "zod";
34

45
export function cn(...inputs: ClassValue[]) {
56
return twMerge(clsx(inputs));
67
}
8+
9+
const objSchema = z.record(z.string(), z.any());
10+
const arrSchema = z.array(z.any());
11+
// accepts an Array with any entries that are any kind of Object and goes
12+
// through each Object's keys to ensure that values containing an Object or
13+
// Array are `stringify`ed. This enables showing nested data in an html table
14+
// without the dreded "[object Object]"
15+
export function objectToTableData<TData>(data: any[]) {
16+
data = arrSchema.parse(data);
17+
18+
return data.map(function (d) {
19+
return Object.fromEntries(
20+
Object.entries(objSchema.parse(d)).map(function ([key, val]) {
21+
// check for Object or Array
22+
if (typeof val === "object" && val !== null) {
23+
try {
24+
val = JSON.stringify(val);
25+
} catch (err) {
26+
console.log(`could not stringify`, err);
27+
}
28+
}
29+
30+
return [key, val];
31+
}),
32+
) as TData;
33+
});
34+
}

packages/web/lib/validator-queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function getPopularTables(
6868
export interface SqlLog {
6969
blockNumber: number;
7070
txIndex: number;
71-
caller: string;
71+
caller: string | null;
7272
error: string | null;
7373
eventIndex: number;
7474
eventType: "ContractRunSQL" | "ContractCreateTable";

0 commit comments

Comments
 (0)