@cubejs-client/vue3 0.30.46 → 0.30.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/cubejs-client-vue3.esm.js +468 -623
- package/dist/cubejs-client-vue3.esm.js.map +1 -1
- package/dist/cubejs-client-vue3.js +70 -22
- package/dist/cubejs-client-vue3.js.map +1 -1
- package/dist/cubejs-client-vue3.umd.js +3941 -3931
- package/dist/cubejs-client-vue3.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/QueryBuilder.js +71 -28
|
@@ -1,45 +1,13 @@
|
|
|
1
1
|
import { isQueryPresent, areQueriesEqual, GRANULARITIES, ResultSet, moveItemInArray, movePivotItem, getOrderMembersFromOrder, defaultHeuristics, defaultOrder } from '@cubejs-client/core';
|
|
2
2
|
export { GRANULARITIES } from '@cubejs-client/core';
|
|
3
|
-
import 'core-js/modules/es.object.keys.js';
|
|
4
|
-
import 'core-js/modules/es.symbol.js';
|
|
5
|
-
import 'core-js/modules/es.array.filter.js';
|
|
6
|
-
import 'core-js/modules/es.object.get-own-property-descriptor.js';
|
|
7
|
-
import 'core-js/modules/es.array.for-each.js';
|
|
8
|
-
import 'core-js/modules/web.dom-collections.for-each.js';
|
|
9
|
-
import 'core-js/modules/es.object.get-own-property-descriptors.js';
|
|
10
|
-
import 'core-js/modules/es.object.define-properties.js';
|
|
11
|
-
import 'core-js/modules/es.object.define-property.js';
|
|
12
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
13
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
14
|
-
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
15
|
-
import 'core-js/modules/es.array.iterator.js';
|
|
16
|
-
import 'core-js/modules/es.object.to-string.js';
|
|
17
|
-
import 'core-js/modules/es.promise.js';
|
|
18
|
-
import 'core-js/modules/es.string.iterator.js';
|
|
19
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
20
|
-
import 'core-js/modules/es.array.map.js';
|
|
21
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
22
3
|
import { toPairs, fromPairs, clone, equals } from 'ramda';
|
|
23
4
|
import { h } from 'vue';
|
|
24
|
-
|
|
25
|
-
import 'core-js/modules/es.function.name.js';
|
|
26
|
-
import 'core-js/modules/es.array.reduce.js';
|
|
27
|
-
import 'core-js/modules/es.array.concat.js';
|
|
28
|
-
import 'core-js/modules/es.array.slice.js';
|
|
29
|
-
import 'core-js/modules/es.array.find.js';
|
|
30
|
-
import 'core-js/modules/es.array.find-index.js';
|
|
31
|
-
import 'core-js/modules/es.array.splice.js';
|
|
32
|
-
|
|
33
|
-
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
34
|
-
|
|
35
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
|
|
36
6
|
var QueryRenderer = {
|
|
37
7
|
props: {
|
|
38
8
|
query: {
|
|
39
9
|
type: [Object, Array],
|
|
40
|
-
|
|
41
|
-
return {};
|
|
42
|
-
}
|
|
10
|
+
default: () => ({})
|
|
43
11
|
},
|
|
44
12
|
// TODO: validate with current react implementation
|
|
45
13
|
queries: {
|
|
@@ -55,16 +23,15 @@ var QueryRenderer = {
|
|
|
55
23
|
builderProps: {
|
|
56
24
|
type: Object,
|
|
57
25
|
required: false,
|
|
58
|
-
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
26
|
+
default: () => ({})
|
|
61
27
|
},
|
|
62
28
|
chartType: {
|
|
63
29
|
type: String,
|
|
64
30
|
required: false
|
|
65
31
|
}
|
|
66
32
|
},
|
|
67
|
-
|
|
33
|
+
|
|
34
|
+
data() {
|
|
68
35
|
return {
|
|
69
36
|
mutexObj: {},
|
|
70
37
|
error: undefined,
|
|
@@ -73,236 +40,134 @@ var QueryRenderer = {
|
|
|
73
40
|
sqlQuery: undefined
|
|
74
41
|
};
|
|
75
42
|
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
_context.next = 6;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
_context.next = 4;
|
|
93
|
-
return _this.load();
|
|
94
|
-
|
|
95
|
-
case 4:
|
|
96
|
-
_context.next = 9;
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
case 6:
|
|
100
|
-
if (!isQueryPresent(queries)) {
|
|
101
|
-
_context.next = 9;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_context.next = 9;
|
|
106
|
-
return _this.loadQueries(queries);
|
|
107
|
-
|
|
108
|
-
case 9:
|
|
109
|
-
case "end":
|
|
110
|
-
return _context.stop();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}, _callee);
|
|
114
|
-
}))();
|
|
43
|
+
|
|
44
|
+
async mounted() {
|
|
45
|
+
const {
|
|
46
|
+
query,
|
|
47
|
+
queries
|
|
48
|
+
} = this;
|
|
49
|
+
|
|
50
|
+
if (isQueryPresent(query)) {
|
|
51
|
+
await this.load();
|
|
52
|
+
} else if (isQueryPresent(queries)) {
|
|
53
|
+
await this.loadQueries(queries);
|
|
54
|
+
}
|
|
115
55
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
56
|
+
|
|
57
|
+
render() {
|
|
58
|
+
const {
|
|
59
|
+
$slots,
|
|
60
|
+
resultSet,
|
|
61
|
+
error,
|
|
62
|
+
loading,
|
|
63
|
+
sqlQuery
|
|
64
|
+
} = this;
|
|
65
|
+
const empty = h('div', {});
|
|
66
|
+
let slot = this.$slots.empty ? this.$slots.empty() : empty;
|
|
67
|
+
let controls = h('div', {});
|
|
68
|
+
const onlyDefault = !('empty' in this.$slots) && !('error' in this.$slots);
|
|
126
69
|
|
|
127
70
|
if ($slots.builder && this.builderProps.measures) {
|
|
128
|
-
controls = $slots.builder(
|
|
71
|
+
controls = $slots.builder({ ...this.builderProps
|
|
72
|
+
});
|
|
129
73
|
}
|
|
130
74
|
|
|
131
75
|
if (!loading && resultSet && !error || onlyDefault) {
|
|
132
|
-
|
|
133
|
-
resultSet
|
|
134
|
-
sqlQuery
|
|
76
|
+
let slotProps = {
|
|
77
|
+
resultSet,
|
|
78
|
+
sqlQuery,
|
|
135
79
|
query: this.builderProps.query || this.query
|
|
136
80
|
};
|
|
137
81
|
|
|
138
82
|
if (onlyDefault) {
|
|
139
|
-
slotProps =
|
|
140
|
-
loading
|
|
141
|
-
error
|
|
142
|
-
refetch: this.load
|
|
143
|
-
|
|
83
|
+
slotProps = {
|
|
84
|
+
loading,
|
|
85
|
+
error,
|
|
86
|
+
refetch: this.load,
|
|
87
|
+
...this.builderProps,
|
|
88
|
+
...slotProps
|
|
89
|
+
};
|
|
144
90
|
}
|
|
145
91
|
|
|
146
|
-
slot = $slots
|
|
92
|
+
slot = $slots.default ? $slots.default(slotProps) : slot;
|
|
147
93
|
} else if (error) {
|
|
148
94
|
slot = $slots.error ? $slots.error({
|
|
149
|
-
error
|
|
150
|
-
sqlQuery
|
|
95
|
+
error,
|
|
96
|
+
sqlQuery
|
|
151
97
|
}) : slot;
|
|
152
98
|
}
|
|
153
99
|
|
|
154
100
|
return h('div', {}, [controls, slot]);
|
|
155
101
|
},
|
|
102
|
+
|
|
156
103
|
methods: {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
_this2.resultSet = _context2.sent;
|
|
219
|
-
_context2.next = 25;
|
|
220
|
-
break;
|
|
221
|
-
|
|
222
|
-
case 22:
|
|
223
|
-
_context2.next = 24;
|
|
224
|
-
return _this2.cubejsApi.load(query, {
|
|
225
|
-
mutexObj: _this2.mutexObj,
|
|
226
|
-
mutexKey: 'query'
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
case 24:
|
|
230
|
-
_this2.resultSet = _context2.sent;
|
|
231
|
-
|
|
232
|
-
case 25:
|
|
233
|
-
_this2.loading = false;
|
|
234
|
-
_context2.next = 33;
|
|
235
|
-
break;
|
|
236
|
-
|
|
237
|
-
case 28:
|
|
238
|
-
_context2.prev = 28;
|
|
239
|
-
_context2.t0 = _context2["catch"](3);
|
|
240
|
-
_this2.error = _context2.t0;
|
|
241
|
-
_this2.resultSet = undefined;
|
|
242
|
-
_this2.loading = false;
|
|
243
|
-
|
|
244
|
-
case 33:
|
|
245
|
-
case "end":
|
|
246
|
-
return _context2.stop();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}, _callee2, null, [[3, 28]]);
|
|
250
|
-
}))();
|
|
251
|
-
},
|
|
252
|
-
loadQueries: function loadQueries() {
|
|
253
|
-
var _this3 = this;
|
|
254
|
-
|
|
255
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
256
|
-
var queries, resultPromises;
|
|
257
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
258
|
-
while (1) {
|
|
259
|
-
switch (_context3.prev = _context3.next) {
|
|
260
|
-
case 0:
|
|
261
|
-
queries = _this3.queries;
|
|
262
|
-
_context3.prev = 1;
|
|
263
|
-
_this3.error = undefined;
|
|
264
|
-
_this3.loading = true;
|
|
265
|
-
resultPromises = Promise.all(toPairs(queries).map(function (_ref) {
|
|
266
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
267
|
-
name = _ref2[0],
|
|
268
|
-
query = _ref2[1];
|
|
269
|
-
|
|
270
|
-
return _this3.cubejsApi.load(query, {
|
|
271
|
-
mutexObj: _this3.mutexObj,
|
|
272
|
-
mutexKey: name
|
|
273
|
-
}).then(function (r) {
|
|
274
|
-
return [name, r];
|
|
275
|
-
});
|
|
276
|
-
}));
|
|
277
|
-
_context3.t0 = fromPairs;
|
|
278
|
-
_context3.next = 8;
|
|
279
|
-
return resultPromises;
|
|
280
|
-
|
|
281
|
-
case 8:
|
|
282
|
-
_context3.t1 = _context3.sent;
|
|
283
|
-
_this3.resultSet = (0, _context3.t0)(_context3.t1);
|
|
284
|
-
_this3.loading = false;
|
|
285
|
-
_context3.next = 17;
|
|
286
|
-
break;
|
|
287
|
-
|
|
288
|
-
case 13:
|
|
289
|
-
_context3.prev = 13;
|
|
290
|
-
_context3.t2 = _context3["catch"](1);
|
|
291
|
-
_this3.error = _context3.t2;
|
|
292
|
-
_this3.loading = false;
|
|
293
|
-
|
|
294
|
-
case 17:
|
|
295
|
-
case "end":
|
|
296
|
-
return _context3.stop();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}, _callee3, null, [[1, 13]]);
|
|
300
|
-
}))();
|
|
104
|
+
async load() {
|
|
105
|
+
const {
|
|
106
|
+
query
|
|
107
|
+
} = this;
|
|
108
|
+
|
|
109
|
+
if (!isQueryPresent(query)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
this.loading = true;
|
|
115
|
+
this.error = null;
|
|
116
|
+
this.resultSet = null;
|
|
117
|
+
|
|
118
|
+
if (this.loadSql === 'only') {
|
|
119
|
+
this.sqlQuery = await this.cubejsApi.sql(query, {
|
|
120
|
+
mutexObj: this.mutexObj,
|
|
121
|
+
mutexKey: 'sql'
|
|
122
|
+
});
|
|
123
|
+
} else if (this.loadSql) {
|
|
124
|
+
this.sqlQuery = await this.cubejsApi.sql(query, {
|
|
125
|
+
mutexObj: this.mutexObj,
|
|
126
|
+
mutexKey: 'sql'
|
|
127
|
+
});
|
|
128
|
+
this.resultSet = await this.cubejsApi.load(query, {
|
|
129
|
+
mutexObj: this.mutexObj,
|
|
130
|
+
mutexKey: 'query'
|
|
131
|
+
});
|
|
132
|
+
} else {
|
|
133
|
+
this.resultSet = await this.cubejsApi.load(query, {
|
|
134
|
+
mutexObj: this.mutexObj,
|
|
135
|
+
mutexKey: 'query'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.loading = false;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
this.error = error;
|
|
142
|
+
this.resultSet = undefined;
|
|
143
|
+
this.loading = false;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
async loadQueries() {
|
|
148
|
+
const {
|
|
149
|
+
queries
|
|
150
|
+
} = this;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
this.error = undefined;
|
|
154
|
+
this.loading = true;
|
|
155
|
+
const resultPromises = Promise.all(toPairs(queries).map(([name, query]) => this.cubejsApi.load(query, {
|
|
156
|
+
mutexObj: this.mutexObj,
|
|
157
|
+
mutexKey: name
|
|
158
|
+
}).then(r => [name, r])));
|
|
159
|
+
this.resultSet = fromPairs(await resultPromises);
|
|
160
|
+
this.loading = false;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
this.error = error;
|
|
163
|
+
this.loading = false;
|
|
164
|
+
}
|
|
301
165
|
}
|
|
166
|
+
|
|
302
167
|
},
|
|
303
168
|
watch: {
|
|
304
|
-
loading
|
|
305
|
-
if (
|
|
169
|
+
loading(loading) {
|
|
170
|
+
if (loading === false) {
|
|
306
171
|
this.$emit('queryStatus', {
|
|
307
172
|
isLoading: false,
|
|
308
173
|
error: this.error,
|
|
@@ -314,61 +179,98 @@ var QueryRenderer = {
|
|
|
314
179
|
});
|
|
315
180
|
}
|
|
316
181
|
},
|
|
317
|
-
|
|
182
|
+
|
|
183
|
+
cubejsApi() {
|
|
318
184
|
this.load();
|
|
319
185
|
},
|
|
320
|
-
|
|
186
|
+
|
|
187
|
+
chartType() {
|
|
321
188
|
this.load();
|
|
322
189
|
},
|
|
190
|
+
|
|
323
191
|
query: {
|
|
324
192
|
deep: true,
|
|
325
|
-
|
|
193
|
+
|
|
194
|
+
handler(query, prevQuery) {
|
|
326
195
|
if (!areQueriesEqual(query, prevQuery)) {
|
|
327
196
|
this.load();
|
|
328
197
|
}
|
|
329
198
|
}
|
|
199
|
+
|
|
330
200
|
},
|
|
331
201
|
queries: {
|
|
332
|
-
handler
|
|
202
|
+
handler(val) {
|
|
333
203
|
if (val) {
|
|
334
204
|
this.loadQueries();
|
|
335
205
|
}
|
|
336
206
|
},
|
|
207
|
+
|
|
337
208
|
deep: true
|
|
338
209
|
}
|
|
339
210
|
}
|
|
340
211
|
};
|
|
341
212
|
|
|
342
|
-
|
|
213
|
+
const QUERY_ELEMENTS = ['measures', 'dimensions', 'segments', 'timeDimensions', 'filters'];
|
|
343
214
|
|
|
344
|
-
|
|
345
|
-
|
|
215
|
+
const toOrderMember = member => ({
|
|
216
|
+
id: member.name,
|
|
217
|
+
title: member.title
|
|
218
|
+
});
|
|
346
219
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
220
|
+
const reduceOrderMembers = array => array.reduce((acc, {
|
|
221
|
+
id,
|
|
222
|
+
order
|
|
223
|
+
}) => order !== 'none' ? [...acc, [id, order]] : acc, []);
|
|
224
|
+
|
|
225
|
+
const operators = ['and', 'or'];
|
|
226
|
+
|
|
227
|
+
const validateFilters = filters => filters.reduce((acc, raw) => {
|
|
228
|
+
if (raw.operator) {
|
|
229
|
+
return [...acc, raw];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const validBooleanFilter = operators.reduce((acc, operator) => {
|
|
233
|
+
const filters = raw[operator];
|
|
234
|
+
const booleanFilters = validateFilters(filters || []);
|
|
235
|
+
|
|
236
|
+
if (booleanFilters.length) {
|
|
237
|
+
return { ...acc,
|
|
238
|
+
[operator]: booleanFilters
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return acc;
|
|
243
|
+
}, {});
|
|
244
|
+
|
|
245
|
+
if (operators.some(operator => validBooleanFilter[operator])) {
|
|
246
|
+
return [...acc, validBooleanFilter];
|
|
247
|
+
}
|
|
353
248
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
249
|
+
return acc;
|
|
250
|
+
}, []);
|
|
251
|
+
|
|
252
|
+
const getDimensionOrMeasure = (meta, m) => {
|
|
253
|
+
const memberName = m.member || m.dimension;
|
|
254
|
+
return memberName && meta.resolveMember(memberName, ['dimensions', 'measures']);
|
|
360
255
|
};
|
|
361
256
|
|
|
257
|
+
const resolveMembers = (meta, arr) => arr && arr.map((e, index) => {
|
|
258
|
+
return { ...e,
|
|
259
|
+
member: getDimensionOrMeasure(meta, e),
|
|
260
|
+
index,
|
|
261
|
+
and: resolveMembers(meta, e.and),
|
|
262
|
+
or: resolveMembers(meta, e.or)
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
|
|
362
266
|
var QueryBuilder = {
|
|
363
267
|
components: {
|
|
364
|
-
QueryRenderer
|
|
268
|
+
QueryRenderer
|
|
365
269
|
},
|
|
366
270
|
props: {
|
|
367
271
|
query: {
|
|
368
272
|
type: Object,
|
|
369
|
-
|
|
370
|
-
return {};
|
|
371
|
-
}
|
|
273
|
+
default: () => ({})
|
|
372
274
|
},
|
|
373
275
|
cubejsApi: {
|
|
374
276
|
type: Object,
|
|
@@ -376,9 +278,7 @@ var QueryBuilder = {
|
|
|
376
278
|
},
|
|
377
279
|
initialChartType: {
|
|
378
280
|
type: String,
|
|
379
|
-
|
|
380
|
-
return 'line';
|
|
381
|
-
}
|
|
281
|
+
default: () => 'line'
|
|
382
282
|
},
|
|
383
283
|
disableHeuristics: {
|
|
384
284
|
type: Boolean
|
|
@@ -388,24 +288,22 @@ var QueryBuilder = {
|
|
|
388
288
|
},
|
|
389
289
|
initialVizState: {
|
|
390
290
|
type: Object,
|
|
391
|
-
|
|
392
|
-
return {};
|
|
393
|
-
}
|
|
291
|
+
default: () => ({})
|
|
394
292
|
}
|
|
395
293
|
},
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
294
|
+
|
|
295
|
+
data() {
|
|
296
|
+
const {
|
|
297
|
+
query = this.query,
|
|
298
|
+
chartType = this.initialChartType,
|
|
299
|
+
pivotConfig
|
|
300
|
+
} = this.initialVizState;
|
|
403
301
|
return {
|
|
404
302
|
initialQuery: query,
|
|
405
303
|
skipHeuristics: true,
|
|
406
304
|
meta: undefined,
|
|
407
305
|
mutex: {},
|
|
408
|
-
chartType
|
|
306
|
+
chartType,
|
|
409
307
|
measures: [],
|
|
410
308
|
dimensions: [],
|
|
411
309
|
segments: [],
|
|
@@ -424,199 +322,193 @@ var QueryBuilder = {
|
|
|
424
322
|
pivotConfig: ResultSet.getNormalizedPivotConfig(query || {}, pivotConfig)
|
|
425
323
|
};
|
|
426
324
|
},
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
325
|
+
|
|
326
|
+
render() {
|
|
327
|
+
const {
|
|
328
|
+
chartType,
|
|
329
|
+
cubejsApi,
|
|
330
|
+
dimensions,
|
|
331
|
+
filters,
|
|
332
|
+
measures,
|
|
333
|
+
meta,
|
|
334
|
+
query,
|
|
335
|
+
segments,
|
|
336
|
+
timeDimensions,
|
|
337
|
+
validatedQuery,
|
|
338
|
+
isQueryPresent,
|
|
339
|
+
availableSegments,
|
|
340
|
+
availableTimeDimensions,
|
|
341
|
+
availableDimensions,
|
|
342
|
+
availableMeasures,
|
|
343
|
+
limit,
|
|
344
|
+
offset,
|
|
345
|
+
setLimit,
|
|
346
|
+
removeLimit,
|
|
347
|
+
setOffset,
|
|
348
|
+
removeOffset,
|
|
349
|
+
renewQuery,
|
|
350
|
+
order,
|
|
351
|
+
orderMembers
|
|
352
|
+
} = this;
|
|
353
|
+
let builderProps = {};
|
|
455
354
|
|
|
456
355
|
if (meta) {
|
|
457
356
|
builderProps = {
|
|
458
|
-
query
|
|
459
|
-
validatedQuery
|
|
460
|
-
isQueryPresent
|
|
461
|
-
chartType
|
|
462
|
-
measures
|
|
463
|
-
dimensions
|
|
464
|
-
segments
|
|
465
|
-
timeDimensions
|
|
466
|
-
filters
|
|
467
|
-
availableSegments
|
|
468
|
-
availableTimeDimensions
|
|
469
|
-
availableDimensions
|
|
470
|
-
availableMeasures
|
|
357
|
+
query,
|
|
358
|
+
validatedQuery,
|
|
359
|
+
isQueryPresent,
|
|
360
|
+
chartType,
|
|
361
|
+
measures,
|
|
362
|
+
dimensions,
|
|
363
|
+
segments,
|
|
364
|
+
timeDimensions,
|
|
365
|
+
filters,
|
|
366
|
+
availableSegments,
|
|
367
|
+
availableTimeDimensions,
|
|
368
|
+
availableDimensions,
|
|
369
|
+
availableMeasures,
|
|
471
370
|
updateChartType: this.updateChart,
|
|
472
|
-
limit
|
|
473
|
-
offset
|
|
474
|
-
setLimit
|
|
475
|
-
removeLimit
|
|
476
|
-
setOffset
|
|
477
|
-
removeOffset
|
|
478
|
-
renewQuery
|
|
479
|
-
order
|
|
480
|
-
orderMembers
|
|
371
|
+
limit,
|
|
372
|
+
offset,
|
|
373
|
+
setLimit,
|
|
374
|
+
removeLimit,
|
|
375
|
+
setOffset,
|
|
376
|
+
removeOffset,
|
|
377
|
+
renewQuery,
|
|
378
|
+
order,
|
|
379
|
+
orderMembers,
|
|
481
380
|
setOrder: this.setOrder,
|
|
482
|
-
setQuery: this.setQuery,
|
|
483
381
|
pivotConfig: this.pivotConfig,
|
|
484
382
|
updateOrder: {
|
|
485
|
-
set:
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
});
|
|
490
|
-
}));
|
|
383
|
+
set: (memberId, newOrder) => {
|
|
384
|
+
this.order = reduceOrderMembers(orderMembers.map(orderMember => ({ ...orderMember,
|
|
385
|
+
order: orderMember.id === memberId ? newOrder : orderMember.order
|
|
386
|
+
})));
|
|
491
387
|
},
|
|
492
|
-
update:
|
|
493
|
-
|
|
388
|
+
update: newOrder => {
|
|
389
|
+
this.order = newOrder;
|
|
494
390
|
},
|
|
495
|
-
reorder:
|
|
496
|
-
|
|
391
|
+
reorder: (sourceIndex, destinationIndex) => {
|
|
392
|
+
this.order = reduceOrderMembers(moveItemInArray(orderMembers, sourceIndex, destinationIndex));
|
|
497
393
|
}
|
|
498
394
|
},
|
|
499
395
|
updatePivotConfig: {
|
|
500
|
-
moveItem:
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
396
|
+
moveItem: ({
|
|
397
|
+
sourceIndex,
|
|
398
|
+
destinationIndex,
|
|
399
|
+
sourceAxis,
|
|
400
|
+
destinationAxis
|
|
401
|
+
}) => {
|
|
402
|
+
this.pivotConfig = movePivotItem(this.pivotConfig, sourceIndex, destinationIndex, sourceAxis, destinationAxis);
|
|
506
403
|
},
|
|
507
|
-
update:
|
|
508
|
-
|
|
509
|
-
x: pivotConfig.x ||
|
|
510
|
-
y: pivotConfig.y ||
|
|
404
|
+
update: pivotConfig => {
|
|
405
|
+
this.pivotConfig = {
|
|
406
|
+
x: pivotConfig.x || this.pivotConfig.x,
|
|
407
|
+
y: pivotConfig.y || this.pivotConfig.y
|
|
511
408
|
};
|
|
512
409
|
}
|
|
513
410
|
}
|
|
514
411
|
};
|
|
515
|
-
QUERY_ELEMENTS.forEach(
|
|
516
|
-
|
|
412
|
+
QUERY_ELEMENTS.forEach(elementName => {
|
|
413
|
+
const name = elementName.charAt(0).toUpperCase() + elementName.slice(1);
|
|
517
414
|
|
|
518
|
-
builderProps[
|
|
519
|
-
|
|
415
|
+
builderProps[`add${name}`] = member => {
|
|
416
|
+
this.addMember(elementName, member);
|
|
520
417
|
};
|
|
521
418
|
|
|
522
|
-
builderProps[
|
|
523
|
-
|
|
419
|
+
builderProps[`update${name}`] = (member, updateWith) => {
|
|
420
|
+
this.updateMember(elementName, member, updateWith);
|
|
524
421
|
};
|
|
525
422
|
|
|
526
|
-
builderProps[
|
|
527
|
-
|
|
423
|
+
builderProps[`remove${name}`] = member => {
|
|
424
|
+
this.removeMember(elementName, member);
|
|
528
425
|
};
|
|
529
426
|
|
|
530
|
-
builderProps[
|
|
531
|
-
|
|
427
|
+
builderProps[`set${name}`] = members => {
|
|
428
|
+
this.setMembers(elementName, members);
|
|
532
429
|
};
|
|
533
430
|
});
|
|
534
431
|
}
|
|
535
432
|
|
|
536
433
|
return h(QueryRenderer, {
|
|
537
434
|
query: this.validatedQuery,
|
|
538
|
-
cubejsApi
|
|
539
|
-
builderProps
|
|
435
|
+
cubejsApi,
|
|
436
|
+
builderProps,
|
|
540
437
|
slots: this.$slots,
|
|
541
438
|
on: {
|
|
542
|
-
queryStatus:
|
|
543
|
-
|
|
439
|
+
queryStatus: event => {
|
|
440
|
+
this.$emit('queryStatus', event);
|
|
544
441
|
}
|
|
545
442
|
}
|
|
546
443
|
}, this.$slots);
|
|
547
444
|
},
|
|
445
|
+
|
|
548
446
|
computed: {
|
|
549
|
-
isQueryPresent
|
|
550
|
-
|
|
447
|
+
isQueryPresent() {
|
|
448
|
+
const {
|
|
449
|
+
validatedQuery
|
|
450
|
+
} = this;
|
|
551
451
|
return isQueryPresent(validatedQuery);
|
|
552
452
|
},
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}))).map(
|
|
558
|
-
|
|
453
|
+
|
|
454
|
+
orderMembers() {
|
|
455
|
+
return getOrderMembersFromOrder([...this.measures, ...this.dimensions, ...this.timeDimensions.map(({
|
|
456
|
+
dimension
|
|
457
|
+
}) => toOrderMember(dimension))].map((member, index) => {
|
|
458
|
+
const id = member.name || member.id;
|
|
559
459
|
|
|
560
460
|
if (!id) {
|
|
561
461
|
return false;
|
|
562
462
|
}
|
|
563
463
|
|
|
564
464
|
return {
|
|
565
|
-
index
|
|
566
|
-
id
|
|
465
|
+
index,
|
|
466
|
+
id,
|
|
567
467
|
title: member.title
|
|
568
468
|
};
|
|
569
469
|
}).filter(Boolean), this.order);
|
|
570
470
|
},
|
|
571
|
-
|
|
471
|
+
|
|
472
|
+
vizState() {
|
|
572
473
|
return {
|
|
573
474
|
query: this.validatedQuery,
|
|
574
475
|
chartType: this.chartType,
|
|
575
476
|
pivotConfig: this.pivotConfig
|
|
576
477
|
};
|
|
577
478
|
},
|
|
578
|
-
validatedQuery: function validatedQuery() {
|
|
579
|
-
var _this2 = this;
|
|
580
479
|
|
|
581
|
-
|
|
480
|
+
validatedQuery() {
|
|
481
|
+
let validatedQuery = {};
|
|
582
482
|
|
|
583
|
-
|
|
584
|
-
return member.name;
|
|
585
|
-
}; // TODO: implement timezone
|
|
483
|
+
let toQuery = member => member.name; // TODO: implement timezone
|
|
586
484
|
|
|
587
485
|
|
|
588
|
-
|
|
589
|
-
QUERY_ELEMENTS.forEach(
|
|
486
|
+
let hasElements = false;
|
|
487
|
+
QUERY_ELEMENTS.forEach(element => {
|
|
590
488
|
if (element === 'timeDimensions') {
|
|
591
|
-
toQuery =
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
};
|
|
597
|
-
};
|
|
489
|
+
toQuery = member => ({
|
|
490
|
+
dimension: member.dimension.name,
|
|
491
|
+
granularity: member.granularity,
|
|
492
|
+
dateRange: member.dateRange
|
|
493
|
+
});
|
|
598
494
|
} else if (element === 'filters') {
|
|
599
|
-
toQuery =
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
};
|
|
495
|
+
toQuery = member => ({
|
|
496
|
+
member: member.member && member.member.name,
|
|
497
|
+
operator: member.operator,
|
|
498
|
+
values: member.values,
|
|
499
|
+
and: member.and && member.and.map(toQuery),
|
|
500
|
+
or: member.or && member.or.map(toQuery)
|
|
501
|
+
});
|
|
606
502
|
}
|
|
607
503
|
|
|
608
|
-
if (
|
|
609
|
-
validatedQuery[element] =
|
|
610
|
-
return toQuery(x);
|
|
611
|
-
});
|
|
504
|
+
if (this[element].length > 0) {
|
|
505
|
+
validatedQuery[element] = this[element].map(x => toQuery(x));
|
|
612
506
|
hasElements = true;
|
|
613
507
|
}
|
|
614
508
|
});
|
|
615
509
|
|
|
616
510
|
if (validatedQuery.filters) {
|
|
617
|
-
validatedQuery.filters = validatedQuery.filters
|
|
618
|
-
return f.operator;
|
|
619
|
-
});
|
|
511
|
+
validatedQuery.filters = validateFilters(validatedQuery.filters);
|
|
620
512
|
} // only set limit and offset if there are elements otherwise an invalid request with just limit/offset
|
|
621
513
|
// gets sent when the component is first mounted, but before the actual query is constructed.
|
|
622
514
|
|
|
@@ -640,25 +532,25 @@ var QueryBuilder = {
|
|
|
640
532
|
}
|
|
641
533
|
|
|
642
534
|
if (!this.skipHeuristics && !this.disableHeuristics && isQueryPresent(validatedQuery) && this.meta) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
535
|
+
const heuristicsFn = this.stateChangeHeuristics || defaultHeuristics;
|
|
536
|
+
const {
|
|
537
|
+
query,
|
|
538
|
+
chartType,
|
|
539
|
+
shouldApplyHeuristicOrder,
|
|
540
|
+
pivotConfig
|
|
541
|
+
} = heuristicsFn({
|
|
648
542
|
query: validatedQuery,
|
|
649
543
|
chartType: this.chartType
|
|
650
544
|
}, this.prevValidatedQuery, {
|
|
651
545
|
meta: this.meta,
|
|
652
|
-
sessionGranularity:
|
|
653
|
-
})
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
order: defaultOrder(query)
|
|
661
|
-
} : null);
|
|
546
|
+
sessionGranularity: validatedQuery?.timeDimensions?.[0]?.granularity
|
|
547
|
+
});
|
|
548
|
+
validatedQuery = { ...validatedQuery,
|
|
549
|
+
...query,
|
|
550
|
+
...(shouldApplyHeuristicOrder ? {
|
|
551
|
+
order: defaultOrder(query)
|
|
552
|
+
} : null)
|
|
553
|
+
};
|
|
662
554
|
this.chartType = chartType || this.chartType;
|
|
663
555
|
this.pivotConfig = ResultSet.getNormalizedPivotConfig(validatedQuery, pivotConfig || this.pivotConfig);
|
|
664
556
|
this.copyQueryFromProps(validatedQuery);
|
|
@@ -672,247 +564,186 @@ var QueryBuilder = {
|
|
|
672
564
|
this.prevValidatedQuery = validatedQuery;
|
|
673
565
|
return validatedQuery;
|
|
674
566
|
}
|
|
567
|
+
|
|
675
568
|
},
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
_context.next = 2;
|
|
686
|
-
return _this3.cubejsApi.meta();
|
|
687
|
-
|
|
688
|
-
case 2:
|
|
689
|
-
_this3.meta = _context.sent;
|
|
690
|
-
|
|
691
|
-
_this3.copyQueryFromProps();
|
|
692
|
-
|
|
693
|
-
if (!isQueryPresent(_this3.initialQuery)) {
|
|
694
|
-
_context.next = 9;
|
|
695
|
-
break;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
_context.next = 7;
|
|
699
|
-
return _this3.cubejsApi.dryRun(_this3.initialQuery);
|
|
700
|
-
|
|
701
|
-
case 7:
|
|
702
|
-
dryRunResponse = _context.sent;
|
|
703
|
-
_this3.pivotConfig = ResultSet.getNormalizedPivotConfig((dryRunResponse === null || dryRunResponse === void 0 ? void 0 : dryRunResponse.pivotQuery) || {}, _this3.pivotConfig);
|
|
704
|
-
|
|
705
|
-
case 9:
|
|
706
|
-
case "end":
|
|
707
|
-
return _context.stop();
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}, _callee);
|
|
711
|
-
}))();
|
|
569
|
+
|
|
570
|
+
async mounted() {
|
|
571
|
+
this.meta = await this.cubejsApi.meta();
|
|
572
|
+
this.copyQueryFromProps();
|
|
573
|
+
|
|
574
|
+
if (isQueryPresent(this.initialQuery)) {
|
|
575
|
+
const dryRunResponse = await this.cubejsApi.dryRun(this.initialQuery);
|
|
576
|
+
this.pivotConfig = ResultSet.getNormalizedPivotConfig(dryRunResponse?.pivotQuery || {}, this.pivotConfig);
|
|
577
|
+
}
|
|
712
578
|
},
|
|
579
|
+
|
|
713
580
|
methods: {
|
|
714
|
-
copyQueryFromProps
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
});
|
|
738
|
-
this.
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
},
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
});
|
|
755
|
-
});
|
|
756
|
-
this.filters = filters.map(function (m, index) {
|
|
757
|
-
return _objectSpread(_objectSpread({}, m), {}, {
|
|
758
|
-
member: _this4.meta.resolveMember(m.member || m.dimension, ['dimensions', 'measures']),
|
|
759
|
-
operators: _this4.meta.filterOperatorsForMember(m.member || m.dimension, ['dimensions', 'measures']),
|
|
760
|
-
index: index
|
|
761
|
-
});
|
|
581
|
+
copyQueryFromProps(query) {
|
|
582
|
+
const {
|
|
583
|
+
measures = [],
|
|
584
|
+
dimensions = [],
|
|
585
|
+
segments = [],
|
|
586
|
+
timeDimensions = [],
|
|
587
|
+
filters = [],
|
|
588
|
+
limit,
|
|
589
|
+
offset,
|
|
590
|
+
renewQuery,
|
|
591
|
+
order
|
|
592
|
+
} = query || this.initialQuery;
|
|
593
|
+
this.measures = measures.map((m, index) => ({
|
|
594
|
+
index,
|
|
595
|
+
...this.meta.resolveMember(m, 'measures')
|
|
596
|
+
}));
|
|
597
|
+
this.dimensions = dimensions.map((m, index) => ({
|
|
598
|
+
index,
|
|
599
|
+
...this.meta.resolveMember(m, 'dimensions')
|
|
600
|
+
}));
|
|
601
|
+
this.segments = segments.map((m, index) => ({
|
|
602
|
+
index,
|
|
603
|
+
...this.meta.resolveMember(m, 'segments')
|
|
604
|
+
}));
|
|
605
|
+
this.timeDimensions = timeDimensions.map((m, index) => ({ ...m,
|
|
606
|
+
dimension: { ...this.meta.resolveMember(m.dimension, 'dimensions'),
|
|
607
|
+
granularities: this.granularities
|
|
608
|
+
},
|
|
609
|
+
index
|
|
610
|
+
}));
|
|
611
|
+
const memberTypes = ['dimensions', 'measures'];
|
|
612
|
+
this.filters = filters.map((m, index) => {
|
|
613
|
+
const memberName = m.member || m.dimension;
|
|
614
|
+
return { ...m,
|
|
615
|
+
member: memberName && this.meta.resolveMember(memberName, memberTypes),
|
|
616
|
+
operators: memberName && this.meta.filterOperatorsForMember(memberName, memberTypes),
|
|
617
|
+
and: resolveMembers(this.meta, m.and),
|
|
618
|
+
or: resolveMembers(this.meta, m.or),
|
|
619
|
+
index
|
|
620
|
+
};
|
|
762
621
|
});
|
|
763
622
|
this.availableMeasures = this.meta.membersForQuery({}, 'measures') || [];
|
|
764
623
|
this.availableDimensions = this.meta.membersForQuery({}, 'dimensions') || [];
|
|
765
|
-
this.availableTimeDimensions = (this.meta.membersForQuery({}, 'dimensions') || []).filter(
|
|
766
|
-
return m.type === 'time';
|
|
767
|
-
});
|
|
624
|
+
this.availableTimeDimensions = (this.meta.membersForQuery({}, 'dimensions') || []).filter(m => m.type === 'time');
|
|
768
625
|
this.availableSegments = this.meta.membersForQuery({}, 'segments') || [];
|
|
769
626
|
this.limit = limit || 10000;
|
|
770
627
|
this.offset = offset || null;
|
|
771
628
|
this.renewQuery = renewQuery || false;
|
|
772
629
|
this.order = order || null;
|
|
773
630
|
},
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
631
|
+
|
|
632
|
+
addMember(element, member) {
|
|
633
|
+
const name = element.charAt(0).toUpperCase() + element.slice(1);
|
|
634
|
+
let mem;
|
|
777
635
|
|
|
778
636
|
if (element === 'timeDimensions') {
|
|
779
|
-
mem = this[
|
|
780
|
-
return m.name === member.dimension;
|
|
781
|
-
});
|
|
637
|
+
mem = this[`available${name}`].find(m => m.name === member.dimension);
|
|
782
638
|
|
|
783
639
|
if (mem) {
|
|
784
|
-
|
|
640
|
+
const dimension = { ...this.meta.resolveMember(mem.name, 'dimensions'),
|
|
785
641
|
granularities: this.granularities
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
mem = _objectSpread(_objectSpread({}, mem), {}, {
|
|
642
|
+
};
|
|
643
|
+
mem = { ...mem,
|
|
789
644
|
granularity: member.granularity,
|
|
790
645
|
dateRange: member.dateRange,
|
|
791
|
-
dimension
|
|
646
|
+
dimension,
|
|
792
647
|
index: this[element].length
|
|
793
|
-
}
|
|
648
|
+
};
|
|
794
649
|
}
|
|
795
650
|
} else if (element === 'filters') {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
member:
|
|
800
|
-
}
|
|
651
|
+
mem = { ...member,
|
|
652
|
+
and: resolveMembers(this.meta, member.and),
|
|
653
|
+
or: resolveMembers(this.meta, member.or),
|
|
654
|
+
member: getDimensionOrMeasure(this.meta, member)
|
|
655
|
+
};
|
|
801
656
|
} else {
|
|
802
|
-
mem = this[
|
|
803
|
-
return m.name === member;
|
|
804
|
-
});
|
|
657
|
+
mem = this[`available${name}`].find(m => m.name === member);
|
|
805
658
|
}
|
|
806
659
|
|
|
807
660
|
if (mem) {
|
|
808
661
|
this[element].push(mem);
|
|
809
662
|
}
|
|
810
663
|
},
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
664
|
+
|
|
665
|
+
removeMember(element, member) {
|
|
666
|
+
const name = element.charAt(0).toUpperCase() + element.slice(1);
|
|
667
|
+
let mem;
|
|
814
668
|
|
|
815
669
|
if (element === 'timeDimensions') {
|
|
816
|
-
mem = this[
|
|
817
|
-
return x.name === member;
|
|
818
|
-
});
|
|
670
|
+
mem = this[`available${name}`].find(x => x.name === member);
|
|
819
671
|
} else if (element === 'filters') {
|
|
820
672
|
mem = member;
|
|
821
673
|
} else {
|
|
822
|
-
mem = this[
|
|
823
|
-
return m.name === member;
|
|
824
|
-
});
|
|
674
|
+
mem = this[`available${name}`].find(m => m.name === member);
|
|
825
675
|
}
|
|
826
676
|
|
|
827
677
|
if (mem) {
|
|
828
|
-
|
|
829
|
-
return x.name === mem;
|
|
830
|
-
});
|
|
678
|
+
const index = this[element].findIndex(x => x.name === mem);
|
|
831
679
|
this[element].splice(index, 1);
|
|
832
680
|
}
|
|
833
681
|
},
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
682
|
+
|
|
683
|
+
updateMember(element, old, member) {
|
|
684
|
+
const name = element.charAt(0).toUpperCase() + element.slice(1);
|
|
685
|
+
let mem;
|
|
686
|
+
let index;
|
|
838
687
|
|
|
839
688
|
if (element === 'timeDimensions') {
|
|
840
|
-
index = this[element].findIndex(
|
|
841
|
-
|
|
842
|
-
});
|
|
843
|
-
mem = this["available".concat(name)].find(function (m) {
|
|
844
|
-
return m.name === member.dimension;
|
|
845
|
-
});
|
|
689
|
+
index = this[element].findIndex(x => x.dimension.name === old.dimension);
|
|
690
|
+
mem = this[`available${name}`].find(m => m.name === member.dimension);
|
|
846
691
|
|
|
847
692
|
if (mem) {
|
|
848
|
-
|
|
693
|
+
const dimension = { ...this.meta.resolveMember(mem.name, 'dimensions'),
|
|
849
694
|
granularities: this.granularities
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
dimension: dimension,
|
|
695
|
+
};
|
|
696
|
+
mem = { ...mem,
|
|
697
|
+
dimension,
|
|
854
698
|
granularity: member.granularity,
|
|
855
699
|
dateRange: member.dateRange,
|
|
856
|
-
index
|
|
857
|
-
}
|
|
700
|
+
index
|
|
701
|
+
};
|
|
858
702
|
}
|
|
859
703
|
} else if (element === 'filters') {
|
|
860
|
-
index = this[element].findIndex(
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
mem = _objectSpread(_objectSpread({}, member), {}, {
|
|
867
|
-
member: filterMember
|
|
868
|
-
});
|
|
704
|
+
index = this[element].findIndex(x => x.dimension === old);
|
|
705
|
+
mem = { ...member,
|
|
706
|
+
and: resolveMembers(this.meta, member.and),
|
|
707
|
+
or: resolveMembers(this.meta, member.or),
|
|
708
|
+
member: getDimensionOrMeasure(this.meta, member)
|
|
709
|
+
};
|
|
869
710
|
} else {
|
|
870
|
-
index = this[element].findIndex(
|
|
871
|
-
|
|
872
|
-
});
|
|
873
|
-
mem = this["available".concat(name)].find(function (m) {
|
|
874
|
-
return m.name === member;
|
|
875
|
-
});
|
|
711
|
+
index = this[element].findIndex(x => x.name === old);
|
|
712
|
+
mem = this[`available${name}`].find(m => m.name === member);
|
|
876
713
|
}
|
|
877
714
|
|
|
878
715
|
if (mem) {
|
|
879
716
|
this[element].splice(index, 1, mem);
|
|
880
717
|
}
|
|
881
718
|
},
|
|
882
|
-
setMembers: function setMembers(element, members) {
|
|
883
|
-
var _this5 = this;
|
|
884
719
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
720
|
+
setMembers(element, members) {
|
|
721
|
+
const name = element.charAt(0).toUpperCase() + element.slice(1);
|
|
722
|
+
let mem;
|
|
723
|
+
const elements = [];
|
|
724
|
+
members.filter(Boolean).forEach(m => {
|
|
889
725
|
if (element === 'timeDimensions') {
|
|
890
|
-
mem =
|
|
891
|
-
return x.name === m.dimension;
|
|
892
|
-
});
|
|
726
|
+
mem = this[`available${name}`].find(x => x.name === m.dimension);
|
|
893
727
|
|
|
894
728
|
if (mem) {
|
|
895
|
-
|
|
896
|
-
granularities:
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
mem = _objectSpread(_objectSpread({}, mem), {}, {
|
|
729
|
+
const dimension = { ...this.meta.resolveMember(mem.name, 'dimensions'),
|
|
730
|
+
granularities: this.granularities
|
|
731
|
+
};
|
|
732
|
+
mem = { ...mem,
|
|
900
733
|
granularity: m.granularity,
|
|
901
734
|
dateRange: m.dateRange,
|
|
902
|
-
dimension
|
|
903
|
-
index:
|
|
904
|
-
}
|
|
735
|
+
dimension,
|
|
736
|
+
index: this[element].length
|
|
737
|
+
};
|
|
905
738
|
}
|
|
906
739
|
} else if (element === 'filters') {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
member:
|
|
911
|
-
}
|
|
740
|
+
mem = { ...m,
|
|
741
|
+
and: resolveMembers(this.meta, m.and),
|
|
742
|
+
or: resolveMembers(this.meta, m.or),
|
|
743
|
+
member: getDimensionOrMeasure(this.meta, m)
|
|
744
|
+
};
|
|
912
745
|
} else {
|
|
913
|
-
mem =
|
|
914
|
-
return x.name === m;
|
|
915
|
-
});
|
|
746
|
+
mem = this[`available${name}`].find(x => x.name === m);
|
|
916
747
|
}
|
|
917
748
|
|
|
918
749
|
if (mem) {
|
|
@@ -921,62 +752,71 @@ var QueryBuilder = {
|
|
|
921
752
|
});
|
|
922
753
|
this[element] = elements;
|
|
923
754
|
},
|
|
924
|
-
|
|
755
|
+
|
|
756
|
+
setLimit(limit) {
|
|
925
757
|
this.limit = limit;
|
|
926
758
|
},
|
|
927
|
-
|
|
759
|
+
|
|
760
|
+
removeLimit() {
|
|
928
761
|
this.limit = null;
|
|
929
762
|
},
|
|
930
|
-
|
|
763
|
+
|
|
764
|
+
setOffset(offset) {
|
|
931
765
|
this.offset = offset;
|
|
932
766
|
},
|
|
933
|
-
|
|
767
|
+
|
|
768
|
+
removeOffset() {
|
|
934
769
|
this.offset = null;
|
|
935
770
|
},
|
|
936
|
-
|
|
771
|
+
|
|
772
|
+
updateChart(chartType) {
|
|
937
773
|
this.chartType = chartType;
|
|
938
774
|
},
|
|
939
|
-
|
|
940
|
-
|
|
775
|
+
|
|
776
|
+
setOrder(order = {}) {
|
|
941
777
|
this.order = order;
|
|
942
778
|
},
|
|
943
|
-
|
|
944
|
-
|
|
779
|
+
|
|
780
|
+
emitVizStateChange(partialVizState) {
|
|
781
|
+
this.$emit('vizStateChange', clone({ ...this.vizState,
|
|
782
|
+
...partialVizState
|
|
783
|
+
}));
|
|
945
784
|
}
|
|
785
|
+
|
|
946
786
|
},
|
|
947
787
|
watch: {
|
|
948
788
|
validatedQuery: {
|
|
949
789
|
deep: true,
|
|
950
|
-
handler: function handler(query, prevQuery) {
|
|
951
|
-
var _this6 = this;
|
|
952
790
|
|
|
953
|
-
|
|
791
|
+
handler(query, prevQuery) {
|
|
792
|
+
const hasQueryChanged = !areQueriesEqual(query, prevQuery);
|
|
954
793
|
|
|
955
794
|
if (hasQueryChanged) {
|
|
956
795
|
this.emitVizStateChange({
|
|
957
|
-
query
|
|
796
|
+
query
|
|
958
797
|
});
|
|
959
798
|
}
|
|
960
799
|
|
|
961
800
|
if (isQueryPresent(query) && hasQueryChanged) {
|
|
962
801
|
this.cubejsApi.dryRun(query, {
|
|
963
802
|
mutexObj: this.mutex
|
|
964
|
-
}).then(
|
|
965
|
-
|
|
966
|
-
|
|
803
|
+
}).then(({
|
|
804
|
+
pivotQuery
|
|
805
|
+
}) => {
|
|
806
|
+
const pivotConfig = ResultSet.getNormalizedPivotConfig(pivotQuery, this.pivotConfig);
|
|
967
807
|
|
|
968
|
-
if (!equals(pivotConfig,
|
|
969
|
-
|
|
808
|
+
if (!equals(pivotConfig, this.pivotConfig)) {
|
|
809
|
+
this.pivotConfig = pivotConfig;
|
|
970
810
|
}
|
|
971
|
-
})
|
|
972
|
-
return console.error(error);
|
|
973
|
-
});
|
|
811
|
+
}).catch(error => console.error(error));
|
|
974
812
|
}
|
|
975
813
|
}
|
|
814
|
+
|
|
976
815
|
},
|
|
977
816
|
query: {
|
|
978
817
|
deep: true,
|
|
979
|
-
|
|
818
|
+
|
|
819
|
+
handler(query) {
|
|
980
820
|
if (!this.meta) {
|
|
981
821
|
// this is ok as if meta has not been loaded by the time query prop has changed,
|
|
982
822
|
// then the promise for loading meta (found in mounted()) will call
|
|
@@ -986,22 +826,27 @@ var QueryBuilder = {
|
|
|
986
826
|
|
|
987
827
|
this.copyQueryFromProps(query);
|
|
988
828
|
}
|
|
829
|
+
|
|
989
830
|
},
|
|
990
831
|
pivotConfig: {
|
|
991
832
|
deep: true,
|
|
992
|
-
|
|
833
|
+
|
|
834
|
+
handler(pivotConfig, prevPivotConfig) {
|
|
993
835
|
if (!equals(pivotConfig, prevPivotConfig)) {
|
|
994
836
|
this.emitVizStateChange({
|
|
995
|
-
pivotConfig
|
|
837
|
+
pivotConfig
|
|
996
838
|
});
|
|
997
839
|
}
|
|
998
840
|
}
|
|
841
|
+
|
|
999
842
|
},
|
|
1000
|
-
|
|
843
|
+
|
|
844
|
+
chartType(value) {
|
|
1001
845
|
this.emitVizStateChange({
|
|
1002
846
|
chartType: value
|
|
1003
847
|
});
|
|
1004
848
|
}
|
|
849
|
+
|
|
1005
850
|
}
|
|
1006
851
|
};
|
|
1007
852
|
|