|
| 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