sea-chart 1.1.30 → 1.1.32

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/dist/context.js CHANGED
@@ -19,6 +19,8 @@ class Context {
19
19
  onFail
20
20
  });
21
21
  }
22
+
23
+ // use default api to get chart result data
22
24
  const table = getTableById(tables, chart.config.table_id);
23
25
  const currentView = table.views.find(view => view._id === chart.config.view_id);
24
26
  // use default view
@@ -6,6 +6,7 @@ import { settingsContext, DepartmentsContext, GlobalThemeContext } from '../util
6
6
  import { eventStopPropagation } from '../utils';
7
7
  import { BaseUtils } from '../utils';
8
8
  import { CHART_SETTINGS_TYPE, CHART_SETTINGS } from '../constants';
9
+ import useForceUpdate from '../components/types-dialog/use-force-update';
9
10
  import Divider from './widgets/divider';
10
11
  import DataSettings from './data-settings';
11
12
  import StyleSettings from './style-settings';
@@ -20,10 +21,19 @@ const Settings = _ref => {
20
21
  onChange,
21
22
  children,
22
23
  departments,
23
- globalTheme
24
+ globalTheme,
25
+ lang
24
26
  } = _ref;
25
27
  const [type, setType] = useState(CHART_SETTINGS_TYPE.DATA);
26
28
  const [labelColorConfigs, setLabelColorConfigs] = useState([]);
