Skip to content

Commit 76e9ba7

Browse files
committed
(web) lint and build
1 parent 88dab41 commit 76e9ba7

File tree

5 files changed

+46
-54
lines changed

5 files changed

+46
-54
lines changed

packages/web/app/[team]/[project]/[env]/console/page.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
1-
import { type schema } from "@tableland/studio-store";
2-
import { cache } from "react";
31
import { TRPCError } from "@trpc/server";
4-
import { getSession } from "@tableland/studio-api";
5-
import { cookies, headers } from "next/headers";
6-
import NeedsDeploy from "./_components/needs-deploy";
72
import { Console } from "@/components/console";
8-
import { api } from "@/trpc/server";
93
import {
10-
defBySlug,
114
environmentBySlug,
125
projectBySlug,
136
teamBySlug,
147
} from "@/lib/api-helpers";
15-
import DefDetails from "@/components/def-details";
16-
import TableWrapper from "@/components/table-wrapper";
178

189
export default async function ConsolePage({
1910
params,
2011
}: {
2112
params: { team: string; project: string; env: string };
2213
}) {
23-
const session = await getSession({ headers: headers(), cookies: cookies() });
2414
const team = await teamBySlug(params.team);
2515
const project = await projectBySlug(params.project, team.id);
2616
const environment = await environmentBySlug(project.id, params.env);
2717

2818
if (!environment) {
2919
throw new TRPCError({
3020
code: "NOT_FOUND",
31-
status: 404,
3221
});
3322
}
3423

35-
const isAuthorized = await cache(api.teams.isAuthorized)({ teamId: team.id });
36-
3724
return (
3825
<main className="flex-1 p-4">
3926
<Console environmentId={environment.id} />

packages/web/app/[team]/[project]/_components/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useParams,
1313
useRouter,
1414
useSelectedLayoutSegment,
15+
usePathname,
1516
} from "next/navigation";
1617
import { skipToken } from "@tanstack/react-query";
1718
import { useState } from "react";
@@ -23,7 +24,6 @@ import {
2324
} from "@/components/ui/dropdown-menu";
2425
import { api } from "@/trpc/react";
2526
import { SidebarContainer, SidebarSection } from "@/components/sidebar";
26-
import { usePathname } from "next/navigation";
2727
import ImportTableForm from "@/components/import-table-form";
2828
import NewDefForm from "@/components/new-def-form";
2929
import SidebarLink from "@/components/sidebar-link";

packages/web/components/code-editor.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import React from "react";
22
import Editor from "react-simple-code-editor";
3+
// @ts-expect-error this came from the o.g. console and there's no types for this afaik
34
import { highlight, languages } from "prismjs/components/prism-core";
45
import "prismjs/components/prism-clike";
56
import "prismjs/components/prism-sql";
67

7-
const hightlightWithLineNumbers = (input, language, hideLineNumbers): any =>
8+
const hightlightWithLineNumbers = (input: any, language: any, hideLineNumbers: boolean): any =>
89
highlight(input, language)
910
.split("\n")
1011
.map(
11-
(line, i) =>
12+
(line: string, i: number) =>
1213
`${
1314
hideLineNumbers
1415
? ""
15-
: `<span class='editorLineNumber'>${(i as number) + 1}</span>`
16-
}${line as string}`,
16+
: `<span class='editorLineNumber'>${(i) + 1}</span>`
17+
}${line}`,
1718
)
1819
.join("\n");
1920

packages/web/components/console.tsx

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
"use client";
22

3-
import { v4 as uuidv4 } from "uuid";
43
import * as React from "react";
5-
import {
6-
Database,
7-
Validator,
8-
chainsMap,
9-
type Schema,
10-
helpers,
11-
type Result,
12-
} from "@tableland/sdk";
4+
import { Database, helpers } from "@tableland/sdk";
135
import { studioAliases, getBaseUrl } from "@tableland/studio-client";
146
import { init } from "@tableland/sqlparser";
15-
import { api } from "@/trpc/react";
16-
import { cn, objectToTableData } from "@/lib/utils";
177
import { CodeEditor } from "./code-editor";
188
import { DataTable } from "./data-table";
19-
import { Table } from "./ui/table";
9+
import { cn, objectToTableData } from "@/lib/utils";
2010

2111
init().catch((err: any) => {
2212
console.log("could not init sqlparser:", err);
2313
throw err;
2414
});
2515

26-
export function Console({ environmentId }: Props) {
16+
interface Tab {
17+
tabId: number;
18+
name: string;
19+
query: string;
20+
columns?: any[];
21+
results: any[];
22+
messages: string[]
23+
error: any;
24+
queryType: string;
25+
committing: boolean;
26+
}
27+
28+
export function Console({ environmentId }: { environmentId: string; }) {
2729
const [loading, setLoading] = React.useState(false);
28-
const [tabs, setTabs] = React.useState([]);
29-
const [currentTab, setCurrentTab] = React.useState();
30+
const [tabs, setTabs] = React.useState<Tab[]>([]);
31+
const [currentTab, setCurrentTab] = React.useState<number | undefined>();
3032

31-
const runQuery = async function ({ tabId, query: queryText }) {
33+
const runQuery = async function ({ tabId, query: queryText }: { tabId: number; query: string; }) {
3234
if (loading) return;
3335
setLoading(true);
3436

3537
try {
36-
const { statements, type, tables } = await sqlparser.normalize(queryText);
38+
const { statements, tables } = await sqlparser.normalize(queryText);
3739
if (statements.length > 1) {
3840
throw new Error("you may only run one statement at a time");
3941
}
@@ -52,12 +54,11 @@ export function Console({ environmentId }: Props) {
5254
if (!uuTableName) throw new Error("invalid table name");
5355

5456
const chainId = parseInt(uuTableName.split("_").reverse()[1], 10);
55-
const chain = helpers.getChainInfo(chainId);
5657
const baseUrl = helpers.getBaseUrl(chainId);
5758
const db = new Database({ baseUrl, aliases });
5859
const data = await db.prepare(statement).all();
5960
console.log(data);
60-
const columns: Array<ColumnDef<unknown>> | undefined = data
61+
const columns = data
6162
? data.results.length
6263
? Object.keys(data.results[0] as object).map((col) => ({
6364
accessorKey: col,
@@ -67,7 +68,7 @@ export function Console({ environmentId }: Props) {
6768
: undefined;
6869

6970
setTabs(
70-
tabs.map((tab) => {
71+
tabs.map((tab: Tab) => {
7172
if (tab.tabId !== tabId) return tab;
7273

7374
tab.error = null;
@@ -76,16 +77,16 @@ export function Console({ environmentId }: Props) {
7677
tab.columns = columns;
7778
tab.results = data.results;
7879

79-
if (!columns.length && data.success) {
80+
if (!columns?.length && data.success) {
8081
tab.messages = [
8182
"success: true",
8283
`duration: ${data.meta.duration}`,
83-
`tableIds: ${data.meta.txn.tableIds.join(", ")}`,
84-
`transactionHash: ${data.meta.txn.transactionHash}`,
85-
`blockNumber: ${data.meta.txn.blockNumber}`,
86-
`chainId: ${data.meta.txn.chainId}`,
87-
`universalTableNames": ${data.meta.txn.names.join(", ")}`,
88-
`definitionNames: ${data.meta.txn.prefixes.join(", ")}`,
84+
`tableIds: ${data.meta.txn?.tableIds.join(", ")}`,
85+
`transactionHash: ${data.meta.txn?.transactionHash}`,
86+
`blockNumber: ${data.meta.txn?.blockNumber}`,
87+
`chainId: ${data.meta.txn?.chainId}`,
88+
`universalTableNames": ${data.meta.txn?.names.join(", ")}`,
89+
`definitionNames: ${data.meta.txn?.prefixes.join(", ")}`,
8990
];
9091
}
9192

