Skip to content

Commit 29e2655

Browse files
Copilothotlong
andcommitted
Update dashboard schema and tests to use modern MongoDB-style filters
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d22ccaf commit 29e2655

3 files changed

Lines changed: 30 additions & 27 deletions

File tree

examples/todo/src/client-test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ async function main() {
5555
console.log('✅ Deleted:', deleted);
5656
}
5757

58-
// 6. Advanced Query (AST)
59-
console.log('\n🧠 Testing Advanced Query (Select & AST)...');
58+
// 6. Advanced Query (Modern Filter Syntax)
59+
console.log('\n🧠 Testing Advanced Query (Select & Modern Filter)...');
6060
const advancedResult = await client.data.find('todo_task', {
6161
select: ['subject', 'priority'],
62-
filters: ['priority', '>=', 2],
62+
where: {
63+
priority: { $gte: 2 } // Modern MongoDB-style filter syntax
64+
},
6365
sort: ['-priority']
6466
});
6567
console.log(`🎉 Found ${advancedResult.count} high priority tasks:`);

packages/spec/src/ui/dashboard.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('DashboardWidgetSchema', () => {
9797
title: 'Top Accounts',
9898
type: 'table',
9999
object: 'account',
100-
filter: [{ field: 'annual_revenue', operator: '>', value: 1000000 }],
100+
filter: { annual_revenue: { $gt: 1000000 } }, // Modern MongoDB-style filter
101101
layout: { x: 0, y: 6, w: 12, h: 4 },
102102
};
103103

@@ -109,7 +109,7 @@ describe('DashboardWidgetSchema', () => {
109109
title: 'Active Opportunities',
110110
type: 'metric',
111111
object: 'opportunity',
112-
filter: { field: 'status', operator: 'equals', value: 'active' },
112+
filter: { status: 'active' },
113113
aggregate: 'count',
114114
layout: { x: 0, y: 0, w: 3, h: 2 },
115115
};
@@ -209,15 +209,15 @@ describe('DashboardSchema', () => {
209209
object: 'opportunity',
210210
valueField: 'amount',
211211
aggregate: 'sum',
212-
filter: { field: 'is_closed', operator: 'equals', value: false },
212+
filter: { is_closed: false },
213213
layout: { x: 0, y: 0, w: 3, h: 2 },
214214
},
215215
{
216216
title: 'Open Opportunities',
217217
type: 'metric',
218218
object: 'opportunity',
219219
aggregate: 'count',
220-
filter: { field: 'is_closed', operator: 'equals', value: false },
220+
filter: { is_closed: false },
221221
layout: { x: 3, y: 0, w: 3, h: 2 },
222222
},
223223
{
@@ -236,7 +236,7 @@ describe('DashboardSchema', () => {
236236
object: 'opportunity',
237237
valueField: 'amount',
238238
aggregate: 'avg',
239-
filter: { field: 'status', operator: 'equals', value: 'won' },
239+
filter: { status: 'won' },
240240
layout: { x: 9, y: 0, w: 3, h: 2 },
241241
},
242242
{
@@ -246,7 +246,7 @@ describe('DashboardSchema', () => {
246246
categoryField: 'stage',
247247
valueField: 'amount',
248248
aggregate: 'sum',
249-
filter: { field: 'is_closed', operator: 'equals', value: false },
249+
filter: { is_closed: false },
250250
layout: { x: 0, y: 2, w: 8, h: 4 },
251251
options: {
252252
horizontal: true,
@@ -268,7 +268,7 @@ describe('DashboardSchema', () => {
268268
categoryField: 'close_date',
269269
valueField: 'amount',
270270
aggregate: 'sum',
271-
filter: { field: 'close_date', operator: 'last_n_months', value: 12 },
271+
filter: { close_date: '{last_12_months}' },
272272
layout: { x: 0, y: 6, w: 12, h: 4 },
273273
options: {
274274
smoothCurve: true,
@@ -292,7 +292,7 @@ describe('DashboardSchema', () => {
292292
type: 'metric',
293293
object: 'case',
294294
aggregate: 'count',
295-
filter: { field: 'status', operator: 'not_equals', value: 'closed' },
295+
filter: { status: { $ne: 'closed' } },
296296
layout: { x: 0, y: 0, w: 3, h: 2 },
297297
options: {
298298
color: '#FF6384',
@@ -303,10 +303,10 @@ describe('DashboardSchema', () => {
303303
type: 'metric',
304304
object: 'case',
305305
aggregate: 'count',
306-
filter: [
307-
{ field: 'status', operator: 'equals', value: 'closed' },
308-
{ field: 'closed_date', operator: 'today' },
309-
],
306+
filter: { // Modern MongoDB-style filter
307+
status: 'closed',
308+
closed_date: '{today}'
309+
},
310310
layout: { x: 3, y: 0, w: 3, h: 2 },
311311
},
312312
{
@@ -326,7 +326,7 @@ describe('DashboardSchema', () => {
326326
object: 'case',
327327
valueField: 'satisfaction_rating',
328328
aggregate: 'avg',
329-
filter: { field: 'satisfaction_rating', operator: 'not_null' },
329+
filter: { satisfaction_rating: { $null: false } },
330330
layout: { x: 9, y: 0, w: 3, h: 2 },
331331
options: {
332332
max: 5,
@@ -339,7 +339,7 @@ describe('DashboardSchema', () => {
339339
object: 'case',
340340
categoryField: 'priority',
341341
aggregate: 'count',
342-
filter: { field: 'status', operator: 'not_equals', value: 'closed' },
342+
filter: { status: { $ne: 'closed' } },
343343
layout: { x: 0, y: 2, w: 6, h: 4 },
344344
},
345345
{
@@ -354,7 +354,7 @@ describe('DashboardSchema', () => {
354354
title: 'Recent High Priority Cases',
355355
type: 'table',
356356
object: 'case',
357-
filter: { field: 'priority', operator: 'equals', value: 'high' },
357+
filter: { priority: 'high' }, // Modern MongoDB-style filter
358358
layout: { x: 0, y: 6, w: 12, h: 4 },
359359
options: {
360360
columns: ['case_number', 'subject', 'account', 'owner', 'created_date'],
@@ -379,10 +379,10 @@ describe('DashboardSchema', () => {
379379
object: 'opportunity',
380380
valueField: 'amount',
381381
aggregate: 'sum',
382-
filter: [
383-
{ field: 'status', operator: 'equals', value: 'won' },
384-
{ field: 'close_date', operator: 'this_quarter' },
385-
],
382+
filter: { // Modern MongoDB-style filter
383+
status: 'won',
384+
close_date: '{this_quarter}'
385+
},
386386
layout: { x: 0, y: 0, w: 4, h: 3 },
387387
options: {
388388
prefix: '$',
@@ -395,15 +395,15 @@ describe('DashboardSchema', () => {
395395
type: 'metric',
396396
object: 'account',
397397
aggregate: 'count',
398-
filter: { field: 'created_date', operator: 'this_month' },
398+
filter: { created_date: '{this_month}' }, // Modern MongoDB-style filter
399399
layout: { x: 4, y: 0, w: 4, h: 3 },
400400
},
401401
{
402402
title: 'Active Users',
403403
type: 'metric',
404404
object: 'user',
405405
aggregate: 'count',
406-
filter: { field: 'is_active', operator: 'equals', value: true },
406+
filter: { is_active: true },
407407
layout: { x: 8, y: 0, w: 4, h: 3 },
408408
},
409409
{
@@ -413,7 +413,7 @@ describe('DashboardSchema', () => {
413413
categoryField: 'product_line',
414414
valueField: 'amount',
415415
aggregate: 'sum',
416-
filter: { field: 'status', operator: 'equals', value: 'won' },
416+
filter: { status: 'won' },
417417
layout: { x: 0, y: 3, w: 8, h: 4 },
418418
},
419419
{

packages/spec/src/ui/dashboard.zod.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from 'zod';
2+
import { FilterConditionSchema } from '../data/filter.zod';
23

34
/**
45
* Chart Type Enum
@@ -28,8 +29,8 @@ export const DashboardWidgetSchema = z.object({
2829
/** Data Source Object */
2930
object: z.string().optional().describe('Data source object name'),
3031

31-
/** Data Filter (ObjectQL JSON) */
32-
filter: z.any().optional().describe('Data filter criteria'),
32+
/** Data Filter (MongoDB-style FilterCondition) */
33+
filter: FilterConditionSchema.optional().describe('Data filter criteria'),
3334

3435
/** Category Field (X-Axis / Group By) */
3536
categoryField: z.string().optional().describe('Field for grouping (X-Axis)'),

0 commit comments

Comments
 (0)