Skip to content

Commit cfdfcc1

Browse files
authored
feat(explorer): run query shortcut (#3443)
1 parent a6fe15c commit cfdfcc1

File tree

6 files changed

+72
-44
lines changed

6 files changed

+72
-44
lines changed

.changeset/perfect-steaks-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/explorer": patch
3+
---
4+
5+
SQL queries can be executed using the Cmd/Ctrl + Enter shortcut.

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/Explorer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export function Explorer() {
3838
}, [chainId, setQuery, selectedTableId, table, worldAddress, prevSelectedTableId, query, indexer.type]);
3939

4040
return (
41-
<>
42-
{indexer.type !== "sqlite" && <SQLEditor table={table} />}
41+
<div className="space-y-4">
4342
<TableSelector tables={tables} />
43+
{indexer.type !== "sqlite" && <SQLEditor table={table} />}
4444
<TablesViewer table={table} query={query} />
45-
</>
45+
</div>
4646
);
4747
}

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/ExportButton.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export function ExportButton({ tableData, isLoading }: { tableData?: TData; isLo
1414
<DropdownMenu>
1515
<DropdownMenuTrigger asChild>
1616
<Button variant="outline" disabled={!tableData || isLoading}>
17-
<DownloadIcon className="mr-2 h-4 w-4" />
18-
Export
17+
<DownloadIcon className="h-4 w-4" />
1918
</Button>
2019
</DropdownMenuTrigger>
2120
<DropdownMenuContent>

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/SQLEditor.tsx

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

3-
import { PlayIcon } from "lucide-react";
4-
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
3+
import { CommandIcon, CornerDownLeft } from "lucide-react";
4+
import { KeyCode, KeyMod, editor } from "monaco-editor/esm/vs/editor/editor.api";
55
import { useQueryState } from "nuqs";
66
import { useEffect, useRef, useState } from "react";
77
import { useForm } from "react-hook-form";
@@ -58,40 +58,64 @@ export function SQLEditor({ table }: Props) {
5858

5959
return (
6060
<Form {...form}>
61-
<form
62-
className={cn("relative w-full rounded-md border bg-black px-3 py-2 ring-offset-background", {
63-
"outline-none ring-2 ring-ring ring-offset-2": isFocused,
64-
})}
65-
onSubmit={handleSubmit}
66-
>
67-
<FormField
68-
name="query"
69-
render={({ field }) => (
70-
<div ref={containerRef} className="min-h-[21px] w-full">
71-
<Editor
72-
width="100%"
73-
theme="hc-black"
74-
value={decodeURIComponent(field.value)}
75-
options={monacoOptions}
76-
language="sql"
77-
onChange={(value) => field.onChange(encodeURIComponent(value ?? ""))}
78-
onMount={(editor) => {
79-
editorRef.current = editor;
61+
<form onSubmit={handleSubmit} className="space-y-4">
62+
<div
63+
className={cn("relative w-full rounded-md border bg-black px-3 py-2 ring-offset-background", {
64+
"outline-none ring-2 ring-ring ring-offset-2": isFocused,
65+
})}
66+
>
67+
<FormField
68+
name="query"
69+
render={({ field }) => (
70+
<div ref={containerRef} className="min-h-[21px] w-full">
71+
<Editor
72+
width="100%"
73+
theme="hc-black"
74+
value={decodeURIComponent(field.value)}
75+
options={monacoOptions}
76+
language="sql"
77+
onChange={(value) => field.onChange(encodeURIComponent(value ?? ""))}
78+
onMount={(editor) => {
79+
editorRef.current = editor;
80+
editor.addAction({
81+
id: "executeSQL",
82+
label: "Execute SQL command",
83+
keybindings: [KeyMod.CtrlCmd | KeyCode.Enter],
84+
run: () => {
85+
handleSubmit();
86+
},
87+
});
8088

81-
updateHeight();
82-
editor.onDidContentSizeChange(updateHeight);
83-
editor.onDidFocusEditorText(() => setIsFocused(true));
84-
editor.onDidBlurEditorText(() => setIsFocused(false));
85-
}}
86-
loading={null}
87-
/>
88-
</div>
89-
)}
90-
/>
89+
updateHeight();
90+
editor.onDidContentSizeChange(updateHeight);
91+
editor.onDidFocusEditorText(() => setIsFocused(true));
92+
editor.onDidBlurEditorText(() => setIsFocused(false));
93+
}}
94+
loading={null}
95+
/>
96+
</div>
97+
)}
98+
/>
99+
</div>
91100

92-
<Button className="absolute bottom-1 right-1 h-8 px-4" type="submit">
93-
<PlayIcon className="mr-1.5 h-3 w-3" /> Run
94-
</Button>
101+
<div className="flex justify-end">
102+
<Button className="flex gap-2 pl-4 pr-3" type="submit">
103+
Run
104+
<span className="flex items-center gap-0.5 text-white/60">
105+
{navigator.platform.toLowerCase().includes("mac") ? (
106+
<>
107+
<CommandIcon className="h-3 w-3" />
108+
<CornerDownLeft className="h-3 w-3" />
109+
</>
110+
) : (
111+
<>
112+
<span className="text-xs">CTRL</span>
113+
<CornerDownLeft className="h-3 w-3" />
114+
</>
115+
)}
116+
</span>
117+
</Button>
118+
</div>
95119
</form>
96120
</Form>
97121
);

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/TableSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function TableSelector({ tables }: { tables?: Table[] }) {
4545
}, [selectedTableId, setTableId, tables]);
4646

4747
return (
48-
<div className="w-full py-4">
48+
<div className="w-full">
4949
<Popover open={open} onOpenChange={setOpen}>
5050
<PopoverTrigger asChild>
5151
<Button

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/TablesViewer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export function TablesViewer({ table, query }: { table?: TableType; query?: stri
9797
});
9898

9999
return (
100-
<>
101-
<div className="flex items-center justify-between gap-4 pb-4">
100+
<div className="!-mt-10 space-y-4">
101+
<div className="flex w-1/2 items-center gap-4">
102102
<Input
103103
placeholder="Filter..."
104104
value={globalFilter}
@@ -172,7 +172,7 @@ export function TablesViewer({ table, query }: { table?: TableType; query?: stri
172172
)}
173173
</div>
174174

175-
<div className="flex items-center justify-end space-x-2 py-4">
175+
<div className="flex items-center justify-end space-x-2">
176176
<div className="flex-1 text-sm text-muted-foreground">
177177
{tableData && `Total rows: ${tableData.rows.length.toLocaleString()}`}
178178
</div>
@@ -196,6 +196,6 @@ export function TablesViewer({ table, query }: { table?: TableType; query?: stri
196196
</Button>
197197
</div>
198198
</div>
199-
</>
199+
</div>
200200
);
201201
}

0 commit comments

Comments
 (0)