-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(local-explorer-ui): Added initial data studio plumbing #12518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 29 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
68487ef
Minor Tailwind CSS linting fixes
NuroDev 7f43d5c
Minor Tailwind CSS linting fixes
NuroDev 334acbe
Added initial D1 route plumbing
NuroDev 43a6b47
Added `lodash` dependency
NuroDev ae30d73
Added `@types/lodash` dev dependency
NuroDev c7deb47
Add initial (D1) driver plumbing
NuroDev e1526b4
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev d3082c0
Added changeset
NuroDev 87bb21c
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev c0bef86
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 50d44ec
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 93ac650
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev ca30e3f
Removed placeholder driver logic from D1 database route
NuroDev fb7bbf7
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 22a69e6
Minor refactoring
NuroDev 09133d9
Minor `StudioSQLiteExplainTab` refactoring
NuroDev f3187e7
Minor SQLite driver generator refactoring
NuroDev 39c88ec
Improve driver JSDoc's
NuroDev 1e7e857
Removed `mysql` dialect support
NuroDev 12138db
Minor refactoring / code cleanup
NuroDev 2e810b3
Added explicit returns to `CursorV2`
NuroDev e26192d
Fixed Devin critical suggestions
NuroDev 355e6b9
Fixed Devin minor suggestions
NuroDev 44b98b8
Replaced `Promise.all` with `Promise.allSettled`
NuroDev 0c86976
Improved data fetching error message
NuroDev 5e9789f
Added granular data fetching error handling
NuroDev 589b7bd
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 0f61c9c
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 31dd02b
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 3cd4e28
Fix `TOKEN_IDENTIFIER` & `TOKEN_STRING_LITERAL` regex pattern parenth…
NuroDev 4525660
[C3] bump sv from 0.11.4 to 0.12.1 in /packages/create-cloudflare/src…
dependabot[bot] cbd2e8c
fix(wrangler): don't proxy localhost requests during dev (#12516)
edmundhung 9378280
[wrangler] Use project's package manager in wrangler setup (#12437)
MattieTK 17fdca7
Skip TurboRepo running builds in Vite playground packages (#12450)
jamesopstad ac29fe9
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 23656ba
Refactored sidebar to have re-usable item group component
NuroDev 1bafa14
Refactored to use a unified breadcrumb component
NuroDev 82536b7
Added basic unit tests for SQLite driver + utils
NuroDev a82a064
Fixed React fragment missing key
NuroDev b516b8d
Replaced `lodash` with inline forks
NuroDev fa79a07
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev 690d78a
Improved changeset description
NuroDev bcb4087
Merge branch 'main' into NuroDev/local-explorer-studio-plumbing
NuroDev d934801
Replaced `String(...)` with `JSON.stringify(...)`
NuroDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| --- | ||
| "@cloudflare/local-explorer-ui": minor | ||
| --- | ||
|
|
||
| Implemented initial data studio driver support. | ||
|
|
||
| This provides the initial plumbing needed to add the complete data studio component to the local explorer in a later PR. | ||
|
|
||
| This is an experimental WIP feature. |
This file contains hidden or 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 hidden or 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
209 changes: 209 additions & 0 deletions
209
packages/local-explorer-ui/src/components/studio/Explain/SQLiteExplainTab.tsx
emily-shen marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,209 @@ | ||
| import { cn, Tooltip } from "@cloudflare/kumo"; | ||
| import { TableIcon } from "@phosphor-icons/react"; | ||
| import { Fragment } from "react"; | ||
| import type { StudioResultSet } from "../../../types/studio"; | ||
| import type { ReactNode } from "react"; | ||
|
|
||
| interface StudioSQLiteExplainProps { | ||
| data: StudioResultSet; | ||
| } | ||
|
|
||
| interface StudioSQLiteExplainRow { | ||
| id: number; | ||
| parent: number; | ||
| detail: string; | ||
| } | ||
|
|
||
| interface StudioSQLiteExplainTree extends StudioSQLiteExplainRow { | ||
| children: StudioSQLiteExplainTree[]; | ||
| } | ||
|
|
||
| export function StudioSQLiteExplainTab({ | ||
| data, | ||
| }: StudioSQLiteExplainProps): JSX.Element { | ||
| const rows = data.rows as unknown as StudioSQLiteExplainRow[]; | ||
|
|
||
| let tree = rows.map( | ||
| (r) => | ||
| ({ | ||
| ...r, | ||
| children: [], | ||
| }) satisfies StudioSQLiteExplainTree | ||
| ); | ||
|
|
||
| const nodeTable = tree.reduce( | ||
| (a, b) => ({ | ||
| ...a, | ||
| [b.id]: b, | ||
| }), | ||
| {} as Record<string, StudioSQLiteExplainTree> | ||
| ); | ||
|
|
||
| for (const node of tree) { | ||
| if (node.parent) { | ||
| nodeTable[node.parent]?.children.push(node); | ||
| } | ||
| } | ||
|
|
||
| tree = tree.filter((node) => node.parent === 0); | ||
|
|
||
| return ( | ||
| <div className="w-full h-full grow p-8 overflow-auto"> | ||
| <div className="font-mono text-sm"> | ||
| <ExplainNodes data={tree} /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| interface ExplainNodesProps { | ||
| data: StudioSQLiteExplainTree[]; | ||
| } | ||
|
|
||
| function ExplainNodes({ data }: ExplainNodesProps): JSX.Element { | ||
| return ( | ||
| <> | ||
| {data.map((row) => { | ||
| const { label, performance } = describeExplainNode(row.detail); | ||
|
|
||
| return ( | ||
| <Fragment key={row.id}> | ||
| <div className="h-8 flex gap-2 items-center"> | ||
| <div | ||
| className={cn("inline-flex border rounded-full", { | ||
| "bg-green-500": performance === "fast", | ||
| "bg-red-500": performance === "slow", | ||
| "bg-yellow-500": performance === "medium", | ||
| "bg-gray-500": performance === "neutral", | ||
| })} | ||
| style={{ width: 10, height: 10, marginLeft: -5 }} | ||
| /> | ||
| <div>{label}</div> | ||
| </div> | ||
| <div className="pl-4 border-l"> | ||
| <ExplainNodes data={row.children} /> | ||
| </div> | ||
| </Fragment> | ||
| ); | ||
| })} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| type ExplainNodePerformance = "slow" | "medium" | "fast" | "neutral"; | ||
|
|
||
| /** | ||
| * Convert an EXPLAIN step detail string into a UI-friendly | ||
| * description with performance classification and formatted label. | ||
| * | ||
| * Performance indicates execution efficiency: | ||
| * - slow: likely very costly | ||
| * - medium: potentially adds extra work | ||
| * - fast: generally efficient | ||
| * - neutral: informational only | ||
| * | ||
| * @param detail - The raw detail text from the EXPLAIN result | ||
| * | ||
| * @returns Object containing a ReactNode label and performance level | ||
| */ | ||
| function describeExplainNode(d: string): { | ||
| label: ReactNode; | ||
| performance: ExplainNodePerformance; | ||
| } { | ||
| if (d.startsWith("SCAN ")) { | ||
| return { | ||
| performance: "slow", | ||
| label: ( | ||
| <div className="flex items-center"> | ||
| <strong>SCAN </strong> | ||
| <span className="border border-color p-1 mx-2 rounded flex items-center gap-2"> | ||
| <TableIcon /> | ||
| {d.substring("SCAN ".length)} | ||
| </span> | ||
| </div> | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| if (d.startsWith("CORRELATED ")) { | ||
| return { | ||
| performance: "slow", | ||
| label: ( | ||
| <div> | ||
| <Tooltip | ||
| side="bottom" | ||
| content={ | ||
| <div className="flex flex-col gap-2"> | ||
| <div> | ||
| This subquery depends on values from the outer query, so | ||
| it's evaluated once per outer row.{" "} | ||
| <strong className="text-red-500"> | ||
| Can be slow on large inputs | ||
| </strong> | ||
| . | ||
| </div> | ||
| <div className="text-green-500"> | ||
| Mitigate by indexing the correlated columns or rewriting as a | ||
| JOIN + aggregate. | ||
| </div> | ||
| </div> | ||
| } | ||
| > | ||
| <strong className="underline cursor-pointer">CORRELATED</strong> | ||
| </Tooltip> | ||
| <span>{d.substring("CORRELATED".length)}</span> | ||
| </div> | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| if (d.startsWith("SEARCH ")) { | ||
| return { | ||
| performance: "fast", | ||
| label: ( | ||
| <div> | ||
| <strong>SEARCH </strong> | ||
| <span>{d.substring("SEARCH".length)}</span> | ||
| </div> | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| if ( | ||
| d.startsWith("USE TEMP B-TREE FOR ORDER BY") || | ||
| d.startsWith("USE TEMP B-TREE FOR GROUP BY") || | ||
| d.startsWith("USE TEMP B-TREE FOR DISTINCT") | ||
| ) { | ||
| return { | ||
| performance: "medium", | ||
| label: ( | ||
| <Tooltip | ||
| side="bottom" | ||
| content={ | ||
| <div className="flex flex-col gap-2"> | ||
| <div> | ||
| SQLite can’t return rows in the requested order/grouping | ||
| directly, so it gathers them into a temporary structure and | ||
| processes them before returning results.{" "} | ||
| <span className="text-red-500"> | ||
| This adds extra work and grows with result size. | ||
| </span> | ||
| </div> | ||
| <div className="text-green-500"> | ||
| Add an index that matches the clause (ORDER BY / GROUP BY / | ||
| DISTINCT) to avoid the temp structure. | ||
| </div> | ||
| </div> | ||
| } | ||
| > | ||
| <strong className="underline cursor-pointer">{d}</strong> | ||
| </Tooltip> | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| label: <span>{d}</span>, | ||
| performance: "neutral", | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have a single error banner? instead of making it resource specific.
i see the pr description says you made it more granular but i'm just wondering why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought about this as well. The only reason I made these errors unique is so if (for whatever reason) D1 databases fail to load but KV does, you can still access your local KV namespaces and not have the sidebar just set all items to render an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about setting a single error, and returning an empty array for the problematic resource if there is an error?