dtable-statistic 5.0.57 → 5.0.58-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.
- package/es/dashboard.js +0 -9
- package/es/desktop-dashboard.js +2 -0
- package/es/index.js +8 -11
- package/es/locale/index.js +1 -1
- package/package.json +4 -5
- package/es/utils/formula-calc-worker/calc-with-worker.js +0 -85
- package/es/utils/formula-calc-worker/calc.worker.js +0 -18
- package/es/utils/formula-calc-worker/result-cache-manager.js +0 -53
- package/es/utils/formula-calc-worker/thread-manager.js +0 -71
- package/es/utils/hasReactElement.js +0 -37
package/es/dashboard.js
CHANGED
|
@@ -17,7 +17,6 @@ var _mobileDashboard = _interopRequireDefault(require("./mobile-dashboard"));
|
|
|
17
17
|
var _utils = require("./utils");
|
|
18
18
|
var _commonUtils = require("./utils/common-utils");
|
|
19
19
|
var _constants = require("./constants");
|
|
20
|
-
var _threadManager = _interopRequireDefault(require("./utils/formula-calc-worker/thread-manager"));
|
|
21
20
|
require("./locale");
|
|
22
21
|
require("./assets/css/dashboard.css");
|
|
23
22
|
require("./assets/css/theme.css");
|
|
@@ -124,14 +123,9 @@ class DashBoard extends _react.Component {
|
|
|
124
123
|
activeView
|
|
125
124
|
});
|
|
126
125
|
};
|
|
127
|
-
this.cancelCalculation = () => {
|
|
128
|
-
_threadManager.default.clearQueue();
|
|
129
|
-
_threadManager.default.terminateWorkers();
|
|
130
|
-
};
|
|
131
126
|
this.selectDashboard = selectedDashboardIdx => {
|
|
132
127
|
this.disabledUpdateLayout = true;
|
|
133
128
|
this.setSelectedDashboardIdx(selectedDashboardIdx);
|
|
134
|
-
this.cancelCalculation();
|
|
135
129
|
this.setState({
|
|
136
130
|
selectedDashboardIdx
|
|
137
131
|
});
|
|
@@ -164,7 +158,6 @@ class DashBoard extends _react.Component {
|
|
|
164
158
|
});
|
|
165
159
|
const selectedDashboardIdx = updatedStatistics.length - 1;
|
|
166
160
|
this.setSelectedDashboardIdx(selectedDashboardIdx);
|
|
167
|
-
this.cancelCalculation();
|
|
168
161
|
this.updateStatistics({
|
|
169
162
|
statistics: updatedStatistics,
|
|
170
163
|
selectedDashboardIdx
|
|
@@ -203,7 +196,6 @@ class DashBoard extends _react.Component {
|
|
|
203
196
|
}
|
|
204
197
|
});
|
|
205
198
|
this.setSelectedDashboardIdx(nextSelectedDashboardIdx);
|
|
206
|
-
this.cancelCalculation();
|
|
207
199
|
this.updateStatistics({
|
|
208
200
|
statistics: updatedStatistics,
|
|
209
201
|
selectedDashboardIdx: nextSelectedDashboardIdx
|
|
@@ -383,7 +375,6 @@ class DashBoard extends _react.Component {
|
|
|
383
375
|
componentWillUnmount() {
|
|
384
376
|
this.unsubscribeLocalDtableChanged();
|
|
385
377
|
this.unsubscribeRemoteDtableChange();
|
|
386
|
-
this.cancelCalculation();
|
|
387
378
|
}
|
|
388
379
|
render() {
|
|
389
380
|
const {
|
package/es/desktop-dashboard.js
CHANGED
|
@@ -138,6 +138,7 @@ class DesktopDashboard extends _react.Component {
|
|
|
138
138
|
return _dtableDbApi.default.sqlQuery(sql);
|
|
139
139
|
}
|
|
140
140
|
render() {
|
|
141
|
+
var _window$dtable;
|
|
141
142
|
const {
|
|
142
143
|
getValue,
|
|
143
144
|
isTableReadOnly,
|
|
@@ -260,6 +261,7 @@ class DesktopDashboard extends _react.Component {
|
|
|
260
261
|
onToggleEditChart: this.onToggleEditChart
|
|
261
262
|
}), isShowChartAddDialog && /*#__PURE__*/_react.default.createElement(_seaChart.TypesDialog, {
|
|
262
263
|
type: "",
|
|
264
|
+
lang: (_window$dtable = window.dtable) === null || _window$dtable === void 0 ? void 0 : _window$dtable.lang,
|
|
263
265
|
onToggle: this.onToggleAddChart,
|
|
264
266
|
onChange: this.onTypeChange
|
|
265
267
|
}), this.state.isShowColorThemeDialog && /*#__PURE__*/_react.default.createElement(_colorThemeDialog.default, {
|
package/es/index.js
CHANGED
|
@@ -4,8 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
var _react = _interopRequireDefault(require("react"));
|
|
5
5
|
var _dtableStore = require("dtable-store");
|
|
6
6
|
var _dashboard = _interopRequireDefault(require("./dashboard"));
|
|
7
|
-
var _calcWithWorker = require("./utils/formula-calc-worker/calc-with-worker");
|
|
8
|
-
var _resultCacheManager = require("./utils/formula-calc-worker/result-cache-manager");
|
|
9
7
|
class Statistic {
|
|
10
8
|
static getInitProps() {
|
|
11
9
|
if (!window || !window.app) {
|
|
@@ -35,17 +33,16 @@ class Statistic {
|
|
|
35
33
|
deletePluginSettings: this.deletePluginSettings.bind(this, dtableStore)
|
|
36
34
|
};
|
|
37
35
|
}
|
|
38
|
-
static
|
|
36
|
+
static getViewRows(view, table) {
|
|
39
37
|
const dtableStore = window.app.dtableStore || {};
|
|
40
38
|
const {
|
|
41
39
|
username = null,
|
|
42
40
|
userId = null,
|
|
43
41
|
userDepartmentIdsMap = null
|
|
44
42
|
} = dtableStore.dtableSettings;
|
|
45
|
-
|
|
46
|
-
return rows;
|
|
43
|
+
return _dtableStore.Views.getViewRows(view, table, dtableStore.value, username, userId, userDepartmentIdsMap);
|
|
47
44
|
}
|
|
48
|
-
static
|
|
45
|
+
static getTableFormulaResults(table, rows) {
|
|
49
46
|
const dtableStore = window.app.dtableStore || {};
|
|
50
47
|
const {
|
|
51
48
|
username = null,
|
|
@@ -53,8 +50,11 @@ class Statistic {
|
|
|
53
50
|
userDepartmentIdsMap = null
|
|
54
51
|
} = dtableStore.dtableSettings;
|
|
55
52
|
const formulaColumns = _dtableStore.Views.getFormulaColumnsContainLinks(table);
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
return _dtableStore.Views.getTableFormulaResults(table, rows, dtableStore.value, formulaColumns, {
|
|
54
|
+
username,
|
|
55
|
+
userId,
|
|
56
|
+
userDepartmentIdsMap
|
|
57
|
+
});
|
|
58
58
|
}
|
|
59
59
|
static updateStatistics(dtableStore, statistics) {
|
|
60
60
|
dtableStore.updateStatisticsList(statistics);
|
|
@@ -74,9 +74,6 @@ class Statistic {
|
|
|
74
74
|
animation: true
|
|
75
75
|
};
|
|
76
76
|
if (!window.app) return;
|
|
77
|
-
_resultCacheManager.viewRowsCacheManager.clear();
|
|
78
|
-
_resultCacheManager.formulaResultsCacheManager.clear();
|
|
79
|
-
(0, _resultCacheManager.clearCachedBase)();
|
|
80
77
|
window.app.unmountWidget({
|
|
81
78
|
animation
|
|
82
79
|
});
|
package/es/locale/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtable-statistic",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.58-alpha.1",
|
|
4
4
|
"description": "statistics",
|
|
5
5
|
"main": "dist/dtable-statistic.js",
|
|
6
6
|
"author": "seafile",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"react-grid-layout": "^1.2.5",
|
|
19
19
|
"react-intl-universal": "^2.4.8",
|
|
20
20
|
"reactstrap": "8.9.0",
|
|
21
|
-
"sea-chart": "
|
|
21
|
+
"sea-chart": "1.1.0-alpha.5"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"dtable-ui-component": "~5.
|
|
24
|
+
"dtable-ui-component": "~5.0.*",
|
|
25
25
|
"dtable-utils": "~5.0.*"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -53,9 +53,8 @@
|
|
|
53
53
|
"dotenv": "^10.0.0",
|
|
54
54
|
"dotenv-expand": "^5.1.0",
|
|
55
55
|
"dtable-store": "4.3.6",
|
|
56
|
-
"dtable-ui-component": "~5.
|
|
56
|
+
"dtable-ui-component": "~5.0.11",
|
|
57
57
|
"dtable-utils": "5.0.0",
|
|
58
|
-
"dtable-web-api": "^5.0.3",
|
|
59
58
|
"eslint": "^8.3.0",
|
|
60
59
|
"eslint-config-react-app": "^7.0.1",
|
|
61
60
|
"eslint-webpack-plugin": "^3.1.1",
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.calcFormulaResultsWithWorker = calcFormulaResultsWithWorker;
|
|
9
|
-
exports.calcViewRowsWithWorker = calcViewRowsWithWorker;
|
|
10
|
-
var Comlink = _interopRequireWildcard(require("comlink"));
|
|
11
|
-
var _calc = _interopRequireDefault(require("./calc.worker"));
|
|
12
|
-
var _resultCacheManager = require("./result-cache-manager");
|
|
13
|
-
var _threadManager = _interopRequireDefault(require("./thread-manager"));
|
|
14
|
-
var _lodashEs = require("lodash-es");
|
|
15
|
-
function uuid() {
|
|
16
|
-
return Math.random().toString(36).slice(2, 9);
|
|
17
|
-
}
|
|
18
|
-
async function calcViewRowsWithWorker(view, table, value, username, userId, userDepartmentIdsMap) {
|
|
19
|
-
const key = view._id + table._id;
|
|
20
|
-
const cachedRows = _resultCacheManager.viewRowsCacheManager.get(key);
|
|
21
|
-
if (cachedRows) {
|
|
22
|
-
return cachedRows;
|
|
23
|
-
}
|
|
24
|
-
if (!_resultCacheManager.cachedBase) {
|
|
25
|
-
(0, _resultCacheManager.initCachedBase)(value);
|
|
26
|
-
}
|
|
27
|
-
const clonedTable = (0, _lodashEs.cloneDeep)(table);
|
|
28
|
-
// Symbol can't passed to workers
|
|
29
|
-
clonedTable.columns = clonedTable.columns.map(c => {
|
|
30
|
-
delete c.editor;
|
|
31
|
-
delete c.formatter;
|
|
32
|
-
return c;
|
|
33
|
-
});
|
|
34
|
-
const workerId = uuid();
|
|
35
|
-
let worker;
|
|
36
|
-
try {
|
|
37
|
-
worker = await _threadManager.default.applyThread(workerId, _calc.default);
|
|
38
|
-
} catch (e) {
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
const calcWorker = Comlink.wrap(worker);
|
|
42
|
-
const rows = await calcWorker.getViewRows(view, clonedTable, _resultCacheManager.cachedBase, username, userId, userDepartmentIdsMap);
|
|
43
|
-
if (rows && Object.keys(rows).length) {
|
|
44
|
-
_resultCacheManager.viewRowsCacheManager.set(key, rows);
|
|
45
|
-
}
|
|
46
|
-
_threadManager.default.removeThread(workerId);
|
|
47
|
-
return rows;
|
|
48
|
-
}
|
|
49
|
-
async function calcFormulaResultsWithWorker(table, rows, value, formulaColumns, username, userId, userDepartmentIdsMap, viewId) {
|
|
50
|
-
const key = viewId + table._id;
|
|
51
|
-
const cachedResults = _resultCacheManager.formulaResultsCacheManager.get(key);
|
|
52
|
-
if (cachedResults) {
|
|
53
|
-
return cachedResults;
|
|
54
|
-
}
|
|
55
|
-
if (!_resultCacheManager.cachedBase) {
|
|
56
|
-
(0, _resultCacheManager.initCachedBase)(value);
|
|
57
|
-
}
|
|
58
|
-
const clonedTable = (0, _lodashEs.cloneDeep)(table);
|
|
59
|
-
// Symbol can't passed to workers
|
|
60
|
-
clonedTable.columns = clonedTable.columns.map(c => {
|
|
61
|
-
delete c.editor;
|
|
62
|
-
delete c.formatter;
|
|
63
|
-
return c;
|
|
64
|
-
});
|
|
65
|
-
let clonedFormulaColumns = (0, _lodashEs.cloneDeep)(formulaColumns);
|
|
66
|
-
clonedFormulaColumns = clonedFormulaColumns.map(c => {
|
|
67
|
-
delete c.editor;
|
|
68
|
-
delete c.formatter;
|
|
69
|
-
return c;
|
|
70
|
-
});
|
|
71
|
-
const workerId = uuid();
|
|
72
|
-
let worker;
|
|
73
|
-
try {
|
|
74
|
-
worker = await _threadManager.default.applyThread(workerId, _calc.default);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
const calcWorker = Comlink.wrap(worker);
|
|
79
|
-
const results = await calcWorker.getTableFormulaResults(clonedTable, rows, _resultCacheManager.cachedBase, clonedFormulaColumns, username, userId, userDepartmentIdsMap);
|
|
80
|
-
if (results && Object.keys(results).length) {
|
|
81
|
-
_resultCacheManager.formulaResultsCacheManager.set(key, results);
|
|
82
|
-
}
|
|
83
|
-
_threadManager.default.removeThread(workerId);
|
|
84
|
-
return results;
|
|
85
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
var Comlink = _interopRequireWildcard(require("comlink"));
|
|
5
|
-
var _dtableStore = require("dtable-store");
|
|
6
|
-
const workerFunctions = {
|
|
7
|
-
async getViewRows(view, table, value, username, userId, userDepartmentIdsMap) {
|
|
8
|
-
return _dtableStore.Views.getViewRows(view, table, value, username, userId, userDepartmentIdsMap);
|
|
9
|
-
},
|
|
10
|
-
async getTableFormulaResults(table, rows, value, formulaColumns, username, userId, userDepartmentIdsMap) {
|
|
11
|
-
return _dtableStore.Views.getTableFormulaResults(table, rows, value, formulaColumns, {
|
|
12
|
-
username,
|
|
13
|
-
userId,
|
|
14
|
-
userDepartmentIdsMap
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
Comlink.expose(workerFunctions);
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.cachedBase = void 0;
|
|
7
|
-
exports.clearCachedBase = clearCachedBase;
|
|
8
|
-
exports.formulaResultsCacheManager = void 0;
|
|
9
|
-
exports.initCachedBase = initCachedBase;
|
|
10
|
-
exports.viewRowsCacheManager = void 0;
|
|
11
|
-
var _lodashEs = require("lodash-es");
|
|
12
|
-
class ResultCacheManager {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.cache = new Map();
|
|
15
|
-
}
|
|
16
|
-
get(key) {
|
|
17
|
-
return this.cache.get(key);
|
|
18
|
-
}
|
|
19
|
-
set(key, value) {
|
|
20
|
-
this.cache.set(key, value);
|
|
21
|
-
}
|
|
22
|
-
clear() {
|
|
23
|
-
this.cache.clear();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const viewRowsCacheManager = exports.viewRowsCacheManager = new ResultCacheManager();
|
|
27
|
-
const formulaResultsCacheManager = exports.formulaResultsCacheManager = new ResultCacheManager();
|
|
28
|
-
let cachedBase = exports.cachedBase = null;
|
|
29
|
-
function initCachedBase(value) {
|
|
30
|
-
// don't clone rows cause they are really big
|
|
31
|
-
const tableIdRowMap = {};
|
|
32
|
-
value.tables.forEach(t => {
|
|
33
|
-
tableIdRowMap[t._id] = t === null || t === void 0 ? void 0 : t.rows;
|
|
34
|
-
t.rows && delete t.rows;
|
|
35
|
-
});
|
|
36
|
-
const clonedBase = (0, _lodashEs.cloneDeep)(value);
|
|
37
|
-
clonedBase.tables.forEach(t => {
|
|
38
|
-
// delete symbols
|
|
39
|
-
t.columns = t.columns.map(c => {
|
|
40
|
-
delete c.editor;
|
|
41
|
-
delete c.formatter;
|
|
42
|
-
return c;
|
|
43
|
-
});
|
|
44
|
-
t.rows = tableIdRowMap[t._id];
|
|
45
|
-
});
|
|
46
|
-
value.tables.forEach(t => {
|
|
47
|
-
t.rows = tableIdRowMap[t._id];
|
|
48
|
-
});
|
|
49
|
-
exports.cachedBase = cachedBase = clonedBase;
|
|
50
|
-
}
|
|
51
|
-
function clearCachedBase() {
|
|
52
|
-
exports.cachedBase = cachedBase = null;
|
|
53
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
class ThreadManager {
|
|
8
|
-
constructor(threadCount) {
|
|
9
|
-
const supportedThreads = navigator.hardwareConcurrency;
|
|
10
|
-
// prevent the browser from freezing by leaving 3 threads for the main thread
|
|
11
|
-
if (typeof supportedThreads === 'number' && supportedThreads - 3 > 0) {
|
|
12
|
-
this.threadCount = supportedThreads - 3;
|
|
13
|
-
} else {
|
|
14
|
-
this.threadCount = 2;
|
|
15
|
-
}
|
|
16
|
-
this.threadList = [];
|
|
17
|
-
this.queue = [];
|
|
18
|
-
}
|
|
19
|
-
async applyThread(id, workerConstructor) {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
if (this.threadList.length < this.threadCount) {
|
|
22
|
-
const worker = new workerConstructor();
|
|
23
|
-
worker.id = id;
|
|
24
|
-
this.threadList.push(worker);
|
|
25
|
-
resolve(worker);
|
|
26
|
-
} else {
|
|
27
|
-
this.queue.push({
|
|
28
|
-
id,
|
|
29
|
-
emitter: resolve,
|
|
30
|
-
rejector: reject,
|
|
31
|
-
workerConstructor
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
removeThread(id) {
|
|
37
|
-
const index = this.threadList.findIndex(worker => worker.id === id);
|
|
38
|
-
if (index > -1) {
|
|
39
|
-
this.threadList[index] && this.threadList[index].terminate();
|
|
40
|
-
this.threadList.splice(index, 1);
|
|
41
|
-
}
|
|
42
|
-
if (this.queue.length > 0) {
|
|
43
|
-
const {
|
|
44
|
-
id,
|
|
45
|
-
emitter,
|
|
46
|
-
workerConstructor
|
|
47
|
-
} = this.queue.shift();
|
|
48
|
-
const worker = new workerConstructor();
|
|
49
|
-
worker.id = id;
|
|
50
|
-
this.threadList.push(worker);
|
|
51
|
-
emitter(worker);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
clearQueue() {
|
|
55
|
-
this.queue.forEach(_ref => {
|
|
56
|
-
let {
|
|
57
|
-
rejector
|
|
58
|
-
} = _ref;
|
|
59
|
-
return rejector();
|
|
60
|
-
});
|
|
61
|
-
this.queue = [];
|
|
62
|
-
}
|
|
63
|
-
terminateWorkers() {
|
|
64
|
-
this.threadList.forEach(item => {
|
|
65
|
-
item && item.terminate();
|
|
66
|
-
});
|
|
67
|
-
this.threadList = [];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const threadManager = new ThreadManager();
|
|
71
|
-
var _default = exports.default = threadManager;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.containsReactElementSymbol = containsReactElementSymbol;
|
|
7
|
-
const REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
|
8
|
-
function containsReactElementSymbol(obj) {
|
|
9
|
-
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
10
|
-
if (obj === null || typeof obj !== 'object') {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Check if the current object is a React element
|
|
15
|
-
if (obj.$$typeof === REACT_ELEMENT_TYPE) {
|
|
16
|
-
console.log('Parent object containing Symbol(react.element):', parent);
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Recursively check all properties of the object
|
|
21
|
-
for (let key in obj) {
|
|
22
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
23
|
-
if (containsReactElementSymbol(obj[key], obj)) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Check symbol properties as well
|
|
30
|
-
const symbolProperties = Object.getOwnPropertySymbols(obj);
|
|
31
|
-
for (let symbol of symbolProperties) {
|
|
32
|
-
if (containsReactElementSymbol(obj[symbol], obj)) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|