@@ -122,8 +123,10 @@ export function Console({ environmentId }: Props) {
122123

123124
// TODO: this is the only way I can find to get an incrementing default tab
124125
// name with a number that lives across re-renders.
126+
// eslint-disable-next-line
125127
const name = "Tab " + (largestDefaultNum + 1);
126128
const tab = {
129+
// eslint-disable-next-line
127130
tabId: tabs.length === 0 ? 1 : tabs[tabs.length - 1].tabId + 1,
128131
name,
129132
query: "",
@@ -146,14 +149,14 @@ export function Console({ environmentId }: Props) {
146149
};
147150

148151
const openQueryTab = function (id?: number | string) {
149-
if (id) return setCurrentTab(parseInt(id, 10));
152+
if (id) return setCurrentTab(parseInt(id?.toString() || "0", 10));
150153

151154
const tab = newQueryTab();
152155
setCurrentTab(tab.tabId);
153156
};
154157

155158
const closeQueryTab = function (id?: number | string) {
156-
const tabId = parseInt(id, 10);
159+
const tabId = parseInt(id?.toString() || "0", 10);
157160
const isCurrent = currentTab === tabId;
158161

159162
setTabs(tabs.filter((t) => t.tabId !== tabId));
@@ -164,6 +167,7 @@ export function Console({ environmentId }: Props) {
164167
const firstTab = getNewTab();
165168
setTabs([firstTab]);
166169
setCurrentTab(firstTab.tabId);
170+
// eslint-disable-next-line
167171
}, []);
168172

169173
return (
@@ -176,7 +180,7 @@ export function Console({ environmentId }: Props) {
176180
<TabLabel
177181
key={tab.tabId}
178182
tab={tab}
179-
currentTab={currentTab}
183+
currentTab={currentTab || 0}
180184
loading={loading}
181185
openTab={() => openQueryTab(tab.tabId)}
182186
closeTab={() => closeQueryTab(tab.tabId)}
@@ -219,7 +223,7 @@ function QueryPane(props: any): React.JSX.Element {
219223
const { tabId, query: initialQuery, runQuery, loading } = props;
220224

221225
const [query, setQuery] = React.useState(initialQuery);
222-
const updateQuery = function (payload) {
226+
const updateQuery = function (payload: any) {
223227
setQuery(payload.query);
224228
};
225229

@@ -247,12 +251,13 @@ function QueryPane(props: any): React.JSX.Element {
247251
<button
248252
disabled={props.loading}
249253
className="my-4 mr-4 inline-flex h-8 items-center justify-center rounded-md border border-input bg-transparent px-3 text-xs font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
254+
// @ts-expect-error
250255
onClick={sendQuery}
251256
>
252257
Run Query
253258
</button>
254259

255-
{/*<button
260+
{/* <button
256261
className="my-4 mr-4 inline-flex h-8 items-center justify-center rounded-md border border-input bg-transparent px-3 text-xs font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
257262
onClick={() => {
258263
let savedQueries = JSON.parse(
@@ -270,7 +275,7 @@ function QueryPane(props: any): React.JSX.Element {
270275
}}
271276
>
272277
Save
273-
</button>*/}
278+
</button> */}
274279
</li>
275280
</ul>
276281
</div>
@@ -336,7 +341,7 @@ function TabLabel(props: {
336341
}
337342

338343
function ResultSetPane(props: any): React.JSX.Element {
339-
const { error, loading, message, tab } = props;
344+
const { tab } = props;
340345
const formattedData = objectToTableData(tab.results);
341346

342347
return (
@@ -349,7 +354,7 @@ function ResultSetPane(props: any): React.JSX.Element {
349354
)}
350355
{!!tab.messages?.length && (
351356
<div className="mt-4 rounded-md border p-4">
352-
{tab.messages.map((message, i) => {
357+
{tab.messages.map((message: string, i: number) => {
353358
return <p key={i}>{message}</p>;
354359
})}
355360
</div>

packages/web/components/table.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { chainsMap } from "@/lib/chains-map";
3232
import { cn, objectToTableData } from "@/lib/utils";
3333
import { TimeSince } from "@/components/time";
3434
import { api } from "@/trpc/server";
35-
import { Console } from "@/components/console";
3635
import DefDetails from "@/components/def-details";
3736
import { ensureError } from "@/lib/ensure-error";
3837

0 commit comments

Comments
 (0)