@nocobase/plugin-charts 0.10.0-alpha.2 → 0.10.0-alpha.3
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.
|
@@ -32,6 +32,13 @@ function _client() {
|
|
|
32
32
|
};
|
|
33
33
|
return data;
|
|
34
34
|
}
|
|
35
|
+
function _client2() {
|
|
36
|
+
const data = require("@nocobase/utils/client");
|
|
37
|
+
_client2 = function _client2() {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
35
42
|
function _react2() {
|
|
36
43
|
const data = _interopRequireWildcard(require("react"));
|
|
37
44
|
_react2 = function _react2() {
|
|
@@ -52,20 +59,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
52
59
|
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; }
|
|
53
60
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
54
61
|
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); }
|
|
55
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
56
|
-
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."); }
|
|
57
|
-
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); }
|
|
58
|
-
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; }
|
|
59
|
-
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; } }
|
|
60
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
61
62
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
62
63
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
63
64
|
const ChartQueryBlockInitializer = props => {
|
|
64
|
-
const defaultItems = [{
|
|
65
|
-
type: 'itemGroup',
|
|
66
|
-
title: (0, _locale.lang)('Select query data'),
|
|
67
|
-
children: []
|
|
68
|
-
}];
|
|
69
65
|
const templateWrap = props.templateWrap,
|
|
70
66
|
onCreateBlockSchema = props.onCreateBlockSchema,
|
|
71
67
|
componentType = props.componentType,
|
|
@@ -74,14 +70,10 @@ const ChartQueryBlockInitializer = props => {
|
|
|
74
70
|
others = _objectWithoutProperties(props, _excluded);
|
|
75
71
|
const _useContext = (0, _react2().useContext)(_client().SchemaInitializerButtonContext),
|
|
76
72
|
setVisible = _useContext.setVisible;
|
|
77
|
-
const _useState = (0, _react2().useState)(defaultItems),
|
|
78
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
79
|
-
items = _useState2[0],
|
|
80
|
-
setItems = _useState2[1];
|
|
81
73
|
const apiClient = (0, _client().useAPIClient)();
|
|
82
74
|
const ctx = (0, _ChartQueryMetadataProvider.useChartQueryMetadataContext)();
|
|
83
75
|
const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
|
|
84
|
-
const onAddQuery = info => {
|
|
76
|
+
const onAddQuery = (0, _react2().useCallback)(info => {
|
|
85
77
|
(0, _antd().FormDialog)({
|
|
86
78
|
sql: (0, _locale.lang)('Add SQL query'),
|
|
87
79
|
json: (0, _locale.lang)('Add JSON query')
|
|
@@ -112,37 +104,50 @@ const ChartQueryBlockInitializer = props => {
|
|
|
112
104
|
}).then( /*#__PURE__*/function () {
|
|
113
105
|
var _ref = _asyncToGenerator(function* (values) {
|
|
114
106
|
try {
|
|
115
|
-
var _apiClient$resource
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
107
|
+
var _apiClient$resource;
|
|
108
|
+
if ((_apiClient$resource = apiClient.resource('chartsQueries')) === null || _apiClient$resource === void 0 ? void 0 : _apiClient$resource.create) {
|
|
109
|
+
const _yield$apiClient$reso = yield apiClient.resource('chartsQueries').create({
|
|
110
|
+
values
|
|
111
|
+
}),
|
|
112
|
+
data = _yield$apiClient$reso.data;
|
|
113
|
+
const items = yield ctx.refresh();
|
|
114
|
+
const item = items.find(item => {
|
|
115
|
+
var _data$data;
|
|
116
|
+
return item.id === (data === null || data === void 0 ? void 0 : (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.id);
|
|
117
|
+
});
|
|
118
|
+
onCreateBlockSchema({
|
|
119
|
+
item
|
|
120
|
+
});
|
|
121
|
+
}
|
|
128
122
|
setVisible(false);
|
|
129
|
-
} catch (
|
|
123
|
+
} catch (err) {
|
|
124
|
+
(0, _client2().error)(err);
|
|
125
|
+
}
|
|
130
126
|
});
|
|
131
|
-
return function (
|
|
127
|
+
return function (_x) {
|
|
132
128
|
return _ref.apply(this, arguments);
|
|
133
129
|
};
|
|
134
|
-
}()).catch(
|
|
135
|
-
|
|
136
|
-
|
|
130
|
+
}()).catch(err => {
|
|
131
|
+
(0, _client2().error)(err);
|
|
132
|
+
});
|
|
133
|
+
}, [apiClient, ctx, onCreateBlockSchema, options.components, options.scope, setVisible]);
|
|
134
|
+
const items = (0, _react2().useMemo)(() => {
|
|
135
|
+
const defaultItems = [{
|
|
136
|
+
type: 'itemGroup',
|
|
137
|
+
title: (0, _locale.lang)('Select query data'),
|
|
138
|
+
children: []
|
|
139
|
+
}];
|
|
137
140
|
const chartQueryMetadata = ctx.data;
|
|
138
141
|
if (chartQueryMetadata && Array.isArray(chartQueryMetadata)) {
|
|
139
|
-
|
|
142
|
+
const item1 = chartQueryMetadata.length > 0 ? {
|
|
140
143
|
type: 'itemGroup',
|
|
141
144
|
title: '{{t("Select chart query", {ns: "charts"})}}',
|
|
142
145
|
children: chartQueryMetadata
|
|
143
|
-
} : null
|
|
146
|
+
} : null;
|
|
147
|
+
const item2 = chartQueryMetadata.length > 0 ? {
|
|
144
148
|
type: 'divider'
|
|
145
|
-
} : null
|
|
149
|
+
} : null;
|
|
150
|
+
return [item1, item2, {
|
|
146
151
|
type: 'subMenu',
|
|
147
152
|
title: (0, _locale.lang)('Add chart query'),
|
|
148
153
|
// component: AddChartQuery,
|
|
@@ -157,9 +162,10 @@ const ChartQueryBlockInitializer = props => {
|
|
|
157
162
|
title: 'JSON',
|
|
158
163
|
onClick: onAddQuery
|
|
159
164
|
}]
|
|
160
|
-
}].filter(Boolean)
|
|
165
|
+
}].filter(Boolean);
|
|
161
166
|
}
|
|
162
|
-
|
|
167
|
+
return defaultItems;
|
|
168
|
+
}, [ctx.data, onAddQuery]);
|
|
163
169
|
return _react2().default.createElement(_client().SchemaInitializer.Item, _objectSpread(_objectSpread({
|
|
164
170
|
icon: _react2().default.createElement(_icons().TableOutlined, null)
|
|
165
171
|
}, others), {}, {
|
|
@@ -172,7 +178,7 @@ const ChartQueryBlockInitializer = props => {
|
|
|
172
178
|
});
|
|
173
179
|
setVisible(false);
|
|
174
180
|
});
|
|
175
|
-
function onClick(
|
|
181
|
+
function onClick(_x2) {
|
|
176
182
|
return _onClick.apply(this, arguments);
|
|
177
183
|
}
|
|
178
184
|
return onClick;
|
|
@@ -54,8 +54,8 @@ function _react2() {
|
|
|
54
54
|
return data;
|
|
55
55
|
}
|
|
56
56
|
var _ChartQueryMetadataProvider = require("../ChartQueryMetadataProvider");
|
|
57
|
-
var _queryTypes = require("./queryTypes");
|
|
58
57
|
var _locale = require("../locale");
|
|
58
|
+
var _queryTypes = require("./queryTypes");
|
|
59
59
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
60
60
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
61
61
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
@@ -188,36 +188,44 @@ const AddNewQuery = () => {
|
|
|
188
188
|
schema = _useState4[0],
|
|
189
189
|
setSchema = _useState4[1];
|
|
190
190
|
const form = (0, _react2().useMemo)(() => (0, _core().createForm)(), []);
|
|
191
|
-
const menu = _react2().
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
191
|
+
const menu = (0, _react2().useMemo)(() => {
|
|
192
|
+
return {
|
|
193
|
+
onClick: info => {
|
|
194
|
+
setVisible(true);
|
|
195
|
+
form.setValues({
|
|
196
|
+
type: info.key
|
|
197
|
+
});
|
|
198
|
+
setSchema(getSchema({
|
|
199
|
+
type: info.key
|
|
200
|
+
}, {
|
|
201
|
+
form,
|
|
202
|
+
isNewRecord: true
|
|
203
|
+
}));
|
|
204
|
+
},
|
|
205
|
+
items: [{
|
|
206
|
+
key: 'json',
|
|
207
|
+
label: 'JSON'
|
|
199
208
|
}, {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}, "Collection"));
|
|
209
|
+
key: 'sql',
|
|
210
|
+
label: 'SQL'
|
|
211
|
+
}, {
|
|
212
|
+
key: 'api',
|
|
213
|
+
label: 'API',
|
|
214
|
+
disabled: true
|
|
215
|
+
}, {
|
|
216
|
+
key: 'collection',
|
|
217
|
+
label: 'Collection',
|
|
218
|
+
disabled: true
|
|
219
|
+
}]
|
|
220
|
+
};
|
|
221
|
+
}, [form]);
|
|
214
222
|
return _react2().default.createElement(_client().ActionContextProvider, {
|
|
215
223
|
value: {
|
|
216
224
|
visible,
|
|
217
225
|
setVisible
|
|
218
226
|
}
|
|
219
227
|
}, _react2().default.createElement(_antd().Dropdown, {
|
|
220
|
-
|
|
228
|
+
menu: menu
|
|
221
229
|
}, _react2().default.createElement(_antd().Button, {
|
|
222
230
|
icon: _react2().default.createElement(_icons().PlusOutlined, null),
|
|
223
231
|
type: 'primary'
|
package/package.json
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
"displayName.zh-CN": "图表",
|
|
5
5
|
"description": "Out-of-the-box, feature-rich chart plugins.",
|
|
6
6
|
"description.zh-CN": "开箱即用、丰富的报表。",
|
|
7
|
-
"version": "0.10.0-alpha.
|
|
7
|
+
"version": "0.10.0-alpha.3",
|
|
8
8
|
"main": "lib/server/index.js",
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@nocobase/client": "0.10.0-alpha.
|
|
11
|
-
"@nocobase/server": "0.10.0-alpha.
|
|
12
|
-
"@nocobase/test": "0.10.0-alpha.
|
|
10
|
+
"@nocobase/client": "0.10.0-alpha.3",
|
|
11
|
+
"@nocobase/server": "0.10.0-alpha.3",
|
|
12
|
+
"@nocobase/test": "0.10.0-alpha.3"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"json5": "^2.2.3"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "1f0b27fc9ab2398cd41c308a6b01a986e025cd20"
|
|
18
18
|
}
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
SchemaInitializerButtonContext,
|
|
9
9
|
useAPIClient,
|
|
10
10
|
} from '@nocobase/client';
|
|
11
|
-
import
|
|
11
|
+
import { error } from '@nocobase/utils/client';
|
|
12
|
+
import React, { useCallback, useContext, useMemo } from 'react';
|
|
12
13
|
import { useChartQueryMetadataContext } from './ChartQueryMetadataProvider';
|
|
13
14
|
import { lang } from './locale';
|
|
14
15
|
import { getQueryTypeSchema } from './settings/queryTypes';
|
|
@@ -21,107 +22,121 @@ export interface ChartQueryMetadata {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export const ChartQueryBlockInitializer = (props) => {
|
|
24
|
-
const defaultItems: any = [
|
|
25
|
-
{
|
|
26
|
-
type: 'itemGroup',
|
|
27
|
-
title: lang('Select query data'),
|
|
28
|
-
children: [],
|
|
29
|
-
},
|
|
30
|
-
];
|
|
31
25
|
const { templateWrap, onCreateBlockSchema, componentType, createBlockSchema, insert, ...others } = props;
|
|
32
26
|
const { setVisible } = useContext(SchemaInitializerButtonContext);
|
|
33
|
-
const [items, setItems] = useState(defaultItems);
|
|
34
27
|
const apiClient = useAPIClient();
|
|
35
28
|
const ctx = useChartQueryMetadataContext();
|
|
36
29
|
const options = useContext(SchemaOptionsContext);
|
|
37
|
-
const onAddQuery = (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
title:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
30
|
+
const onAddQuery = useCallback(
|
|
31
|
+
(info) => {
|
|
32
|
+
FormDialog(
|
|
33
|
+
{
|
|
34
|
+
sql: lang('Add SQL query'),
|
|
35
|
+
json: lang('Add JSON query'),
|
|
36
|
+
}[info.key],
|
|
37
|
+
() => {
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
|
41
|
+
<FormLayout layout={'vertical'}>
|
|
42
|
+
<SchemaComponent
|
|
43
|
+
schema={{
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
title: {
|
|
47
|
+
title: lang('Title'),
|
|
48
|
+
required: true,
|
|
49
|
+
'x-component': 'Input',
|
|
50
|
+
'x-decorator': 'FormItem',
|
|
51
|
+
},
|
|
52
|
+
options: getQueryTypeSchema(info.key),
|
|
57
53
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
},
|
|
67
|
-
)
|
|
68
|
-
.open({
|
|
69
|
-
initialValues: {
|
|
70
|
-
type: info.key,
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
</FormLayout>
|
|
57
|
+
</SchemaComponentOptions>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
71
60
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
61
|
+
)
|
|
62
|
+
.open({
|
|
63
|
+
initialValues: {
|
|
64
|
+
type: info.key,
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
.then(async (values) => {
|
|
68
|
+
try {
|
|
69
|
+
if (apiClient.resource('chartsQueries')?.create) {
|
|
70
|
+
const { data } = await apiClient.resource('chartsQueries').create({ values });
|
|
71
|
+
const items = (await ctx.refresh()) as any;
|
|
72
|
+
const item = items.find((item) => item.id === data?.data?.id);
|
|
73
|
+
onCreateBlockSchema({ item });
|
|
74
|
+
}
|
|
75
|
+
setVisible(false);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
error(err);
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.catch((err) => {
|
|
81
|
+
error(err);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
[apiClient, ctx, onCreateBlockSchema, options.components, options.scope, setVisible],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const items = useMemo(() => {
|
|
88
|
+
const defaultItems: any = [
|
|
89
|
+
{
|
|
90
|
+
type: 'itemGroup',
|
|
91
|
+
title: lang('Select query data'),
|
|
92
|
+
children: [],
|
|
93
|
+
},
|
|
94
|
+
];
|
|
85
95
|
const chartQueryMetadata = ctx.data;
|
|
86
96
|
if (chartQueryMetadata && Array.isArray(chartQueryMetadata)) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
97
|
+
const item1 =
|
|
98
|
+
chartQueryMetadata.length > 0
|
|
99
|
+
? {
|
|
100
|
+
type: 'itemGroup',
|
|
101
|
+
title: '{{t("Select chart query", {ns: "charts"})}}',
|
|
102
|
+
children: chartQueryMetadata,
|
|
103
|
+
}
|
|
104
|
+
: null;
|
|
105
|
+
const item2 =
|
|
106
|
+
chartQueryMetadata.length > 0
|
|
107
|
+
? {
|
|
108
|
+
type: 'divider',
|
|
109
|
+
}
|
|
110
|
+
: null;
|
|
111
|
+
|
|
112
|
+
return [
|
|
113
|
+
item1,
|
|
114
|
+
item2,
|
|
115
|
+
{
|
|
116
|
+
type: 'subMenu',
|
|
117
|
+
title: lang('Add chart query'),
|
|
118
|
+
// component: AddChartQuery,
|
|
119
|
+
children: [
|
|
120
|
+
{
|
|
121
|
+
key: 'sql',
|
|
122
|
+
type: 'item',
|
|
123
|
+
title: 'SQL',
|
|
124
|
+
onClick: onAddQuery,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
key: 'json',
|
|
128
|
+
type: 'item',
|
|
129
|
+
title: 'JSON',
|
|
130
|
+
onClick: onAddQuery,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
].filter(Boolean);
|
|
123
135
|
}
|
|
124
|
-
|
|
136
|
+
|
|
137
|
+
return defaultItems;
|
|
138
|
+
}, [ctx.data, onAddQuery]);
|
|
139
|
+
|
|
125
140
|
return (
|
|
126
141
|
<SchemaInitializer.Item
|
|
127
142
|
icon={<TableOutlined />}
|
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
useResourceActionContext,
|
|
11
11
|
useResourceContext,
|
|
12
12
|
} from '@nocobase/client';
|
|
13
|
-
import { Button, Dropdown,
|
|
13
|
+
import { Button, Dropdown, MenuProps } from 'antd';
|
|
14
14
|
import React, { useMemo, useState } from 'react';
|
|
15
15
|
import { useChartQueryMetadataContext } from '../ChartQueryMetadataProvider';
|
|
16
|
-
import { getQueryTypeSchema } from './queryTypes';
|
|
17
16
|
import { lang } from '../locale';
|
|
17
|
+
import { getQueryTypeSchema } from './queryTypes';
|
|
18
18
|
|
|
19
19
|
const useCreateAction = () => {
|
|
20
20
|
const { setVisible } = useActionContext();
|
|
@@ -112,25 +112,40 @@ export const AddNewQuery = () => {
|
|
|
112
112
|
const [visible, setVisible] = useState(false);
|
|
113
113
|
const [schema, setSchema] = useState({});
|
|
114
114
|
const form = useMemo(() => createForm(), []);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
|
|
116
|
+
const menu = useMemo<MenuProps>(() => {
|
|
117
|
+
return {
|
|
118
|
+
onClick: (info) => {
|
|
118
119
|
setVisible(true);
|
|
119
120
|
form.setValues({ type: info.key });
|
|
120
121
|
setSchema(getSchema({ type: info.key }, { form, isNewRecord: true }));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
},
|
|
123
|
+
items: [
|
|
124
|
+
{
|
|
125
|
+
key: 'json',
|
|
126
|
+
label: 'JSON',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
key: 'sql',
|
|
130
|
+
label: 'SQL',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
key: 'api',
|
|
134
|
+
label: 'API',
|
|
135
|
+
disabled: true,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
key: 'collection',
|
|
139
|
+
label: 'Collection',
|
|
140
|
+
disabled: true,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
}, [form]);
|
|
145
|
+
|
|
131
146
|
return (
|
|
132
147
|
<ActionContextProvider value={{ visible, setVisible }}>
|
|
133
|
-
<Dropdown
|
|
148
|
+
<Dropdown menu={menu}>
|
|
134
149
|
<Button icon={<PlusOutlined />} type={'primary'}>
|
|
135
150
|
{lang('Add query')} <DownOutlined />
|
|
136
151
|
</Button>
|