From 9894d68f84fd0ecbfd7cf84f9460f1e0402fa4ec Mon Sep 17 00:00:00 2001 From: bi0dread <175858839+bi0dread@users.noreply.github.com> Date: Sun, 25 Oct 2026 13:33:36 +0330 Subject: [PATCH] feat(playground): filter sample data with live DSL examples --- .github/workflows/playground-ci.yml | 2 + playground/README.md | 19 +++ playground/index.html | 9 +- playground/package.json | 3 +- playground/src/App.tsx | 28 +++- playground/src/DataPreview.tsx | 114 ++++++++++++++ playground/src/preview.test.ts | 62 ++++++++ playground/src/preview.ts | 232 ++++++++++++++++++++++++++++ playground/src/sampleData.ts | 72 +++++++++ playground/src/samples.ts | 68 ++++++++ playground/src/styles.css | 59 +++++++ 11 files changed, 657 insertions(+), 11 deletions(-) create mode 100644 playground/src/DataPreview.tsx create mode 100644 playground/src/preview.test.ts create mode 100644 playground/src/preview.ts create mode 100644 playground/src/sampleData.ts create mode 100644 playground/src/samples.ts diff --git a/.github/workflows/playground-ci.yml b/.github/workflows/playground-ci.yml index 2ed7b46..2db5852 100644 --- a/.github/workflows/playground-ci.yml +++ b/.github/workflows/playground-ci.yml @@ -48,6 +48,8 @@ jobs: - run: npm ci # Same build the deploy runs: tsc --noEmit && vite build. - run: npm run build + - name: Live data preview regression + run: npm run test:preview # DSL-emitter regression checks (hunt #7). Compiled with the tsc that is # already a devDependency so no test runner has to be added; the script # throws on a failed check, which fails the step. diff --git a/playground/README.md b/playground/README.md index 2277068..cf2b883 100644 --- a/playground/README.md +++ b/playground/README.md @@ -10,8 +10,27 @@ into the **Query** node, and the resulting DSL string is generated live. npm install npm run dev # http://localhost:5173 npm run build # static bundle in dist/ +npm run test:preview # live DSL/table regression checks ``` +## Live data examples + +Below the canvas, the live data preview parses the generated DSL string and applies +it to 18 sample customer accounts and their orders. Six presets demonstrate nested +conditions, active customers, revenue and date ranges, case-insensitive name search, +pagination, and filtered Orders preloads. Loading a preset also updates the canvas. + +Edit the preview's DSL to try your own filters, or enable **Follow visual builder** +to resume using the canvas output. **All source rows** shows the original dataset +with badges for matching, excluded, and paginated-out rows. Expand a row's Orders +button to compare the original orders with the query's filtered preload. + +This is a browser-side demonstration, not a database execution engine. Comparisons +are typed, NULL predicates follow SQL three-valued logic, and sorting places NULLs +last. Regex operators and relations other than Orders report an explicit error. +Backend collation, date coercion, and NULL ordering can differ. The Go adapters +remain authoritative for actual database queries. + ## Blocks | Block | Emits | Notes | diff --git a/playground/index.html b/playground/index.html index f704ac3..c3edf45 100644 --- a/playground/index.html +++ b/playground/index.html @@ -26,8 +26,8 @@ .project-intro p { margin: 8px 0; } .project-intro a, .project-guide a { color: #9baeff; text-underline-offset: 3px; } .project-intro nav { display: flex; flex-wrap: wrap; gap: 8px 24px; } - #root { height: 85vh; min-height: 540px; } - #root .app { height: 100%; } + body > #root { height: auto; } + #root .app { height: 85vh; min-height: 540px; } .project-guide { padding-top: 32px; padding-bottom: 48px; } .project-guide section { margin: 0 0 32px; } .project-guide h2 { font-size: 24px; line-height: 1.3; } @@ -49,15 +49,16 @@

figo — Go dynamic query builder and filter DSL

-
+

Try the visual filter builder

Add a Condition block, choose a field and operator, and connect it to the Query node. Combine conditions with AND, OR, and NOT blocks. Sort, Page, and Load blocks add sorting, pagination, and relation filters. Copy the generated DSL into your application.

-

The playground generates filter text in your browser. It does not run Go code or connect to your database. JavaScript is needed for the interactive builder; the examples and documentation below are available without it.

+

The playground generates filter text in your browser. The live data preview applies that DSL to sample accounts and orders, so you can see matching rows, sorting, and pagination immediately. It does not run Go code or connect to your database. JavaScript is needed for the interactive builder and preview; the examples and documentation below are available without it.

Build database queries from API filters in Go

