@nocobase/plugin-data-visualization 0.11.1-alpha.5 → 0.12.0-alpha.2
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/client.d.ts +2 -2
- package/client.js +1 -1
- package/dist/client/chart/antd/antd.d.ts +7 -0
- package/dist/client/chart/antd/index.d.ts +4 -0
- package/dist/client/chart/antd/statistic.d.ts +19 -0
- package/dist/client/chart/antd/table.d.ts +6 -0
- package/dist/client/chart/chart.d.ts +65 -0
- package/dist/client/chart/g2plot/bar.d.ts +16 -0
- package/dist/client/chart/g2plot/dualAxes.d.ts +20 -0
- package/dist/client/chart/g2plot/g2plot.d.ts +19 -0
- package/dist/client/chart/g2plot/index.d.ts +6 -0
- package/dist/client/chart/g2plot/pie.d.ts +17 -0
- package/dist/client/chart/library.d.ts +28 -0
- package/{lib → dist}/client/hooks.d.ts +22 -154
- package/{lib → dist}/client/index.d.ts +3 -1
- package/dist/client/index.js +67448 -0
- package/{lib → dist}/client/renderer/ChartRendererProvider.d.ts +1 -8
- package/{lib → dist}/client/renderer/index.d.ts +0 -2
- package/{lib → dist}/client/utils.d.ts +1 -1
- package/{lib → dist}/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/locale/en-US.js +26 -0
- package/dist/locale/fr-FR.js +5 -0
- package/dist/locale/ja-JP.js +5 -0
- package/dist/locale/pt-BR.js +26 -0
- package/dist/locale/ru-RU.js +5 -0
- package/dist/locale/tr-TR.js +5 -0
- package/dist/locale/zh-CN.js +74 -0
- package/dist/server/actions/formatter.js +41 -0
- package/{src/server/actions/query.ts → dist/server/actions/query.js} +75 -133
- package/dist/server/index.js +11 -0
- package/dist/server/plugin.js +42 -0
- package/package.json +23 -22
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/lib/client/Settings.js +0 -81
- package/lib/client/block/ChartBlock.js +0 -74
- package/lib/client/block/ChartBlockDesigner.js +0 -35
- package/lib/client/block/ChartBlockInitializer.js +0 -114
- package/lib/client/block/ChartConfigure.js +0 -499
- package/lib/client/block/formatters.js +0 -58
- package/lib/client/block/index.js +0 -49
- package/lib/client/block/schemas/configure.js +0 -517
- package/lib/client/block/transformers.js +0 -68
- package/lib/client/hooks.js +0 -275
- package/lib/client/index.js +0 -80
- package/lib/client/locale/index.js +0 -37
- package/lib/client/renderer/ChartLibrary.d.ts +0 -72
- package/lib/client/renderer/ChartLibrary.js +0 -146
- package/lib/client/renderer/ChartRenderer.js +0 -181
- package/lib/client/renderer/ChartRendererProvider.js +0 -105
- package/lib/client/renderer/index.js +0 -49
- package/lib/client/renderer/library/AntdLibrary.d.ts +0 -2
- package/lib/client/renderer/library/AntdLibrary.js +0 -123
- package/lib/client/renderer/library/G2PlotLibrary.d.ts +0 -2
- package/lib/client/renderer/library/G2PlotLibrary.js +0 -288
- package/lib/client/renderer/library/index.d.ts +0 -3
- package/lib/client/renderer/library/index.js +0 -15
- package/lib/client/utils.js +0 -137
- package/lib/index.js +0 -13
- package/lib/locale/en-US.js +0 -29
- package/lib/locale/fr-FR.js +0 -8
- package/lib/locale/ja-JP.js +0 -8
- package/lib/locale/pt-BR.js +0 -29
- package/lib/locale/ru-RU.js +0 -8
- package/lib/locale/tr-TR.js +0 -8
- package/lib/locale/zh-CN.js +0 -77
- package/lib/server/actions/formatter.js +0 -44
- package/lib/server/actions/query.js +0 -331
- package/lib/server/index.js +0 -13
- package/lib/server/plugin.js +0 -64
- package/src/client/Settings.tsx +0 -43
- package/src/client/__tests__/chart-configure.test.tsx +0 -14
- package/src/client/__tests__/chart-library.test.ts +0 -78
- package/src/client/__tests__/chart-renderer.test.tsx +0 -30
- package/src/client/__tests__/hooks.test.ts +0 -261
- package/src/client/block/ChartBlock.tsx +0 -24
- package/src/client/block/ChartBlockDesigner.tsx +0 -19
- package/src/client/block/ChartBlockInitializer.tsx +0 -82
- package/src/client/block/ChartConfigure.tsx +0 -446
- package/src/client/block/formatters.ts +0 -70
- package/src/client/block/index.ts +0 -4
- package/src/client/block/schemas/configure.ts +0 -504
- package/src/client/block/transformers.ts +0 -52
- package/src/client/hooks.ts +0 -239
- package/src/client/index.tsx +0 -47
- package/src/client/locale/index.ts +0 -18
- package/src/client/renderer/ChartLibrary.tsx +0 -183
- package/src/client/renderer/ChartRenderer.tsx +0 -129
- package/src/client/renderer/ChartRendererProvider.tsx +0 -123
- package/src/client/renderer/index.ts +0 -4
- package/src/client/renderer/library/AntdLibrary.tsx +0 -94
- package/src/client/renderer/library/G2PlotLibrary.tsx +0 -236
- package/src/client/renderer/library/index.tsx +0 -4
- package/src/client/utils.ts +0 -102
- package/src/index.ts +0 -1
- package/src/locale/en-US.ts +0 -23
- package/src/locale/fr-FR.ts +0 -1
- package/src/locale/ja-JP.ts +0 -1
- package/src/locale/pt-BR.ts +0 -23
- package/src/locale/ru-RU.ts +0 -1
- package/src/locale/tr-TR.ts +0 -1
- package/src/locale/zh-CN.ts +0 -72
- package/src/server/__tests__/api.test.ts +0 -102
- package/src/server/__tests__/formatter.test.ts +0 -49
- package/src/server/__tests__/query.test.ts +0 -220
- package/src/server/actions/formatter.ts +0 -49
- package/src/server/collections/.gitkeep +0 -0
- package/src/server/index.ts +0 -1
- package/src/server/plugin.ts +0 -37
- /package/{lib → dist}/client/Settings.d.ts +0 -0
- /package/{lib → dist}/client/block/ChartBlock.d.ts +0 -0
- /package/{lib → dist}/client/block/ChartBlockDesigner.d.ts +0 -0
- /package/{lib → dist}/client/block/ChartBlockInitializer.d.ts +0 -0
- /package/{lib → dist}/client/block/ChartConfigure.d.ts +0 -0
- /package/{lib → dist}/client/block/formatters.d.ts +0 -0
- /package/{lib → dist}/client/block/index.d.ts +0 -0
- /package/{lib → dist}/client/block/schemas/configure.d.ts +0 -0
- /package/{lib → dist}/client/block/transformers.d.ts +0 -0
- /package/{lib → dist}/client/locale/index.d.ts +0 -0
- /package/{lib → dist}/client/renderer/ChartRenderer.d.ts +0 -0
- /package/{lib → dist}/locale/en-US.d.ts +0 -0
- /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
- /package/{lib → dist}/locale/ja-JP.d.ts +0 -0
- /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
- /package/{lib → dist}/locale/ru-RU.d.ts +0 -0
- /package/{lib → dist}/locale/tr-TR.d.ts +0 -0
- /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/actions/formatter.d.ts +0 -0
- /package/{lib → dist}/server/actions/query.d.ts +0 -0
- /package/{lib → dist}/server/index.d.ts +0 -0
- /package/{lib → dist}/server/plugin.d.ts +0 -0
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.queryData = exports.query = exports.processData = exports.parseFieldAndAssociations = exports.parseBuilder = exports.cacheWrap = void 0;
|
|
7
|
-
function _database() {
|
|
8
|
-
const data = require("@nocobase/database");
|
|
9
|
-
_database = function _database() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
var _formatter = require("./formatter");
|
|
15
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
16
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
17
|
-
function ownKeys(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; }
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
21
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
22
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
26
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
27
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
-
const parseFieldAndAssociations = (ctx, params) => {
|
|
29
|
-
const collectionName = params.collection,
|
|
30
|
-
measures = params.measures,
|
|
31
|
-
dimensions = params.dimensions,
|
|
32
|
-
orders = params.orders,
|
|
33
|
-
filter = params.filter;
|
|
34
|
-
const collection = ctx.db.getCollection(collectionName);
|
|
35
|
-
const fields = collection.fields;
|
|
36
|
-
const underscored = ctx.db.options.underscored;
|
|
37
|
-
const models = {};
|
|
38
|
-
const parseField = selected => {
|
|
39
|
-
var _fields$get;
|
|
40
|
-
let target;
|
|
41
|
-
let name;
|
|
42
|
-
if (!Array.isArray(selected.field)) {
|
|
43
|
-
name = selected.field;
|
|
44
|
-
} else if (selected.field.length === 1) {
|
|
45
|
-
name = selected.field[0];
|
|
46
|
-
} else if (selected.field.length > 1) {
|
|
47
|
-
var _selected$field = _slicedToArray(selected.field, 2);
|
|
48
|
-
target = _selected$field[0];
|
|
49
|
-
name = _selected$field[1];
|
|
50
|
-
}
|
|
51
|
-
let field = underscored ? (0, _database().snakeCase)(name) : name;
|
|
52
|
-
let fieldType = (_fields$get = fields.get(name)) === null || _fields$get === void 0 ? void 0 : _fields$get.type;
|
|
53
|
-
if (target) {
|
|
54
|
-
var _targetFields$get, _fields$get2;
|
|
55
|
-
const targetField = fields.get(target);
|
|
56
|
-
const targetCollection = ctx.db.getCollection(targetField.target);
|
|
57
|
-
const targetFields = targetCollection.fields;
|
|
58
|
-
fieldType = (_targetFields$get = targetFields.get(name)) === null || _targetFields$get === void 0 ? void 0 : _targetFields$get.type;
|
|
59
|
-
field = `${target}.${field}`;
|
|
60
|
-
name = `${target}.${name}`;
|
|
61
|
-
const targetType = (_fields$get2 = fields.get(target)) === null || _fields$get2 === void 0 ? void 0 : _fields$get2.type;
|
|
62
|
-
if (!models[target]) {
|
|
63
|
-
models[target] = {
|
|
64
|
-
type: targetType
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
field = `${collectionName}.${field}`;
|
|
69
|
-
}
|
|
70
|
-
return _objectSpread(_objectSpread({}, selected), {}, {
|
|
71
|
-
field,
|
|
72
|
-
name,
|
|
73
|
-
type: fieldType,
|
|
74
|
-
alias: selected.alias || name
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
const parsedMeasures = (measures === null || measures === void 0 ? void 0 : measures.map(parseField)) || [];
|
|
78
|
-
const parsedDimensions = (dimensions === null || dimensions === void 0 ? void 0 : dimensions.map(parseField)) || [];
|
|
79
|
-
const parsedOrders = (orders === null || orders === void 0 ? void 0 : orders.map(parseField)) || [];
|
|
80
|
-
const include = Object.entries(models).map(([target, {
|
|
81
|
-
type
|
|
82
|
-
}]) => _objectSpread({
|
|
83
|
-
association: target,
|
|
84
|
-
attributes: []
|
|
85
|
-
}, type === 'belongsToMany' ? {
|
|
86
|
-
through: {
|
|
87
|
-
attributes: []
|
|
88
|
-
}
|
|
89
|
-
} : {}));
|
|
90
|
-
const filterParser = new (_database().FilterParser)(filter, {
|
|
91
|
-
collection
|
|
92
|
-
});
|
|
93
|
-
const _filterParser$toSeque = filterParser.toSequelizeParams(),
|
|
94
|
-
where = _filterParser$toSeque.where,
|
|
95
|
-
filterInclude = _filterParser$toSeque.include;
|
|
96
|
-
const parsedFilterInclude = filterInclude === null || filterInclude === void 0 ? void 0 : filterInclude.map(item => {
|
|
97
|
-
var _fields$get3;
|
|
98
|
-
if (((_fields$get3 = fields.get(item.association)) === null || _fields$get3 === void 0 ? void 0 : _fields$get3.type) === 'belongsToMany') {
|
|
99
|
-
item.through = {
|
|
100
|
-
attributes: []
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return item;
|
|
104
|
-
});
|
|
105
|
-
return {
|
|
106
|
-
where,
|
|
107
|
-
measures: parsedMeasures,
|
|
108
|
-
dimensions: parsedDimensions,
|
|
109
|
-
orders: parsedOrders,
|
|
110
|
-
include: [...include, ...(parsedFilterInclude || [])]
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
exports.parseFieldAndAssociations = parseFieldAndAssociations;
|
|
114
|
-
const parseBuilder = (ctx, builder) => {
|
|
115
|
-
const sequelize = ctx.db.sequelize;
|
|
116
|
-
const limit = builder.limit;
|
|
117
|
-
const _parseFieldAndAssocia = parseFieldAndAssociations(ctx, builder),
|
|
118
|
-
measures = _parseFieldAndAssocia.measures,
|
|
119
|
-
dimensions = _parseFieldAndAssocia.dimensions,
|
|
120
|
-
orders = _parseFieldAndAssocia.orders,
|
|
121
|
-
include = _parseFieldAndAssocia.include,
|
|
122
|
-
where = _parseFieldAndAssocia.where;
|
|
123
|
-
const attributes = [];
|
|
124
|
-
const group = [];
|
|
125
|
-
const order = [];
|
|
126
|
-
const fieldMap = {};
|
|
127
|
-
let hasAgg = false;
|
|
128
|
-
measures.forEach(measure => {
|
|
129
|
-
const field = measure.field,
|
|
130
|
-
aggregation = measure.aggregation,
|
|
131
|
-
alias = measure.alias;
|
|
132
|
-
const attribute = [];
|
|
133
|
-
const col = sequelize.col(field);
|
|
134
|
-
if (aggregation) {
|
|
135
|
-
hasAgg = true;
|
|
136
|
-
attribute.push(sequelize.fn(aggregation, col));
|
|
137
|
-
} else {
|
|
138
|
-
attribute.push(col);
|
|
139
|
-
}
|
|
140
|
-
if (alias) {
|
|
141
|
-
attribute.push(alias);
|
|
142
|
-
}
|
|
143
|
-
attributes.push(attribute.length > 1 ? attribute : attribute[0]);
|
|
144
|
-
fieldMap[alias || field] = measure;
|
|
145
|
-
});
|
|
146
|
-
dimensions.forEach(dimension => {
|
|
147
|
-
const field = dimension.field,
|
|
148
|
-
format = dimension.format,
|
|
149
|
-
alias = dimension.alias,
|
|
150
|
-
type = dimension.type;
|
|
151
|
-
const attribute = [];
|
|
152
|
-
const col = sequelize.col(field);
|
|
153
|
-
if (format) {
|
|
154
|
-
attribute.push((0, _formatter.formatter)(sequelize, type, field, format));
|
|
155
|
-
} else {
|
|
156
|
-
attribute.push(col);
|
|
157
|
-
}
|
|
158
|
-
if (alias) {
|
|
159
|
-
attribute.push(alias);
|
|
160
|
-
}
|
|
161
|
-
attributes.push(attribute.length > 1 ? attribute : attribute[0]);
|
|
162
|
-
if (hasAgg) {
|
|
163
|
-
group.push(attribute[0]);
|
|
164
|
-
}
|
|
165
|
-
fieldMap[alias || field] = dimension;
|
|
166
|
-
});
|
|
167
|
-
orders.forEach(item => {
|
|
168
|
-
const alias = sequelize.getQueryInterface().quoteIdentifier(item.alias);
|
|
169
|
-
const name = hasAgg ? sequelize.literal(alias) : sequelize.col(item.field);
|
|
170
|
-
order.push([name, item.order || 'ASC']);
|
|
171
|
-
});
|
|
172
|
-
return {
|
|
173
|
-
queryParams: {
|
|
174
|
-
where,
|
|
175
|
-
attributes,
|
|
176
|
-
include,
|
|
177
|
-
group,
|
|
178
|
-
order,
|
|
179
|
-
limit: limit > 2000 ? 2000 : limit,
|
|
180
|
-
raw: true
|
|
181
|
-
},
|
|
182
|
-
fieldMap
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
exports.parseBuilder = parseBuilder;
|
|
186
|
-
const processData = (ctx, data, fieldMap) => {
|
|
187
|
-
const sequelize = ctx.db.sequelize;
|
|
188
|
-
const dialect = sequelize.getDialect();
|
|
189
|
-
switch (dialect) {
|
|
190
|
-
case 'postgres':
|
|
191
|
-
// https://github.com/sequelize/sequelize/issues/4550
|
|
192
|
-
return data.map(record => {
|
|
193
|
-
const result = {};
|
|
194
|
-
Object.entries(record).forEach(([key, value]) => {
|
|
195
|
-
const _ref = fieldMap[key] || {},
|
|
196
|
-
type = _ref.type;
|
|
197
|
-
switch (type) {
|
|
198
|
-
case 'bigInt':
|
|
199
|
-
case 'integer':
|
|
200
|
-
case 'float':
|
|
201
|
-
case 'double':
|
|
202
|
-
value = Number(value);
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
result[key] = value;
|
|
206
|
-
});
|
|
207
|
-
return result;
|
|
208
|
-
});
|
|
209
|
-
default:
|
|
210
|
-
return data;
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
exports.processData = processData;
|
|
214
|
-
const queryData = /*#__PURE__*/function () {
|
|
215
|
-
var _ref2 = _asyncToGenerator(function* (ctx, builder) {
|
|
216
|
-
const collection = builder.collection,
|
|
217
|
-
measures = builder.measures,
|
|
218
|
-
dimensions = builder.dimensions,
|
|
219
|
-
orders = builder.orders,
|
|
220
|
-
filter = builder.filter,
|
|
221
|
-
limit = builder.limit,
|
|
222
|
-
sql = builder.sql;
|
|
223
|
-
const model = ctx.db.getModel(collection);
|
|
224
|
-
const _parseBuilder = parseBuilder(ctx, {
|
|
225
|
-
collection,
|
|
226
|
-
measures,
|
|
227
|
-
dimensions,
|
|
228
|
-
orders,
|
|
229
|
-
filter,
|
|
230
|
-
limit
|
|
231
|
-
}),
|
|
232
|
-
queryParams = _parseBuilder.queryParams,
|
|
233
|
-
fieldMap = _parseBuilder.fieldMap;
|
|
234
|
-
const data = yield model.findAll(queryParams);
|
|
235
|
-
return processData(ctx, data, fieldMap);
|
|
236
|
-
// if (!sql) {
|
|
237
|
-
// return await repository.find(parseBuilder(ctx, { collection, measures, dimensions, orders, filter, limit }));
|
|
238
|
-
// }
|
|
239
|
-
// const statement = `SELECT ${sql.fields} FROM ${collection} ${sql.clauses}`;
|
|
240
|
-
// const [data] = await ctx.db.sequelize.query(statement);
|
|
241
|
-
// return data;
|
|
242
|
-
});
|
|
243
|
-
return function queryData(_x2, _x3) {
|
|
244
|
-
return _ref2.apply(this, arguments);
|
|
245
|
-
};
|
|
246
|
-
}();
|
|
247
|
-
exports.queryData = queryData;
|
|
248
|
-
const cacheWrap = /*#__PURE__*/function () {
|
|
249
|
-
var _ref3 = _asyncToGenerator(function* (cache, options) {
|
|
250
|
-
const func = options.func,
|
|
251
|
-
key = options.key,
|
|
252
|
-
ttl = options.ttl,
|
|
253
|
-
useCache = options.useCache,
|
|
254
|
-
refresh = options.refresh;
|
|
255
|
-
if (useCache && !refresh) {
|
|
256
|
-
const data = yield cache.get(key);
|
|
257
|
-
if (data) {
|
|
258
|
-
return data;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const data = yield func();
|
|
262
|
-
if (useCache) {
|
|
263
|
-
yield cache.set(key, data, ttl);
|
|
264
|
-
}
|
|
265
|
-
return data;
|
|
266
|
-
});
|
|
267
|
-
return function cacheWrap(_x4, _x5) {
|
|
268
|
-
return _ref3.apply(this, arguments);
|
|
269
|
-
};
|
|
270
|
-
}();
|
|
271
|
-
exports.cacheWrap = cacheWrap;
|
|
272
|
-
const query = /*#__PURE__*/function () {
|
|
273
|
-
var _ref4 = _asyncToGenerator(function* (ctx, next) {
|
|
274
|
-
const _ctx$action$params$va = ctx.action.params.values,
|
|
275
|
-
uid = _ctx$action$params$va.uid,
|
|
276
|
-
collection = _ctx$action$params$va.collection,
|
|
277
|
-
measures = _ctx$action$params$va.measures,
|
|
278
|
-
dimensions = _ctx$action$params$va.dimensions,
|
|
279
|
-
orders = _ctx$action$params$va.orders,
|
|
280
|
-
filter = _ctx$action$params$va.filter,
|
|
281
|
-
limit = _ctx$action$params$va.limit,
|
|
282
|
-
sql = _ctx$action$params$va.sql,
|
|
283
|
-
cacheConfig = _ctx$action$params$va.cache,
|
|
284
|
-
refresh = _ctx$action$params$va.refresh;
|
|
285
|
-
const roleName = ctx.state.currentRole || 'anonymous';
|
|
286
|
-
const can = ctx.app.acl.can({
|
|
287
|
-
role: roleName,
|
|
288
|
-
resource: collection,
|
|
289
|
-
action: 'list'
|
|
290
|
-
});
|
|
291
|
-
if (!can && roleName !== 'root') {
|
|
292
|
-
ctx.throw(403, 'No permissions');
|
|
293
|
-
}
|
|
294
|
-
const plugin = ctx.app.getPlugin('data-visualization');
|
|
295
|
-
const cache = plugin.cache;
|
|
296
|
-
const useCache = (cacheConfig === null || cacheConfig === void 0 ? void 0 : cacheConfig.enabled) && uid;
|
|
297
|
-
try {
|
|
298
|
-
ctx.body = yield cacheWrap(cache, {
|
|
299
|
-
func: function () {
|
|
300
|
-
var _func = _asyncToGenerator(function* () {
|
|
301
|
-
return yield queryData(ctx, {
|
|
302
|
-
collection,
|
|
303
|
-
measures,
|
|
304
|
-
dimensions,
|
|
305
|
-
orders,
|
|
306
|
-
filter,
|
|
307
|
-
limit,
|
|
308
|
-
sql
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
function func() {
|
|
312
|
-
return _func.apply(this, arguments);
|
|
313
|
-
}
|
|
314
|
-
return func;
|
|
315
|
-
}(),
|
|
316
|
-
key: uid,
|
|
317
|
-
ttl: (cacheConfig === null || cacheConfig === void 0 ? void 0 : cacheConfig.ttl) || 30,
|
|
318
|
-
useCache: useCache ? true : false,
|
|
319
|
-
refresh
|
|
320
|
-
});
|
|
321
|
-
} catch (err) {
|
|
322
|
-
ctx.app.logger.error('charts query: ', err);
|
|
323
|
-
ctx.throw(500, err);
|
|
324
|
-
}
|
|
325
|
-
yield next();
|
|
326
|
-
});
|
|
327
|
-
return function query(_x6, _x7) {
|
|
328
|
-
return _ref4.apply(this, arguments);
|
|
329
|
-
};
|
|
330
|
-
}();
|
|
331
|
-
exports.query = query;
|
package/lib/server/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "default", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _plugin.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/server/plugin.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.DataVisualizationPlugin = void 0;
|
|
7
|
-
function _cache() {
|
|
8
|
-
const data = require("@nocobase/cache");
|
|
9
|
-
_cache = function _cache() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _server() {
|
|
15
|
-
const data = require("@nocobase/server");
|
|
16
|
-
_server = function _server() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
var _query = require("./actions/query");
|
|
22
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
23
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
24
|
-
class DataVisualizationPlugin extends _server().Plugin {
|
|
25
|
-
constructor(...args) {
|
|
26
|
-
super(...args);
|
|
27
|
-
this.cache = void 0;
|
|
28
|
-
}
|
|
29
|
-
afterAdd() {}
|
|
30
|
-
beforeLoad() {
|
|
31
|
-
this.app.resource({
|
|
32
|
-
name: 'charts',
|
|
33
|
-
actions: {
|
|
34
|
-
query: _query.query
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
this.app.acl.allow('charts', 'query', 'loggedIn');
|
|
38
|
-
}
|
|
39
|
-
load() {
|
|
40
|
-
var _this = this;
|
|
41
|
-
return _asyncToGenerator(function* () {
|
|
42
|
-
_this.cache = (0, _cache().createCache)({
|
|
43
|
-
ttl: 30,
|
|
44
|
-
max: 1000,
|
|
45
|
-
store: 'memory'
|
|
46
|
-
});
|
|
47
|
-
})();
|
|
48
|
-
}
|
|
49
|
-
install(options) {
|
|
50
|
-
return _asyncToGenerator(function* () {})();
|
|
51
|
-
}
|
|
52
|
-
afterEnable() {
|
|
53
|
-
return _asyncToGenerator(function* () {})();
|
|
54
|
-
}
|
|
55
|
-
afterDisable() {
|
|
56
|
-
return _asyncToGenerator(function* () {})();
|
|
57
|
-
}
|
|
58
|
-
remove() {
|
|
59
|
-
return _asyncToGenerator(function* () {})();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.DataVisualizationPlugin = DataVisualizationPlugin;
|
|
63
|
-
var _default = DataVisualizationPlugin;
|
|
64
|
-
exports.default = _default;
|
package/src/client/Settings.tsx
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { CheckOutlined } from '@ant-design/icons';
|
|
2
|
-
import { Form, FormItem } from '@formily/antd-v5';
|
|
3
|
-
import { css } from '@nocobase/client';
|
|
4
|
-
import { Button, Card } from 'antd';
|
|
5
|
-
import cls from 'classnames';
|
|
6
|
-
import React, { useContext } from 'react';
|
|
7
|
-
import { useChartsTranslation } from './locale';
|
|
8
|
-
import { ChartLibraryContext, useToggleChartLibrary } from './renderer';
|
|
9
|
-
|
|
10
|
-
export const Settings = () => {
|
|
11
|
-
const { t } = useChartsTranslation();
|
|
12
|
-
const libraries = useContext(ChartLibraryContext);
|
|
13
|
-
const { toggle } = useToggleChartLibrary();
|
|
14
|
-
const list = Object.entries(libraries).map(([library, { enabled }]) => {
|
|
15
|
-
return (
|
|
16
|
-
<Button
|
|
17
|
-
key={library}
|
|
18
|
-
icon={enabled ? <CheckOutlined /> : ''}
|
|
19
|
-
className={cls(
|
|
20
|
-
css`
|
|
21
|
-
margin: 8px 8px 8px 0;
|
|
22
|
-
`,
|
|
23
|
-
enabled
|
|
24
|
-
? css`
|
|
25
|
-
color: #40a9ff;
|
|
26
|
-
border-color: #40a9ff;
|
|
27
|
-
`
|
|
28
|
-
: '',
|
|
29
|
-
)}
|
|
30
|
-
onClick={() => toggle(library)}
|
|
31
|
-
>
|
|
32
|
-
{library}
|
|
33
|
-
</Button>
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
return (
|
|
37
|
-
<Card>
|
|
38
|
-
<Form layout="vertical">
|
|
39
|
-
<FormItem label={t('Enabled Chart Library')}>{list}</FormItem>
|
|
40
|
-
</Form>
|
|
41
|
-
</Card>
|
|
42
|
-
);
|
|
43
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
describe('ChartConfigure', () => {
|
|
4
|
-
afterEach(() => {
|
|
5
|
-
vi.restoreAllMocks();
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('should render correctly', () => {
|
|
9
|
-
// vi.spyOn(client, 'useDesignable').mockReturnValue({} as any);
|
|
10
|
-
// render(<ChartConfigure insert={(schema, options) => {}} />);
|
|
11
|
-
// const modal = document.querySelector('.ant-modal-content') as HTMLInputElement;
|
|
12
|
-
// expect(modal).toBeInTheDocument();
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { FieldOption } from '../hooks';
|
|
2
|
-
import { infer } from '../renderer';
|
|
3
|
-
|
|
4
|
-
describe('library', () => {
|
|
5
|
-
describe('auto infer', () => {
|
|
6
|
-
const fields = [
|
|
7
|
-
{
|
|
8
|
-
name: 'price',
|
|
9
|
-
value: 'price',
|
|
10
|
-
type: 'number',
|
|
11
|
-
label: 'Price',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
name: 'count',
|
|
15
|
-
value: 'count',
|
|
16
|
-
type: 'number',
|
|
17
|
-
label: 'Count',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: 'title',
|
|
21
|
-
value: 'title',
|
|
22
|
-
type: 'string',
|
|
23
|
-
label: 'Title',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: 'name',
|
|
27
|
-
value: 'name',
|
|
28
|
-
type: 'string',
|
|
29
|
-
label: 'Name',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'createdAt',
|
|
33
|
-
value: 'createdAt',
|
|
34
|
-
type: 'date',
|
|
35
|
-
label: 'Created At',
|
|
36
|
-
},
|
|
37
|
-
] as FieldOption[];
|
|
38
|
-
|
|
39
|
-
test('1 measure, 1 dimension', () => {
|
|
40
|
-
const { xField, yField } = infer(fields, {
|
|
41
|
-
measures: [{ field: ['price'] }],
|
|
42
|
-
dimensions: [{ field: ['title'] }],
|
|
43
|
-
});
|
|
44
|
-
expect(yField.value).toEqual('price');
|
|
45
|
-
expect(xField.value).toEqual('title');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('1 measure, 2 dimensions with date', () => {
|
|
49
|
-
const { xField, yField, seriesField } = infer(fields, {
|
|
50
|
-
measures: [{ field: ['price'] }],
|
|
51
|
-
dimensions: [{ field: ['title'] }, { field: ['createdAt'] }],
|
|
52
|
-
});
|
|
53
|
-
expect(yField.value).toEqual('price');
|
|
54
|
-
expect(xField.value).toEqual('createdAt');
|
|
55
|
-
expect(seriesField.value).toEqual('title');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('1 measure, 2 dimensions without date', () => {
|
|
59
|
-
const { xField, yField, seriesField } = infer(fields, {
|
|
60
|
-
measures: [{ field: ['price'] }],
|
|
61
|
-
dimensions: [{ field: ['title'] }, { field: ['name'] }],
|
|
62
|
-
});
|
|
63
|
-
expect(yField.value).toEqual('price');
|
|
64
|
-
expect(xField.value).toEqual('title');
|
|
65
|
-
expect(seriesField.value).toEqual('name');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('2 measures, 1 dimension', () => {
|
|
69
|
-
const { xField, yField, yFields } = infer(fields, {
|
|
70
|
-
measures: [{ field: ['price'] }, { field: ['count'] }],
|
|
71
|
-
dimensions: [{ field: ['title'] }],
|
|
72
|
-
});
|
|
73
|
-
expect(yField.value).toEqual('price');
|
|
74
|
-
expect(xField.value).toEqual('title');
|
|
75
|
-
expect(yFields.length).toEqual(2);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
describe('ChartRenderer', () => {
|
|
2
|
-
it('should render correctly', () => {
|
|
3
|
-
// render(
|
|
4
|
-
// <ChartLibraryProvider
|
|
5
|
-
// name="Test"
|
|
6
|
-
// charts={{
|
|
7
|
-
// chart: {
|
|
8
|
-
// name: 'Chart',
|
|
9
|
-
// component: () => <div role="chart">Chart</div>,
|
|
10
|
-
// useProps: (info) => info,
|
|
11
|
-
// },
|
|
12
|
-
// }}
|
|
13
|
-
// >
|
|
14
|
-
// <ChartRendererProvider
|
|
15
|
-
// query={{}}
|
|
16
|
-
// config={{
|
|
17
|
-
// chartType: 'chart',
|
|
18
|
-
// general: {},
|
|
19
|
-
// advanced: {},
|
|
20
|
-
// }}
|
|
21
|
-
// collection=""
|
|
22
|
-
// transform={[]}
|
|
23
|
-
// >
|
|
24
|
-
// <ChartRenderer />
|
|
25
|
-
// </ChartRendererProvider>
|
|
26
|
-
// </ChartLibraryProvider>,
|
|
27
|
-
// );
|
|
28
|
-
// expect(screen.getByText('Please configure and run query')).toBeInTheDocument();
|
|
29
|
-
});
|
|
30
|
-
});
|