@nocobase/plugin-charts 0.11.0-alpha.1 → 0.11.1-alpha.1

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.
@@ -15,9 +15,9 @@ export interface ChartBlockEngineMetaData {
15
15
  chart: IChartConfig;
16
16
  }
17
17
  export declare const useGetDataSet: (chartQueryId: number) => {
18
- loading: any;
18
+ loading: boolean;
19
19
  dataSet: any;
20
- error: any;
20
+ error: Error;
21
21
  };
22
22
  declare const ChartBlockEngine: {
23
23
  ({ chartBlockEngineMetaData }: {
@@ -63,11 +63,6 @@ const ChartRenderComponent = ({
63
63
  loading = _useGetDataSet.loading,
64
64
  dataSet = _useGetDataSet.dataSet,
65
65
  error = _useGetDataSet.error;
66
- if (error) {
67
- return _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_antd().Empty, {
68
- description: _react().default.createElement("span", null, "May be this chart block's query data has been deleted,please check!")
69
- }));
70
- }
71
66
  const _useState = (0, _react().useState)({}),
72
67
  _useState2 = _slicedToArray(_useState, 2),
73
68
  currentConfig = _useState2[0],
@@ -75,6 +70,11 @@ const ChartRenderComponent = ({
75
70
  (0, _react().useEffect)(() => {
76
71
  setCurrentConfig(chartConfig);
77
72
  }, [JSON.stringify(chartConfig)]);
73
+ if (error) {
74
+ return _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_antd().Empty, {
75
+ description: _react().default.createElement("span", null, `May be this chart block's query data has been deleted,please check!`)
76
+ }));
77
+ }
78
78
  if (currentConfig.type !== chartConfig.type) {
79
79
  return _react().default.createElement(_react().default.Fragment, null);
80
80
  }
@@ -82,8 +82,7 @@ const ChartRenderComponent = ({
82
82
  case 'G2Plot':
83
83
  {
84
84
  var _templates$get2, _chartConfig$category;
85
- let finalChartOptions;
86
- finalChartOptions = (_templates$get2 = _templates.templates.get(chartType)) === null || _templates$get2 === void 0 ? void 0 : _templates$get2.defaultChartOptions;
85
+ const finalChartOptions = (_templates$get2 = _templates.templates.get(chartType)) === null || _templates$get2 === void 0 ? void 0 : _templates$get2.defaultChartOptions;
87
86
  let template;
88
87
  try {
89
88
  template = _json().default.parse(chartConfig === null || chartConfig === void 0 ? void 0 : chartConfig.template);
@@ -25,6 +25,13 @@ function _client() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ function _client2() {
29
+ const data = require("@nocobase/utils/client");
30
+ _client2 = function _client2() {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
28
35
  function _antd() {
29
36
  const data = require("antd");
30
37
  _antd = function _antd() {
@@ -129,6 +136,8 @@ const ChartBlockEngineDesignerInitializer = props => {
129
136
  query = chartBlockEngineMetaData.query;
130
137
  const _useFieldsById = (0, _hooks.useFieldsById)(query.id),
131
138
  fields = _useFieldsById.fields;
139
+ const _useGlobalTheme = (0, _client().useGlobalTheme)(),
140
+ theme = _useGlobalTheme.theme;
132
141
  const dataSource = fields.map(field => {
133
142
  return {
134
143
  label: field.name,
@@ -138,7 +147,7 @@ const ChartBlockEngineDesignerInitializer = props => {
138
147
  return _react2().default.createElement(_client().SchemaSettings.Item, {
139
148
  onClick: function () {
140
149
  var _onClick = _asyncToGenerator(function* () {
141
- (0, _antdV().FormDialog)({
150
+ (0, _client().FormDialog)({
142
151
  okText: compile('{{t("Submit")}}'),
143
152
  title: (0, _locale.lang)('Edit chart block'),
144
153
  width: 1200,
@@ -147,7 +156,7 @@ const ChartBlockEngineDesignerInitializer = props => {
147
156
  maxHeight: '65vh',
148
157
  overflow: 'auto'
149
158
  }
150
- }, form => {
159
+ }, function Com(form) {
151
160
  var _chartBlockEngineMeta, _chartBlockEngineMeta2;
152
161
  const _useState = (0, _react2().useState)(null),
153
162
  _useState2 = _slicedToArray(_useState, 2),
@@ -251,7 +260,7 @@ const ChartBlockEngineDesignerInitializer = props => {
251
260
  queryId: chartBlockEngineMetaData === null || chartBlockEngineMetaData === void 0 ? void 0 : (_chartBlockEngineMeta2 = chartBlockEngineMetaData.query) === null || _chartBlockEngineMeta2 === void 0 ? void 0 : _chartBlockEngineMeta2.id,
252
261
  fields: fields
253
262
  }))))));
254
- }).open({
263
+ }, theme).open({
255
264
  initialValues: _objectSpread({}, chart) //reset before chartBlockMetaData
256
265
  }).then(values => {
257
266
  //patch updates
@@ -270,6 +279,8 @@ const ChartBlockEngineDesignerInitializer = props => {
270
279
  }
271
280
  });
272
281
  dn.refresh();
282
+ }).catch(err => {
283
+ (0, _client2().error)(err);
273
284
  });
274
285
  });
275
286
  function onClick() {
@@ -102,8 +102,8 @@ const ChartBlockInitializer = props => {
102
102
  const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
103
103
  const api = (0, _client().useAPIClient)();
104
104
  const compile = (0, _client().useCompile)();
105
- const _useChartsTranslation = (0, _locale.useChartsTranslation)(),
106
- t = _useChartsTranslation.t;
105
+ const _useGlobalTheme = (0, _client().useGlobalTheme)(),
106
+ theme = _useGlobalTheme.theme;
107
107
  return _react2().default.createElement(_ChartQueryBlockInitializer.ChartQueryBlockInitializer, _objectSpread(_objectSpread({}, props), {}, {
108
108
  componentType: 'Charts',
109
109
  onCreateBlockSchema: function () {
@@ -116,7 +116,7 @@ const ChartBlockInitializer = props => {
116
116
  value: field.name
117
117
  };
118
118
  });
119
- const values = yield (0, _antdV().FormDialog)({
119
+ const values = yield (0, _client().FormDialog)({
120
120
  okText: compile('{{t("Submit")}}'),
121
121
  title: (0, _locale.lang)('Create chart block'),
122
122
  width: 1200,
@@ -125,7 +125,7 @@ const ChartBlockInitializer = props => {
125
125
  maxHeight: '65vh',
126
126
  overflow: 'auto'
127
127
  }
128
- }, () => {
128
+ }, function Com() {
129
129
  var _chartBlockEngineMeta, _chartBlockEngineMeta2;
130
130
  const form = (0, _react().useForm)();
131
131
  const _useState5 = (0, _react2().useState)(null),
@@ -231,7 +231,7 @@ const ChartBlockInitializer = props => {
231
231
  queryId: chartBlockEngineMetaData === null || chartBlockEngineMetaData === void 0 ? void 0 : (_chartBlockEngineMeta2 = chartBlockEngineMetaData.query) === null || _chartBlockEngineMeta2 === void 0 ? void 0 : _chartBlockEngineMeta2.id,
232
232
  fields: chartQueryMetadata === null || chartQueryMetadata === void 0 ? void 0 : chartQueryMetadata.fields
233
233
  }))))));
234
- }).open({
234
+ }, theme).open({
235
235
  initialValues: {}
236
236
  });
237
237
  if (values) {
@@ -73,8 +73,10 @@ const ChartQueryBlockInitializer = props => {
73
73
  const apiClient = (0, _client().useAPIClient)();
74
74
  const ctx = (0, _ChartQueryMetadataProvider.useChartQueryMetadataContext)();
75
75
  const options = (0, _react2().useContext)(_react().SchemaOptionsContext);
76
+ const _useGlobalTheme = (0, _client().useGlobalTheme)(),
77
+ theme = _useGlobalTheme.theme;
76
78
  const onAddQuery = (0, _react2().useCallback)(info => {
77
- (0, _antdV().FormDialog)({
79
+ (0, _client().FormDialog)({
78
80
  sql: (0, _locale.lang)('Add SQL query'),
79
81
  json: (0, _locale.lang)('Add JSON query')
80
82
  }[info.key], () => {
@@ -97,7 +99,7 @@ const ChartQueryBlockInitializer = props => {
97
99
  }
98
100
  }
99
101
  }))));
100
- }).open({
102
+ }, theme).open({
101
103
  initialValues: {
102
104
  type: info.key
103
105
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "图表",
5
5
  "description": "Out-of-the-box, feature-rich chart plugins.",
6
6
  "description.zh-CN": "开箱即用、丰富的报表。",
7
- "version": "0.11.0-alpha.1",
7
+ "version": "0.11.1-alpha.1",
8
8
  "main": "./lib/server/index.js",
9
9
  "files": [
10
10
  "lib",
@@ -26,15 +26,15 @@
26
26
  "@formily/core": "2.2.26",
27
27
  "@formily/react": "2.2.26",
28
28
  "@formily/shared": "2.2.26",
29
- "@nocobase/client": "0.11.0-alpha.1",
30
- "@nocobase/database": "0.11.0-alpha.1",
31
- "@nocobase/server": "0.11.0-alpha.1",
32
- "@nocobase/test": "0.11.0-alpha.1",
33
- "@nocobase/utils": "0.11.0-alpha.1",
29
+ "@nocobase/client": "0.11.1-alpha.1",
30
+ "@nocobase/database": "0.11.1-alpha.1",
31
+ "@nocobase/server": "0.11.1-alpha.1",
32
+ "@nocobase/test": "0.11.1-alpha.1",
33
+ "@nocobase/utils": "0.11.1-alpha.1",
34
34
  "antd": "^5.6.4",
35
35
  "react": "^18.2.0",
36
36
  "react-i18next": "^11.15.1",
37
37
  "react-router-dom": "^6.11.2"
38
38
  },
39
- "gitHead": "7581b6d3a3a54f09f06a9effb7e3e65328281b2b"
39
+ "gitHead": "9ed1dba520bc5f3a7cb1255ea8d92ccbefc11bc8"
40
40
  }
@@ -36,28 +36,27 @@ const ChartRenderComponent = ({
36
36
  const chartConfig = chartBlockEngineMetaData.chart;
37
37
  const { loading, dataSet, error } = useGetDataSet(chartBlockEngineMetaData.query.id);
38
38
 
39
+ const [currentConfig, setCurrentConfig] = useState<IChartConfig>({} as any);
40
+
41
+ useEffect(() => {
42
+ setCurrentConfig(chartConfig);
43
+ }, [JSON.stringify(chartConfig)]);
44
+
39
45
  if (error) {
40
46
  return (
41
47
  <>
42
- <Empty description={<span>May be this chart block's query data has been deleted,please check!</span>} />
48
+ <Empty description={<span>{`May be this chart block's query data has been deleted,please check!`}</span>} />
43
49
  </>
44
50
  );
45
51
  }
46
52
 
47
- const [currentConfig, setCurrentConfig] = useState<IChartConfig>({} as any);
48
-
49
- useEffect(() => {
50
- setCurrentConfig(chartConfig);
51
- }, [JSON.stringify(chartConfig)]);
52
-
53
53
  if (currentConfig.type !== chartConfig.type) {
54
54
  return <></>;
55
55
  }
56
56
 
57
57
  switch (renderComponent) {
58
58
  case 'G2Plot': {
59
- let finalChartOptions;
60
- finalChartOptions = templates.get(chartType)?.defaultChartOptions;
59
+ const finalChartOptions = templates.get(chartType)?.defaultChartOptions;
61
60
  let template;
62
61
  try {
63
62
  template = JSON5.parse(chartConfig?.template);
@@ -85,7 +84,9 @@ const ChartRenderComponent = ({
85
84
  };
86
85
 
87
86
  export const useGetDataSet = (chartQueryId: number) => {
88
- const { data, loading, error } = useRequest({
87
+ const { data, loading, error } = useRequest<{
88
+ data: any;
89
+ }>({
89
90
  url: `/chartsQueries:getData/${chartQueryId}`,
90
91
  });
91
92
  const dataSet = data?.data;
@@ -1,7 +1,8 @@
1
- import { FormDialog, FormLayout } from '@formily/antd-v5';
1
+ import { FormLayout } from '@formily/antd-v5';
2
2
  import { SchemaOptionsContext, useField, useFieldSchema } from '@formily/react';
3
3
  import {
4
4
  APIClientProvider,
5
+ FormDialog,
5
6
  GeneralSchemaDesigner,
6
7
  SchemaComponent,
7
8
  SchemaComponentOptions,
@@ -11,7 +12,9 @@ import {
11
12
  useAPIClient,
12
13
  useCompile,
13
14
  useDesignable,
15
+ useGlobalTheme,
14
16
  } from '@nocobase/client';
17
+ import { error } from '@nocobase/utils/client';
15
18
  import { Card } from 'antd';
16
19
  import JSON5 from 'json5';
17
20
  import React, { useContext, useEffect, useState } from 'react';
@@ -81,12 +84,15 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
81
84
  const compile = useCompile();
82
85
  const { chart, query } = chartBlockEngineMetaData;
83
86
  const { fields } = useFieldsById(query.id);
87
+ const { theme } = useGlobalTheme();
88
+
84
89
  const dataSource = fields.map((field) => {
85
90
  return {
86
91
  label: field.name,
87
92
  value: field.name,
88
93
  };
89
94
  });
95
+
90
96
  return (
91
97
  <SchemaSettings.Item
92
98
  onClick={async () => {
@@ -97,7 +103,7 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
97
103
  width: 1200,
98
104
  bodyStyle: { background: 'var(--nb-box-bg)', maxHeight: '65vh', overflow: 'auto' },
99
105
  },
100
- (form) => {
106
+ function Com(form) {
101
107
  const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
102
108
  useEffect(() => {
103
109
  const chartBlockEngineMetaData = {
@@ -208,6 +214,7 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
208
214
  </APIClientProvider>
209
215
  );
210
216
  },
217
+ theme,
211
218
  )
212
219
  .open({
213
220
  initialValues: { ...chart }, //reset before chartBlockMetaData
@@ -229,6 +236,9 @@ export const ChartBlockEngineDesignerInitializer = (props) => {
229
236
  },
230
237
  });
231
238
  dn.refresh();
239
+ })
240
+ .catch((err) => {
241
+ error(err);
232
242
  });
233
243
  }}
234
244
  >
@@ -1,14 +1,16 @@
1
- import { FormDialog, FormLayout } from '@formily/antd-v5';
1
+ import { FormLayout } from '@formily/antd-v5';
2
2
  import { Field } from '@formily/core';
3
3
  import { RecursionField, Schema, SchemaOptionsContext, observer, useField, useForm } from '@formily/react';
4
4
  import {
5
5
  APIClientProvider,
6
+ FormDialog,
6
7
  FormProvider,
7
8
  SchemaComponent,
8
9
  SchemaComponentOptions,
9
10
  css,
10
11
  useAPIClient,
11
12
  useCompile,
13
+ useGlobalTheme,
12
14
  } from '@nocobase/client';
13
15
  import { Card } from 'antd';
14
16
  import JSON5 from 'json5';
@@ -17,7 +19,7 @@ import { ChartBlockEngineMetaData } from './ChartBlockEngine';
17
19
  import { jsonConfigDesc } from './ChartBlockEngineDesigner';
18
20
  import { ChartQueryBlockInitializer, ChartQueryMetadata } from './ChartQueryBlockInitializer';
19
21
  import DataSetPreviewTable from './DataSetPreviewTable';
20
- import { lang, useChartsTranslation } from './locale';
22
+ import { lang } from './locale';
21
23
  import { templates } from './templates';
22
24
 
23
25
  export const Options = observer(
@@ -57,7 +59,8 @@ export const ChartBlockInitializer = (props) => {
57
59
  const options = useContext(SchemaOptionsContext);
58
60
  const api = useAPIClient();
59
61
  const compile = useCompile();
60
- const { t } = useChartsTranslation();
62
+ const { theme } = useGlobalTheme();
63
+
61
64
  return (
62
65
  <ChartQueryBlockInitializer
63
66
  {...props}
@@ -76,7 +79,7 @@ export const ChartBlockInitializer = (props) => {
76
79
  width: 1200,
77
80
  bodyStyle: { background: 'var(--nb-box-bg)', maxHeight: '65vh', overflow: 'auto' },
78
81
  },
79
- () => {
82
+ function Com() {
80
83
  const form = useForm<ChartFormInterface>();
81
84
  const [chartBlockEngineMetaData, setChartBlockEngineMetaData] = useState<ChartBlockEngineMetaData>(null);
82
85
  useEffect(() => {
@@ -192,6 +195,7 @@ export const ChartBlockInitializer = (props) => {
192
195
  </APIClientProvider>
193
196
  );
194
197
  },
198
+ theme,
195
199
  ).open({
196
200
  initialValues: {},
197
201
  });
@@ -1,12 +1,14 @@
1
1
  import { TableOutlined } from '@ant-design/icons';
2
- import { FormDialog, FormLayout } from '@formily/antd-v5';
2
+ import { FormLayout } from '@formily/antd-v5';
3
3
  import { SchemaOptionsContext } from '@formily/react';
4
4
  import {
5
+ FormDialog,
5
6
  SchemaComponent,
6
7
  SchemaComponentOptions,
7
8
  SchemaInitializer,
8
9
  SchemaInitializerButtonContext,
9
10
  useAPIClient,
11
+ useGlobalTheme,
10
12
  } from '@nocobase/client';
11
13
  import { error } from '@nocobase/utils/client';
12
14
  import React, { useCallback, useContext, useMemo } from 'react';
@@ -27,6 +29,8 @@ export const ChartQueryBlockInitializer = (props) => {
27
29
  const apiClient = useAPIClient();
28
30
  const ctx = useChartQueryMetadataContext();
29
31
  const options = useContext(SchemaOptionsContext);
32
+ const { theme } = useGlobalTheme();
33
+
30
34
  const onAddQuery = useCallback(
31
35
  (info) => {
32
36
  FormDialog(
@@ -58,6 +62,7 @@ export const ChartQueryBlockInitializer = (props) => {
58
62
  </div>
59
63
  );
60
64
  },
65
+ theme,
61
66
  )
62
67
  .open({
63
68
  initialValues: {
@@ -22,7 +22,9 @@ export const ChartQueryMetadataProvider: React.FC = (props) => {
22
22
 
23
23
  const location = useLocation();
24
24
 
25
- const service = useRequest(options, {
25
+ const service = useRequest<{
26
+ data: any;
27
+ }>(options, {
26
28
  manual: true,
27
29
  });
28
30