From aa28488bb70c929566eaa7b368d33e2a2c765c70 Mon Sep 17 00:00:00 2001 From: Ditadi Date: Tue, 9 Dec 2025 14:15:02 +0000 Subject: [PATCH] fix: type-safety demo theme --- .../client/src/routes/__root.tsx | 2 +- .../client/src/routes/index.tsx | 6 +- .../client/src/routes/type-safety.route.tsx | 144 ++++++++---------- 3 files changed, 70 insertions(+), 82 deletions(-) diff --git a/apps/dev-playground/client/src/routes/__root.tsx b/apps/dev-playground/client/src/routes/__root.tsx index 31e7c33..c4baee2 100644 --- a/apps/dev-playground/client/src/routes/__root.tsx +++ b/apps/dev-playground/client/src/routes/__root.tsx @@ -66,7 +66,7 @@ function RootComponent() { diff --git a/apps/dev-playground/client/src/routes/index.tsx b/apps/dev-playground/client/src/routes/index.tsx index 0ae35bf..43047cf 100644 --- a/apps/dev-playground/client/src/routes/index.tsx +++ b/apps/dev-playground/client/src/routes/index.tsx @@ -124,10 +124,10 @@ function IndexRoute() {
-

+

Type-Safe SQL

-

+

Generate TypeScript types from SQL files at build time. Full IntelliSense for query names, parameters, and results.

@@ -141,7 +141,7 @@ function IndexRoute() {
-
+

built by databricks using app-kit

diff --git a/apps/dev-playground/client/src/routes/type-safety.route.tsx b/apps/dev-playground/client/src/routes/type-safety.route.tsx index 1205a1c..c7e8572 100644 --- a/apps/dev-playground/client/src/routes/type-safety.route.tsx +++ b/apps/dev-playground/client/src/routes/type-safety.route.tsx @@ -1,15 +1,15 @@ -import { createFileRoute, retainSearchParams } from "@tanstack/react-router"; -import { useEffect, useState } from "react"; -import { codeToHtml } from "shiki"; -import { Header } from "@/components/layout/header"; -import { Button } from "@/components/ui/button"; import { + Button, Card, CardContent, CardDescription, CardHeader, CardTitle, -} from "@/components/ui/card"; +} from "@databricks/app-kit-ui/react"; +import { createFileRoute, retainSearchParams } from "@tanstack/react-router"; +import { useEffect, useState } from "react"; +import { codeToHtml } from "shiki"; +import { Header } from "@/components/layout/header"; export const Route = createFileRoute("/type-safety")({ component: TypeSafetyRoute, @@ -34,17 +34,9 @@ function CodeBlock({ }).then(setHtml); }, [code, lang]); - if (!html) { - return ( -
-        {code}
-      
- ); - } - return (
); @@ -128,14 +120,14 @@ function FlowStep({
{number}
{title} @@ -167,7 +159,7 @@ function FlowDiagram() { /> {index < steps.length - 1 && (
)}
@@ -185,6 +177,7 @@ function IntelliSenseDemo() { const [timeoutIds, setTimeoutIds] = useState[]>( [], ); + const [html, setHtml] = useState(""); const queryNames = [ "apps_list", @@ -298,63 +291,61 @@ function IntelliSenseDemo() { scheduleFromStep(0); }; - const codeLines = [ - "const { data } = useAnalyticsQuery(", - step >= 2 ? ' "spend_data",' : ' "|"', - " {", + // Use a unique placeholder that shiki won't transform + const CURSOR_PLACEHOLDER = "___CURSOR___"; + + // Build code based on step - show cursor where user is "typing" + const code = step >= 3 - ? ' startDate: sql.date("2024-01-01"),' + ? `const { data } = useAnalyticsQuery( + "spend_data", + { + startDate: sql.date("2024-01-01"), + endDate: sql.date("2024-12-31"), + } +); + +data?.map(row => row.${CURSOR_PLACEHOLDER})` : step >= 2 - ? " |" - : "", - step >= 3 ? ' endDate: sql.date("2024-12-31"),' : "", - " }", - ");", - "", - step >= 3 ? "data?.map(row => row.|)" : "", - ].filter(Boolean); + ? `const { data } = useAnalyticsQuery( + "spend_data", + { + ${CURSOR_PLACEHOLDER} + } +);` + : `const { data } = useAnalyticsQuery( + "${CURSOR_PLACEHOLDER}" +);`; + + useEffect(() => { + codeToHtml(code, { + lang: "typescript", + theme: "dark-plus", + }).then((highlighted) => { + // Replace placeholder with cursor HTML + const cursorHtml = `|`; + setHtml(highlighted.replace(CURSOR_PLACEHOLDER, cursorHtml)); + }); + }, [code]); return (
-
-
-          {codeLines.map((line) => (
-            
- {line.includes("|") ? ( - <> - {line.split("|")[0]} - - | - - {line.split("|")[1]} - - ) : ( - - {line} - - )} -
- ))} -
+
+
{showAutocomplete && ( -
-
+
+
QueryRegistry
{queryNames.map((name, i) => (
{name} @@ -364,11 +355,11 @@ function IntelliSenseDemo() { )} {showParamHint && ( -
-
+
+
Parameters (spend_data)
-
+
groupBy: SQLStringMarker
startDate: SQLDateMarker
endDate: SQLDateMarker
@@ -377,8 +368,8 @@ function IntelliSenseDemo() { )} {showResultHint && ( -
-
+
+
Result Fields
{["group_key: string", "period: string", "cost_usd: number"].map( @@ -386,7 +377,7 @@ function IntelliSenseDemo() {
{field} @@ -406,7 +397,7 @@ function IntelliSenseDemo() { {isPaused ? "Resume" : "Pause"} )} - + {isPaused && "(Paused) "} {step === 0 && "Click to start"} {step === 1 && "Query name autocomplete"} @@ -421,8 +412,8 @@ function IntelliSenseDemo() { function TypeSafetyRoute() { return ( -
-
+
+
( -
- +
+ -- {type.annotation} - + {type.helper}