-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Summary
When a query contains features that the visual query builder cannot handle, show the full query as an editable JSON editor instead of the point-and-click interface. This eliminates hidden configuration and allows users to edit advanced features directly.
Problem
The visual query builder supports a subset of Cube.js capabilities:
| Feature | JSON Support | Visual Builder |
|---|---|---|
| Simple filters (operators equals, notEquals) | Yes | Yes |
| Simple filters (other operators) | No, but planned | Yes |
| OR/AND filter groups | No, but planned | No |
| Time dimensions | Yes | No |
Date range with $__from/$__to |
Yes | No |
| Dashboard variables in dimensions/measures/filter-members | No | No |
| Dashboard variables in filter-values | Yes | Yes |
Currently, queries with advanced features have hidden configuration that users cannot see or edit in the UI. This leads to confusion and silent behavior.
Solution
Implement a detectUnsupportedFeatures(query) function and switch to a JSON editor when unsupported features are detected:
function QueryEditor({ query, ... }) {
const unsupportedFeatures = detectUnsupportedFeatures(query);
if (unsupportedFeatures.length > 0) {
return <JsonQueryEditor query={query} reasons={unsupportedFeatures} />;
}
return <VisualQueryEditor query={query} />;
}The JSON editor should show:
- An info banner explaining why JSON mode is active (list the detected features)
- The full query as
editableRead-only JSON A "Try Visual Editor" button (with warning if features would be lost)
Implementation
- Create
detectUnsupportedFeatures(query): string[]function - Create basic
JsonQueryEditorJsonQueryViewercomponent - Update
QueryEditorto check for unsupported features first
detectUnsupportedFeatures
Simple boolean checks that return human-readable descriptions:
- Check for time dimensions
Future PRs that add further functionality, will also add features to this detect… function:
- Check for filter operators other than equals/notEquals (eg.
<) - Check for OR/AND filter groups
JsonQuery Editor Viewer
- Display info banner with reasons for JSON mode
- JSON text
editorviewer (textarea or basic Monaco) Parse JSON on change, pass to onChange handler"Try Visual Editor" toggle with confirmation if lossy
Benefits
- No hidden config - Users see exactly what is configured
Editable - Users can modify advanced features directly- LLM-friendly - JSON format matches Cube docs, so LLMs can generate valid queries, and put them directly into Dashboard/Panel JSON
- Future-proof - As visual builder adds features, queries graduate to visual mode
Trade-offs
- Users with advanced queries lose visual builder (but gain visibility)
- JSON editing is harder for non-technical users
- Invalid JSON produces errors only when query runs
Future Enhancements
These are optional improvements for a separate PR if users need the JSON viewer to be editable, and perhaps need better validation:
Editable:
- JSON text editor (textarea or basic Monaco)
- Parse JSON on change, pass to onChange handler
- "Try Visual Editor" toggle with confirmation if lossy
Better validation:
- Add Zod schema validation for real-time error feedback
- Monaco JSON Schema integration for autocomplete
- Inline error markers showing which field is invalid
For now, relying on Cube API error messages should be sufficient.
Context
Identified during OR/AND filter implementation. Rather than building piecemeal solutions for each unsupported feature, a consistent JSON fallback provides better architecture and user experience.