-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): dozer integration (#3185)
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com> Co-authored-by: alvarius <alvarius@lattice.xyz>
- Loading branch information
1 parent
6c056de
commit 2f2e63a
Showing
53 changed files
with
606 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/explorer": patch | ||
--- | ||
|
||
Exploring worlds on Redstone and Garnet chains will now retrieve data from the hosted SQL indexer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
...es/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/DataExplorer.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/Explorer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use client"; | ||
|
||
import { useParams } from "next/navigation"; | ||
import { parseAsString, useQueryState } from "nuqs"; | ||
import { Hex } from "viem"; | ||
import { useEffect } from "react"; | ||
import { useChain } from "../../../../hooks/useChain"; | ||
import { usePrevious } from "../../../../hooks/usePrevious"; | ||
import { useTableDataQuery } from "../../../../queries/useTableDataQuery"; | ||
import { useTablesQuery } from "../../../../queries/useTablesQuery"; | ||
import { constructTableName } from "../../../../utils/constructTableName"; | ||
import { indexerForChainId } from "../../../../utils/indexerForChainId"; | ||
import { SQLEditor } from "./SQLEditor"; | ||
import { TableSelector } from "./TableSelector"; | ||
import { TablesViewer } from "./TablesViewer"; | ||
|
||
export function Explorer() { | ||
const { worldAddress } = useParams(); | ||
const { id: chainId } = useChain(); | ||
const indexer = indexerForChainId(chainId); | ||
const [query, setQuery] = useQueryState("query", parseAsString.withDefault("")); | ||
const [selectedTableId] = useQueryState("tableId"); | ||
const prevSelectedTableId = usePrevious(selectedTableId); | ||
|
||
const { data: tables } = useTablesQuery(); | ||
const table = tables?.find(({ tableId }) => tableId === selectedTableId); | ||
const { data: tableData, isLoading, isFetched } = useTableDataQuery({ table, query }); | ||
|
||
useEffect(() => { | ||
if (table && (!query || prevSelectedTableId !== selectedTableId)) { | ||
const tableName = constructTableName(table, worldAddress as Hex, chainId); | ||
|
||
if (indexer.type === "sqlite") { | ||
setQuery(`SELECT * FROM "${tableName}"`); | ||
} else { | ||
setQuery(`SELECT ${Object.keys(table.schema).join(", ")} FROM ${tableName}`); | ||
} | ||
} | ||
}, [chainId, setQuery, selectedTableId, table, worldAddress, prevSelectedTableId, query, indexer.type]); | ||
|
||
return ( | ||
<> | ||
{indexer.type !== "sqlite" && <SQLEditor />} | ||
<TableSelector tables={tables} /> | ||
<TablesViewer table={table} tableData={tableData} isLoading={isLoading || !isFetched} /> | ||
</> | ||
); | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/SQLEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { PlayIcon } from "lucide-react"; | ||
import { useQueryState } from "nuqs"; | ||
import { useEffect } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { Button } from "../../../../../../components/ui/Button"; | ||
import { Form, FormControl, FormField, FormItem } from "../../../../../../components/ui/Form"; | ||
import { Input } from "../../../../../../components/ui/Input"; | ||
|
||
export function SQLEditor() { | ||
const [query, setQuery] = useQueryState("query"); | ||
const form = useForm({ | ||
defaultValues: { | ||
query: query || "", | ||
}, | ||
}); | ||
|
||
const handleSubmit = form.handleSubmit((data) => { | ||
setQuery(data.query); | ||
}); | ||
|
||
useEffect(() => { | ||
form.reset({ query: query || "" }); | ||
}, [query, form]); | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={handleSubmit}> | ||
<div className="relative"> | ||
<FormField | ||
name="query" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormControl> | ||
<Input {...field} className="pr-[90px]" /> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<Button className="absolute right-1 top-1 h-8 px-4" type="submit"> | ||
<PlayIcon className="mr-1.5 h-3 w-3" /> Run | ||
</Button> | ||
</div> | ||
</form> | ||
</Form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.