@@ -27,6 +27,8 @@ export default {
27
27
availableDimensions : [ ] ,
28
28
availableTimeDimensions : [ ] ,
29
29
availableSegments : [ ] ,
30
+ limit : null ,
31
+ offset : null ,
30
32
} ;
31
33
32
34
data . granularities = [
@@ -42,7 +44,7 @@ export default {
42
44
async mounted ( ) {
43
45
this . meta = await this . cubejsApi . meta ( ) ;
44
46
45
- const { measures, dimensions, segments, timeDimensions, filters } = this . query ;
47
+ const { measures, dimensions, segments, timeDimensions, filters, limit , offset } = this . query ;
46
48
47
49
this . measures = ( measures || [ ] ) . map ( ( m , i ) => ( { index : i , ...this . meta . resolveMember ( m , 'measures' ) } ) ) ;
48
50
this . dimensions = ( dimensions || [ ] ) . map ( ( m , i ) => ( { index : i , ...this . meta . resolveMember ( m , 'dimensions' ) } ) ) ;
@@ -54,8 +56,9 @@ export default {
54
56
} ) ) ;
55
57
this . filters = ( filters || [ ] ) . map ( ( m , i ) => ( {
56
58
...m ,
57
- dimension : this . meta . resolveMember ( m . dimension , [ 'dimensions' , 'measures' ] ) ,
58
- operators : this . meta . filterOperatorsForMember ( m . dimension , [ 'dimensions' , 'measures' ] ) ,
59
+ // using 'dimension' is deprecated, 'member' should be specified instead
60
+ member : this . meta . resolveMember ( m . member || m . dimension , [ 'dimensions' , 'measures' ] ) ,
61
+ operators : this . meta . filterOperatorsForMember ( m . member || m . dimension , [ 'dimensions' , 'measures' ] ) ,
59
62
index : i
60
63
} ) ) ;
61
64
@@ -64,6 +67,8 @@ export default {
64
67
this . availableTimeDimensions = ( this . meta . membersForQuery ( { } , 'dimensions' ) || [ ] )
65
68
. filter ( m => m . type === 'time' ) ;
66
69
this . availableSegments = this . meta . membersForQuery ( { } , 'segments' ) || [ ] ;
70
+ this . limit = ( limit || null ) ;
71
+ this . offset = ( offset || null ) ;
67
72
} ,
68
73
render ( createElement ) {
69
74
const {
@@ -82,6 +87,12 @@ export default {
82
87
availableTimeDimensions,
83
88
availableDimensions,
84
89
availableMeasures,
90
+ limit,
91
+ offset,
92
+ setLimit,
93
+ removeLimit,
94
+ setOffset,
95
+ removeOffset,
85
96
} = this ;
86
97
87
98
let builderProps = { } ;
@@ -102,6 +113,12 @@ export default {
102
113
availableDimensions,
103
114
availableMeasures,
104
115
updateChartType : this . updateChart ,
116
+ limit,
117
+ offset,
118
+ setLimit,
119
+ removeLimit,
120
+ setOffset,
121
+ removeOffset,
105
122
} ;
106
123
107
124
QUERY_ELEMENTS . forEach ( ( e ) => {
@@ -147,9 +164,14 @@ export default {
147
164
validatedQuery ( ) {
148
165
const validatedQuery = { } ;
149
166
let toQuery = member => member . name ;
150
- // TODO: implement order, limit, timezone, renewQuery
167
+ // TODO: implement order, timezone, renewQuery
151
168
169
+ let hasElements = false ;
152
170
QUERY_ELEMENTS . forEach ( ( e ) => {
171
+ if ( ! this [ e ] ) {
172
+ return ;
173
+ }
174
+
153
175
if ( e === 'timeDimensions' ) {
154
176
toQuery = ( member ) => ( {
155
177
dimension : member . dimension . name ,
@@ -158,14 +180,16 @@ export default {
158
180
} ) ;
159
181
} else if ( e === 'filters' ) {
160
182
toQuery = ( member ) => ( {
161
- dimension : member . dimension . name ,
183
+ member : member . member . name ,
162
184
operator : member . operator ,
163
185
values : member . values ,
164
186
} ) ;
165
187
}
166
188
167
189
if ( this [ e ] . length > 0 ) {
168
190
validatedQuery [ e ] = this [ e ] . map ( x => toQuery ( x ) ) ;
191
+
192
+ hasElements = true ;
169
193
}
170
194
} ) ;
171
195
// TODO: implement default heuristics
@@ -174,6 +198,19 @@ export default {
174
198
validatedQuery . filters = validatedQuery . filters . filter ( f => f . operator ) ;
175
199
}
176
200
201
+ // only set limit and offset if there are elements otherwise an invalid request with just limit/offset
202
+ // gets sent when the component is first mounted, but before the actual query is constructed.
203
+ if ( hasElements ) {
204
+ if ( this . limit ) {
205
+ validatedQuery . limit = this . limit ;
206
+ }
207
+
208
+ if ( this . offset ) {
209
+ validatedQuery . offset = this . offset ;
210
+ }
211
+ // add order
212
+ }
213
+
177
214
return validatedQuery ;
178
215
} ,
179
216
} ,
@@ -199,13 +236,13 @@ export default {
199
236
} ;
200
237
}
201
238
} else if ( element === 'filters' ) {
202
- const dimension = {
203
- ...this . meta . resolveMember ( member . dimension , 'dimensions' ) ,
239
+ const filterMember = {
240
+ ...this . meta . resolveMember ( member . member || member . dimension , [ 'dimensions' , 'measures' ] ) ,
204
241
} ;
205
242
206
243
mem = {
207
244
...member ,
208
- dimension ,
245
+ member : filterMember ,
209
246
} ;
210
247
} else {
211
248
mem = this [ `available${ name } ` ] . find ( m => m . name === member ) ;
@@ -254,13 +291,13 @@ export default {
254
291
}
255
292
} else if ( element === 'filters' ) {
256
293
index = this [ element ] . findIndex ( x => x . dimension === old ) ;
257
- const dimension = {
258
- ...this . meta . resolveMember ( member . dimension , 'dimensions' ) ,
294
+ const filterMember = {
295
+ ...this . meta . resolveMember ( member . member || member . dimension , [ 'dimensions' , 'measures' ] ) ,
259
296
} ;
260
297
261
298
mem = {
262
299
...member ,
263
- dimension ,
300
+ member : filterMember ,
264
301
} ;
265
302
} else {
266
303
index = this [ element ] . findIndex ( x => x . name === old ) ;
@@ -294,13 +331,13 @@ export default {
294
331
} ;
295
332
}
296
333
} else if ( element === 'filters' ) {
297
- const dimension = {
298
- ...this . meta . resolveMember ( m . dimension , 'dimensions' ) ,
334
+ const member = {
335
+ ...this . meta . resolveMember ( m . member || m . dimension , [ 'dimensions' , 'measures' ] ) ,
299
336
} ;
300
337
301
338
mem = {
302
339
...m ,
303
- dimension ,
340
+ member ,
304
341
} ;
305
342
} else {
306
343
mem = this [ `available${ name } ` ] . find ( x => x . name === m ) ;
@@ -311,8 +348,20 @@ export default {
311
348
312
349
this [ element ] = elements ;
313
350
} ,
351
+ setLimit ( limit ) {
352
+ this . limit = limit ;
353
+ } ,
354
+ removeLimit ( ) {
355
+ this . limit = null ;
356
+ } ,
357
+ setOffset ( offset ) {
358
+ this . offset = offset ;
359
+ } ,
360
+ removeOffset ( ) {
361
+ this . offset = null ;
362
+ } ,
314
363
updateChart ( chartType ) {
315
364
this . chartType = chartType ;
316
365
} ,
317
366
} ,
318
- } ;
367
+ } ;
0 commit comments