Skip to content

Commit eef035a

Browse files
authored
Merge pull request #22 from objectql/copilot/visual-reporting-multi-table-queries
2 parents a5cf8eb + 5762c69 commit eef035a

File tree

17 files changed

+3556
-0
lines changed

17 files changed

+3556
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,41 @@ graph TD
130130
131131
```
132132

133+
## 📊 Visual Reporting
134+
135+
ObjectQL includes a comprehensive **visual reporting system** similar to Salesforce Reports:
136+
137+
* **Multi-Table Joins**: Create reports spanning multiple related objects using dot notation (`project.owner.name`)
138+
* **Three Report Types**: Tabular (lists), Summary (grouped), and Matrix (pivot tables)
139+
* **Visual Builder**: React components for building reports without code
140+
* **Grouping & Aggregations**: Count, sum, average, min, max across grouped data
141+
* **Chart Integration**: Built-in visualization support
142+
143+
**Example Report Definition:**
144+
```yaml
145+
name: tasks_by_project
146+
label: Tasks by Project and Priority
147+
type: summary
148+
object: tasks
149+
150+
columns:
151+
- field: project.name
152+
label: Project
153+
- field: priority
154+
label: Priority
155+
156+
groupings:
157+
- field: project.name
158+
- field: priority
159+
160+
aggregations:
161+
- field: id
162+
function: count
163+
label: Task Count
164+
```
165+
166+
See [Visual Reporting Guide](./docs/guide/visual-reporting.md) for complete documentation.
167+
133168
## 🛣 Roadmap
134169
135170
* [ ] **Phase 1: Core Protocol:** Define stable `UnifiedQuery` types and AST parser.

VISUAL_REPORTING_README.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Visual Multi-Table Reporting
2+
3+
A comprehensive visual reporting system for ObjectQL that enables users to create sophisticated multi-table reports without writing code, similar to Salesforce Reports and other low-code platforms.
4+
5+
## Quick Start
6+
7+
### 1. Define a Report (YAML)
8+
9+
Create a `.report.yml` file:
10+
11+
```yaml
12+
# reports/my_report.report.yml
13+
name: active_tasks
14+
label: Active Tasks
15+
type: tabular
16+
object: tasks
17+
18+
columns:
19+
- field: name
20+
label: Task Name
21+
- field: project.name
22+
label: Project
23+
- field: assigned_to
24+
label: Assignee
25+
26+
filters:
27+
- - completed
28+
- "="
29+
- false
30+
31+
sort:
32+
- - due_date
33+
- asc
34+
```
35+
36+
### 2. Use the Report Builder (React)
37+
38+
```tsx
39+
import { ReportBuilder, ReportViewer } from '@objectql/ui';
40+
41+
function MyReportPage() {
42+
const [report, setReport] = useState(null);
43+
44+
return (
45+
<ReportBuilder
46+
availableObjects={['tasks', 'projects', 'users']}
47+
onSave={(report) => setReport(report)}
48+
onPreview={(report) => runReport(report)}
49+
/>
50+
);
51+
}
52+
```
53+
54+
### 3. Compile and Execute
55+
56+
```typescript
57+
import { ReportCompiler } from '@objectql/core';
58+
59+
const compiler = new ReportCompiler();
60+
const query = compiler.compile(reportDefinition);
61+
62+
// Execute the query
63+
const results = await objectQL.find(reportDefinition.object, query);
64+
```
65+
66+
## Features
67+
68+
### Multi-Table Joins
69+
70+
Access related data using dot notation:
71+
72+
```yaml
73+
columns:
74+
- field: name # Current object
75+
- field: project.name # One level deep
76+
- field: project.owner.name # Two levels deep
77+
```
78+
79+
### Report Types
80+
81+
1. **Tabular** - Simple list view
82+
2. **Summary** - Grouped with aggregations
83+
3. **Matrix** - Cross-tabulation (pivot table)
84+
85+
### Grouping & Aggregations
86+
87+
```yaml
88+
type: summary
89+
groupings:
90+
- field: project.name
91+
sort: asc
92+
aggregations:
93+
- field: id
94+
function: count
95+
label: Task Count
96+
```
97+
98+
### Charts
99+
100+
```yaml
101+
chart:
102+
type: bar
103+
groupBy: priority
104+
measure: id
105+
aggregation: count
106+
```
107+
108+
## Documentation
109+
110+
- [Visual Reporting Guide](../../docs/guide/visual-reporting.md) - Complete guide (English)
111+
- [中文文档](../../docs/VISUAL_REPORTING_CN.md) - Chinese documentation
112+
113+
## Examples
114+
115+
See `examples/project-management/src/reports/` for complete examples:
116+
117+
- `active_tasks.report.yml` - Simple list report
118+
- `tasks_by_project_priority.report.yml` - Summary report with grouping
119+
- `task_matrix.report.yml` - Matrix report
120+
121+
## Architecture
122+
123+
```
124+
User Interface (React)
125+
126+
ReportBuilder / ReportViewer Components
127+
128+
Report Definition (YAML)
129+
130+
ReportCompiler
131+
132+
UnifiedQuery (JSON-DSL)
133+
134+
ObjectQL Driver
135+
136+
MongoDB / PostgreSQL
137+
```
138+
139+
## API
140+
141+
### ReportCompiler
142+
143+
```typescript
144+
const compiler = new ReportCompiler();
145+
146+
// Compile report to query
147+
const query = compiler.compile(reportDefinition);
148+
149+
// Validate report definition
150+
const { valid, errors } = compiler.validate(reportDefinition);
151+
152+
// Generate preview query (limited rows)
153+
const previewQuery = compiler.compilePreview(reportDefinition, 10);
154+
```
155+
156+
### React Components
157+
158+
**ReportBuilder**
159+
```tsx
160+
<ReportBuilder
161+
initialReport={report}
162+
availableObjects={['tasks', 'projects']}
163+
onSave={handleSave}
164+
onPreview={handlePreview}
165+
/>
166+
```
167+
168+
**ReportViewer**
169+
```tsx
170+
<ReportViewer
171+
report={reportDefinition}
172+
data={reportData}
173+
loading={false}
174+
onRefresh={handleRefresh}
175+
onExport={handleExport}
176+
/>
177+
```
178+
179+
## Best Practices
180+
181+
1. **Limit Relationship Depth**: Keep to 3-4 levels maximum
182+
2. **Index Lookup Fields**: Ensure lookup fields are indexed
183+
3. **Use Specific Fields**: Select only needed fields, not all
184+
4. **Apply Filters Early**: Filter at the lowest level possible
185+
5. **Cache Results**: Cache frequently accessed reports
186+
187+
## Testing
188+
189+
Run tests:
190+
191+
```bash
192+
npm test --workspace=@objectql/core
193+
```
194+
195+
Test files:
196+
- `packages/core/test/report-compiler.test.ts`
197+
198+
## License
199+
200+
MIT

0 commit comments

Comments
 (0)