29
+ const forceUpdate = useForceUpdate();
30
+ useEffect(() => {
31
+ if (lang) {
32
+ intl.setLang(lang);
33
+ forceUpdate();
34
+ }
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ }, []);
27
37
  useEffect(() => {
28
38
  var _window$dtable;
29
39
  const systemCustomColors = ((_window$dtable = window.dtable) === null || _window$dtable === void 0 ? void 0 : _window$dtable.customColors) || [];
@@ -1,41 +1,51 @@
1
+ import { uniqueId } from 'lodash-es';
1
2
  import context from '../../context';
2
3
  import { getErrorMessage } from '..';
3
4
  import intl from '../../intl';
5
+ import concurrencyManager from '../concurrency-manager';
4
6
  import BaseUtils from './base-utils';
5
7
  import SQLStatisticsUtils from './sql-statistics-utils';
6
8
  import OriginalDataUtils from './original-data-utils';
7
9
  class ChartUtils {}
8
- ChartUtils.calculateChart = (chart, value, callback) => {
10
+ ChartUtils.calculateChart = async (chart, value, callback) => {
9
11
  if (!BaseUtils.isValidExistChart(value.tables, chart)) {
10
12
  const tip_message = 'Please_complete_the_chart_configuration_first';
11
13
  return callback && callback('', tip_message, null);
12
14
  }
13
- context.queryChartResult({
14
- chart,
15
- tables: value.tables,
16
- onSuccess: async function (res) {
17
- var _res$data;
18
- let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
19
- const {
20
- success,
21
- error_message
22
- } = res.data;
23
- if (!success) {
24
- const errMsg = intl.get(error_message);
25
- callback && callback(errMsg, '', null);
26
- return;
15
+ const id = uniqueId();
16
+ const requestData = () => {
17
+ context.queryChartResult({
18
+ chart,
19
+ tables: value.tables,
20
+ onSuccess: async function (res) {
21
+ var _res$data;
22
+ let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
23
+ // reolve request and start next request
24
+ concurrencyManager.removeRequest(id);
25
+ const {
26
+ success,
27
+ error_message
28
+ } = res.data;
29
+ if (!success) {
30
+ const errMsg = intl.get(error_message);
31
+ callback && callback(errMsg, '', null);
32
+ return;
33
+ }
34
+ if (dataSources === OriginalDataUtils.dataSources) {
35
+ OriginalDataUtils.calculateChart(chart, value, callback);
36
+ return;
37
+ }
38
+ await SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
39
+ },
40
+ onFail: err => {
41
+ concurrencyManager.removeRequest(id);
42
+ let errorMessage = getErrorMessage(err);
43
+ callback && callback(errorMessage, '', null);
27
44
  }
28
- if (dataSources === OriginalDataUtils.dataSources) {
29
- OriginalDataUtils.calculateChart(chart, value, callback);
30
- return;
31
- }
32
- await SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
33
- },
34
- onFail: err => {
35
- let errorMessage = getErrorMessage(err);
36
- callback && callback(errorMessage, '', null);
37
- }
38
- });
45
+ });
46
+ };
47
+ requestData.id = id;
48
+ concurrencyManager.applyRequest(requestData);
39
49
  };
40
50
  ChartUtils.calculateStaticChart = (chart, value, statisticalResult, callback) => {
41
51
  if (!BaseUtils.isValidExistChart(value.tables, chart)) {
@@ -0,0 +1,33 @@
1
+ class ConcurrencyManager {
2
+ constructor(concurrentCount) {
3
+ this.concurrentCount = concurrentCount;
4
+ this.requestList = [];
5
+ this.queue = [];
6
+ }
7
+ applyRequest(req) {
8
+ if (this.requestList.length < this.concurrentCount) {
9
+ this.requestList.push(req);
10
+ req();
11
+ } else {
12
+ this.queue.push({
13
+ req
14
+ });
15
+ }
16
+ }
17
+ removeRequest(id) {
18
+ const index = this.requestList.findIndex(req => req.id === id);
19
+ if (index > -1) {
20
+ this.requestList.splice(index, 1);
21
+ }
22
+ if (this.queue.length > 0) {
23
+ const {
24
+ req
25
+ } = this.queue.shift();
26
+ this.requestList.push(req);
27
+ req();
28
+ }
29
+ }
30
+ }
31
+ // request once a time
32
+ const concurrencyManager = new ConcurrencyManager(1);
33
+ export default concurrencyManager;
@@ -132,13 +132,22 @@ class View extends React.PureComponent {
132
132
  componentDidMount() {
133
133
  var _window$app;
134
134
  const {
135
- isCalculateByView
135
+ isCalculateByView,
136
+ autoRefresh,
137
+ refreshInterval
136
138
  } = this.props;
137
139
  this.unsubscribeReFreshChart = eventBus.subscribe(CommonEventTypes.REFRESH_CHARTS, this.refreshChart);
138
140
  if (((_window$app = window.app) === null || _window$app === void 0 ? void 0 : _window$app.eventBus) && isCalculateByView) {
139
141
  window.app.eventBus.subscribe(CommonEventTypes.EXPAND_ROW_UPDATED, this.handleModifyRecord);
140
142
  window.app.eventBus.subscribe(CommonEventTypes.EXPAND_ROW_DELETED, this.handleDeleteRecord);
141
143
  }
144
+
145
+ // refreshInterval is minutes
146
+ if (autoRefresh && refreshInterval) {
147
+ this.refreshTimer = setInterval(() => {
148
+ this.calculateStatistic();
149
+ }, refreshInterval * 60000);
150
+ }
142
151
  const {
143
152
  hasUnSaved
144
153
  } = this.props;
@@ -148,19 +157,34 @@ class View extends React.PureComponent {
148
157
  }
149
158
  componentWillUnmount() {
150
159
  this.unsubscribeReFreshChart();
160
+ this.refreshTimer && clearInterval(this.refreshTimer);
151
161
  }
152
162
  UNSAFE_componentWillReceiveProps(nextProps) {
153
163
  const {
154
164
  chart: oldChart,
155
- hasUnSaved
165
+ hasUnSaved,
166
+ version
156
167
  } = this.props;
157
168
  const {
158
169
  chart,
159
- hasUnSaved: nextUnSaved
170
+ hasUnSaved: nextUnSaved,
171
+ version: nextVersion,
172
+ autoRefresh,
173
+ refreshInterval
160
174
  } = nextProps;
161
175
  const {
162
176
  data
163
177
  } = this.state;
178
+
179
+ // after auto_refresh config changed, reset the timer
180
+ if (autoRefresh && refreshInterval) {
181
+ this.refreshTimer && clearInterval(this.refreshTimer);
182
+ this.refreshTimer = setInterval(() => {
183
+ this.calculateStatistic();
184
+ }, refreshInterval * 60000);
185
+ } else {
186
+ this.refreshTimer && clearInterval(this.refreshTimer);
187
+ }
164
188
  context.api = this.props.api;
165
189
 
166
190
  // universal-apps will not trigger calculation of the chart before the chart config saved
@@ -170,7 +194,9 @@ class View extends React.PureComponent {
170
194
  this.calculateStatistic();
171
195
  return;
172
196
  }
173
- if (shallowEqual(chart, oldChart)) return;
197
+
198
+ // version was used to dectect table change in big screen plugin
199
+ if (shallowEqual(chart, oldChart) && version === nextVersion) return;
174
200
  this.setState({
175
201
  isCalculated: false
176
202
  }, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "1.1.30",
3
+ "version": "1.1.32",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",