diff --git a/playground/package.json b/playground/package.json index 86aca96..5b1bda1 100644 --- a/playground/package.json +++ b/playground/package.json @@ -6,7 +6,8 @@ "scripts": { "dev": "vite", "build": "tsc --noEmit && vite build", - "preview": "vite preview" + "preview": "vite preview", + "test:preview": "tsc src/preview.test.ts --outDir node_modules/.cache/preview-tests --target es2022 --module esnext --moduleResolution bundler --skipLibCheck && node node_modules/.cache/preview-tests/preview.test.js" }, "dependencies": { "@xyflow/react": "^12.8.2", diff --git a/playground/src/App.tsx b/playground/src/App.tsx index 4ed8c95..b128d7b 100644 --- a/playground/src/App.tsx +++ b/playground/src/App.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useRef } from 'react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { Background, BackgroundVariant, @@ -19,6 +19,8 @@ import { edgeTypes } from './edges' import { Palette, type PaletteItem } from './Palette' import { DslPanel } from './DslPanel' import { generateDsl, type AppNode } from './dsl' +import { DataPreview } from './DataPreview' +import { sampleGraph } from './samples' type Kind = 'expr' | 'sort' | 'page' | 'load' @@ -235,7 +237,9 @@ function defaultData(item: PaletteItem): Record { function Flow() { const [nodes, setNodes, onNodesChange] = useNodesState(presetNodes()) const [edges, setEdges, onEdgesChange] = useEdgesState(presetEdges()) - const { screenToFlowPosition, getNode } = useReactFlow() + const { screenToFlowPosition, getNode, fitView } = useReactFlow() + const [sampleId, setSampleId] = useState('complex') + const [sampleRevision, setSampleRevision] = useState(0) const wrapRef = useRef(null) const nodeSeq = useRef(0) @@ -344,23 +348,33 @@ function Flow() { [addNode, screenToFlowPosition], ) - const loadExample = useCallback(() => { - setNodes(presetNodes()) - setEdges(presetEdges()) + const loadSample = useCallback((id: string) => { + const graph = id === 'complex' ? { nodes: presetNodes(), edges: presetEdges() } : sampleGraph(id) + setNodes(graph.nodes) + setEdges(graph.edges) + setSampleId(id) + setSampleRevision((revision) => revision + 1) }, [setNodes, setEdges]) + useEffect(() => { + const timer = window.setTimeout(() => { void fitView({ padding: 0.16, maxZoom: 1 }) }, 50) + return () => window.clearTimeout(timer) + }, [sampleRevision, fitView]) + const clearAll = useCallback(() => { setNodes((nds) => nds.filter((n) => n.type === 'root')) setEdges([]) }, [setNodes, setEdges]) return ( + <>
🧩 figo playground drag figo operations, wire them up, read the DSL - + Live data ↓ + GitHub ↗ @@ -396,6 +410,8 @@ function Flow() {
+ + ) } diff --git a/playground/src/DataPreview.tsx b/playground/src/DataPreview.tsx new file mode 100644 index 0000000..435513c --- /dev/null +++ b/playground/src/DataPreview.tsx @@ -0,0 +1,114 @@ +import { Fragment, useEffect, useMemo, useState } from 'react' +import { CUSTOMER_FIELDS, CUSTOMERS, type Customer } from './sampleData' +import { previewDsl } from './preview' +import { SAMPLES } from './samples' + +const dollars = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }) +const nullable = (value: string | null) => value ?? 'NULL' + +export function DataPreview({ dsl, sampleId, revision, onSample }: { + dsl: string; sampleId: string; revision: number; onSample: (id: string) => void +}) { + const [editedDsl, setEditedDsl] = useState(null) + const [showAll, setShowAll] = useState(false) + const [expanded, setExpanded] = useState>(new Set()) + useEffect(() => { setEditedDsl(null) }, [revision]) + const activeDsl = editedDsl ?? dsl + const result = useMemo(() => { + try { return { preview: previewDsl(activeDsl, CUSTOMERS), error: null } } + catch (error) { return { preview: null, error: error instanceof Error ? error.message : 'This filter could not be applied.' } } + }, [activeDsl]) + const { preview, error } = result + const rows = preview ? showAll ? CUSTOMERS : preview.rows : [] + const sample = SAMPLES.find((item) => item.id === sampleId) ?? SAMPLES[0] + const toggle = (id: number) => setExpanded((previous) => { + const next = new Set(previous); if (next.has(id)) next.delete(id); else next.add(id); return next + }) + const matchLabel = (row: Customer) => !preview?.matchingIds.has(row.id) ? 'Filtered out' : !preview.visibleIds.has(row.id) ? 'Outside page' : 'In results' + + return ( +
+
+
+

DSL → sample data

+

See your filter in action

+

Change the blocks above or edit the DSL below. The table updates immediately.

+
+ +
+

{sample.description}

+
+ + +
+