@arcblock/ux 2.1.6 → 2.1.9
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/lib/Datatable/CustomToolbar.js +350 -0
- package/lib/Datatable/DatatableContext.js +47 -0
- package/lib/Datatable/TableSearch.js +98 -0
- package/lib/Datatable/index.js +338 -0
- package/lib/Datatable/utils.js +154 -0
- package/lib/Layout/dashboard/header.js +1 -1
- package/lib/Layout/dashboard/index.js +1 -1
- package/lib/index.js +8 -0
- package/package.json +5 -4
- package/src/Datatable/CustomToolbar.js +406 -0
- package/src/Datatable/DatatableContext.js +32 -0
- package/src/Datatable/TableSearch.js +130 -0
- package/src/Datatable/index.js +314 -0
- package/src/Datatable/utils.js +165 -0
- package/src/Layout/dashboard/header.js +1 -1
- package/src/Layout/dashboard/index.js +1 -1
- package/src/index.js +2 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = Datatable;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _muiDatatables = _interopRequireWildcard(require("mui-datatables"));
|
|
13
|
+
|
|
14
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
15
|
+
|
|
16
|
+
var _isObject = _interopRequireDefault(require("lodash/isObject"));
|
|
17
|
+
|
|
18
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
19
|
+
|
|
20
|
+
var _CustomToolbar = _interopRequireDefault(require("./CustomToolbar"));
|
|
21
|
+
|
|
22
|
+
var _DatatableContext = require("./DatatableContext");
|
|
23
|
+
|
|
24
|
+
const _excluded = ["data", "columns", "locale", "options", "style", "customButtons", "onChange", "loading", "disabled"];
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
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; }
|
|
41
|
+
|
|
42
|
+
function Datatable(_ref) {
|
|
43
|
+
let props = Object.assign({}, _ref);
|
|
44
|
+
return /*#__PURE__*/_react.default.createElement(_DatatableContext.DatatableProvide, null, /*#__PURE__*/_react.default.createElement(ReDatatable, props));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @param {Object} props.options The options of mui-datatable,detail see https://github.com/gregnb/mui-datatables/tree/b8d2eee6af4589d254b40918e5d7e70b1ee4baca
|
|
48
|
+
* @param {Array} props.customButtons Custom buttons for toolbar
|
|
49
|
+
* @param {Function} props.onChange When onChange is present, serverSide mode is activated by default https://github.com/gregnb/mui-datatables/tree/b8d2eee6af4589d254b40918e5d7e70b1ee4baca#remote-data
|
|
50
|
+
* @param {Boolean} props.loading For dynamic data, usually used with onChange
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function ReDatatable(_ref2) {
|
|
56
|
+
let {
|
|
57
|
+
data: originData,
|
|
58
|
+
columns: originColumns,
|
|
59
|
+
locale,
|
|
60
|
+
options,
|
|
61
|
+
style,
|
|
62
|
+
customButtons,
|
|
63
|
+
onChange,
|
|
64
|
+
loading,
|
|
65
|
+
disabled
|
|
66
|
+
} = _ref2,
|
|
67
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
68
|
+
|
|
69
|
+
const container = (0, _react.useRef)(null);
|
|
70
|
+
const oldState = (0, _react.useRef)(null);
|
|
71
|
+
const {
|
|
72
|
+
setCustomButtons,
|
|
73
|
+
setFilterLabel,
|
|
74
|
+
setLoading,
|
|
75
|
+
setDisabled
|
|
76
|
+
} = (0, _DatatableContext.useDatatableContext)();
|
|
77
|
+
const disabledCellStyle = {
|
|
78
|
+
cursor: 'not-allowed',
|
|
79
|
+
pointerEvents: 'none'
|
|
80
|
+
};
|
|
81
|
+
const keys = []; // Convert Columns fields to object sets to support the width function
|
|
82
|
+
|
|
83
|
+
const columns = originColumns.map(e => {
|
|
84
|
+
let tempObj;
|
|
85
|
+
|
|
86
|
+
if (!(0, _isObject.default)(e)) {
|
|
87
|
+
tempObj = {
|
|
88
|
+
label: e,
|
|
89
|
+
name: e
|
|
90
|
+
};
|
|
91
|
+
} else {
|
|
92
|
+
tempObj = (0, _cloneDeep.default)(e);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
keys.push(tempObj.name);
|
|
96
|
+
|
|
97
|
+
if (!tempObj.options) {
|
|
98
|
+
tempObj.options = {};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
setCellHeaderProps
|
|
103
|
+
} = tempObj.options;
|
|
104
|
+
|
|
105
|
+
tempObj.options.setCellHeaderProps = columnMeta => {
|
|
106
|
+
let cellProps = {}; // Complementing width while inheriting old setCellHeaderProps
|
|
107
|
+
|
|
108
|
+
if (setCellHeaderProps && !setCellHeaderProps.__innerFunc) {
|
|
109
|
+
cellProps = setCellHeaderProps(columnMeta) || {};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (loading || disabled) {
|
|
113
|
+
cellProps = _objectSpread(_objectSpread({}, cellProps), {}, {
|
|
114
|
+
style: disabledCellStyle
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (tempObj.width) {
|
|
119
|
+
cellProps.width = tempObj.width;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return cellProps;
|
|
123
|
+
}; // Prevent memory xie caused by recursive forwarding of setCellHeaderProps functions
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
tempObj.options.setCellHeaderProps.__innerFunc = 1;
|
|
127
|
+
return tempObj;
|
|
128
|
+
}); // Fixing object-type structures
|
|
129
|
+
|
|
130
|
+
const data = originData.map(e => {
|
|
131
|
+
if (!Array.isArray(e) && (0, _isObject.default)(e)) {
|
|
132
|
+
return keys.map(key => e[key]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return e;
|
|
136
|
+
});
|
|
137
|
+
(0, _react.useEffect)(() => setCustomButtons(customButtons || []), [customButtons]);
|
|
138
|
+
(0, _react.useEffect)(() => setLoading(loading), [loading]);
|
|
139
|
+
(0, _react.useEffect)(() => setDisabled(disabled), [disabled]);
|
|
140
|
+
let textLabels = {
|
|
141
|
+
body: {
|
|
142
|
+
noMatch: 'Sorry, no matching records found',
|
|
143
|
+
toolTip: 'Sort'
|
|
144
|
+
},
|
|
145
|
+
pagination: {
|
|
146
|
+
next: 'Next Page',
|
|
147
|
+
previous: 'Previous Page',
|
|
148
|
+
rowsPerPage: 'Rows per page:',
|
|
149
|
+
displayRows: 'of',
|
|
150
|
+
jumpToPage: 'Jump to Page:'
|
|
151
|
+
},
|
|
152
|
+
toolbar: {
|
|
153
|
+
search: 'Search',
|
|
154
|
+
downloadCsv: 'Download CSV',
|
|
155
|
+
print: 'Print',
|
|
156
|
+
viewColumns: 'View Columns',
|
|
157
|
+
filterTable: 'Filter Table'
|
|
158
|
+
},
|
|
159
|
+
filter: {
|
|
160
|
+
all: 'All',
|
|
161
|
+
title: 'FILTERS',
|
|
162
|
+
reset: 'RESET'
|
|
163
|
+
},
|
|
164
|
+
viewColumns: {
|
|
165
|
+
title: 'Show Columns',
|
|
166
|
+
titleAria: 'Show/Hide Table Columns'
|
|
167
|
+
},
|
|
168
|
+
selectedRows: {
|
|
169
|
+
text: 'row(s) selected',
|
|
170
|
+
delete: 'Delete',
|
|
171
|
+
deleteAria: 'Delete Selected Rows'
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
if (locale === 'zh') {
|
|
176
|
+
textLabels = {
|
|
177
|
+
body: {
|
|
178
|
+
noMatch: '对不起,没有找到匹配的记录',
|
|
179
|
+
toolTip: '排序'
|
|
180
|
+
},
|
|
181
|
+
pagination: {
|
|
182
|
+
next: '下一页',
|
|
183
|
+
previous: '上一页',
|
|
184
|
+
rowsPerPage: '每页行数',
|
|
185
|
+
displayRows: '/',
|
|
186
|
+
jumpToPage: '跳转到页面:'
|
|
187
|
+
},
|
|
188
|
+
toolbar: {
|
|
189
|
+
search: '搜索',
|
|
190
|
+
downloadCsv: '下载CSV',
|
|
191
|
+
print: '打印',
|
|
192
|
+
viewColumns: '查看列',
|
|
193
|
+
filterTable: '筛选表格'
|
|
194
|
+
},
|
|
195
|
+
filter: {
|
|
196
|
+
all: '全部',
|
|
197
|
+
title: '筛选器',
|
|
198
|
+
reset: '重置'
|
|
199
|
+
},
|
|
200
|
+
viewColumns: {
|
|
201
|
+
title: '显示的列',
|
|
202
|
+
titleAria: '显示/隐藏 表格的列'
|
|
203
|
+
},
|
|
204
|
+
selectedRows: {
|
|
205
|
+
text: '个已选项目',
|
|
206
|
+
delete: '删除',
|
|
207
|
+
deleteAria: '删除所选项目'
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
(0, _react.useEffect)(() => setFilterLabel(textLabels.filter.title), [textLabels.filter.title]);
|
|
213
|
+
|
|
214
|
+
const opts = _objectSpread({
|
|
215
|
+
selectableRows: 'none',
|
|
216
|
+
textLabels,
|
|
217
|
+
rowsPerPage: 10,
|
|
218
|
+
rowsPerPageOptions: [10, 20, 50]
|
|
219
|
+
}, options);
|
|
220
|
+
|
|
221
|
+
if (onChange) {
|
|
222
|
+
Object.assign(opts, {
|
|
223
|
+
serverSide: true,
|
|
224
|
+
// Wrap the more friendly onChange callback by listening to onTableChange,
|
|
225
|
+
// which will only be triggered when the table key state changes
|
|
226
|
+
onTableChange: (action, tableState) => {
|
|
227
|
+
if (action === 'propsUpdate') {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const state = {
|
|
232
|
+
count: tableState.count,
|
|
233
|
+
page: tableState.page,
|
|
234
|
+
rowsPerPage: tableState.rowsPerPage,
|
|
235
|
+
searchText: tableState.searchText,
|
|
236
|
+
sortOrder: tableState.sortOrder,
|
|
237
|
+
//
|
|
238
|
+
filterList: tableState.filterList
|
|
239
|
+
};
|
|
240
|
+
const stateStr = JSON.stringify(state);
|
|
241
|
+
|
|
242
|
+
if (stateStr === oldState.current) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
oldState.current = stateStr;
|
|
247
|
+
onChange(state, action);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const props = _objectSpread(_objectSpread({
|
|
253
|
+
options: opts
|
|
254
|
+
}, rest), {}, {
|
|
255
|
+
components: {
|
|
256
|
+
TableToolbar: _CustomToolbar.default,
|
|
257
|
+
TableFooter: WrapTableFooter,
|
|
258
|
+
TableFilterList: WrapFilterList
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
ReDatatable.propTypes = {
|
|
263
|
+
data: _propTypes.default.array.isRequired,
|
|
264
|
+
columns: _propTypes.default.array.isRequired,
|
|
265
|
+
options: _propTypes.default.object,
|
|
266
|
+
style: _propTypes.default.object,
|
|
267
|
+
locale: _propTypes.default.string,
|
|
268
|
+
loading: _propTypes.default.bool,
|
|
269
|
+
disabled: _propTypes.default.bool,
|
|
270
|
+
customButtons: _propTypes.default.array,
|
|
271
|
+
onChange: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string])
|
|
272
|
+
};
|
|
273
|
+
ReDatatable.defaultProps = {
|
|
274
|
+
options: {},
|
|
275
|
+
style: {},
|
|
276
|
+
locale: 'en',
|
|
277
|
+
loading: false,
|
|
278
|
+
disabled: false,
|
|
279
|
+
customButtons: [],
|
|
280
|
+
onChange: ''
|
|
281
|
+
};
|
|
282
|
+
return /*#__PURE__*/_react.default.createElement(TableContainer, {
|
|
283
|
+
ref: container,
|
|
284
|
+
style: style
|
|
285
|
+
}, /*#__PURE__*/_react.default.createElement(_muiDatatables.default, Object.assign({
|
|
286
|
+
data: data,
|
|
287
|
+
columns: columns
|
|
288
|
+
}, props)));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const TableContainer = _styledComponents.default.div.withConfig({
|
|
292
|
+
displayName: "Datatable__TableContainer",
|
|
293
|
+
componentId: "sc-1ju12vq-0"
|
|
294
|
+
})(["height:100%;> .MuiPaper-root{display:flex;flex-direction:column;height:100%;box-shadow:none;}", "{[class*='MUIDataTableBody-emptyTitle']{padding-left:16px;width:200%;margin-left:-100%;text-align:center;}}"], props => props.theme.breakpoints.down('md'));
|
|
295
|
+
|
|
296
|
+
const FilterLine = _styledComponents.default.div.withConfig({
|
|
297
|
+
displayName: "Datatable__FilterLine",
|
|
298
|
+
componentId: "sc-1ju12vq-1"
|
|
299
|
+
})(["display:flex;align-items:center;.toolbar-filter-content{margin-bottom:8px;}.toolbar-filter-title{font-weight:700;font-size:14px;}"]);
|
|
300
|
+
|
|
301
|
+
const WrapFilterList = props => {
|
|
302
|
+
const {
|
|
303
|
+
filterLabel
|
|
304
|
+
} = (0, _DatatableContext.useDatatableContext)();
|
|
305
|
+
const hasFilter = !!props.filterList.filter(e => e.length).length;
|
|
306
|
+
|
|
307
|
+
if (hasFilter) {
|
|
308
|
+
return /*#__PURE__*/_react.default.createElement(FilterLine, null, hasFilter && /*#__PURE__*/_react.default.createElement("div", {
|
|
309
|
+
className: "toolbar-filter-title"
|
|
310
|
+
}, filterLabel), /*#__PURE__*/_react.default.createElement("div", {
|
|
311
|
+
className: "toolbar-filter-content"
|
|
312
|
+
}, /*#__PURE__*/_react.default.createElement(_muiDatatables.TableFilterList, props)));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return '';
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
WrapFilterList.propTypes = {
|
|
319
|
+
filterList: _propTypes.default.array
|
|
320
|
+
};
|
|
321
|
+
WrapFilterList.defaultProps = {
|
|
322
|
+
filterList: []
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const WrapTableFooter = props => {
|
|
326
|
+
const {
|
|
327
|
+
loading,
|
|
328
|
+
disabled
|
|
329
|
+
} = (0, _DatatableContext.useDatatableContext)();
|
|
330
|
+
return /*#__PURE__*/_react.default.createElement(FooterContainer, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
331
|
+
className: "datatable-footer ".concat(loading || disabled ? 'datatable-footer-disabled' : '')
|
|
332
|
+
}, /*#__PURE__*/_react.default.createElement(_muiDatatables.TableFooter, props)));
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const FooterContainer = _styledComponents.default.div.withConfig({
|
|
336
|
+
displayName: "Datatable__FooterContainer",
|
|
337
|
+
componentId: "sc-1ju12vq-2"
|
|
338
|
+
})(["display:flex;align-items:center;.datatable-footer{position:relative;margin-left:auto;&.datatable-footer-disabled{position:relative;.MuiTablePagination-root{opacity:0.6;}&:after{position:absolute;display:block;z-index:2;width:100%;height:100%;left:0;top:0;content:'';cursor:not-allowed;}}}"]);
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.handleCSVDownload = handleCSVDownload;
|
|
8
|
+
|
|
9
|
+
var _find = _interopRequireDefault(require("lodash/find"));
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
function escapeDangerousCSVCharacters(data) {
|
|
14
|
+
if (typeof data === 'string') {
|
|
15
|
+
// Places single quote before the appearance of dangerous characters if they
|
|
16
|
+
// are the first in the data string.
|
|
17
|
+
// eslint-disable-next-line no-useless-escape
|
|
18
|
+
return data.replace(/^\+|^\-|^\=|^\@/g, "'$&");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function buildCSV(columns, data, options) {
|
|
25
|
+
const replaceDoubleQuoteInString = columnData => typeof columnData === 'string' ? columnData.replace(/"/g, '""') : columnData; // eslint-disable-next-line no-shadow
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const buildHead = columns => {
|
|
29
|
+
return "".concat(columns.reduce((soFar, column) => column.download ? "".concat(soFar, "\"").concat(escapeDangerousCSVCharacters(replaceDoubleQuoteInString(column.label || column.name)), "\"").concat(options.downloadOptions.separator) : soFar, '').slice(0, -1), "\r\n");
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const CSVHead = buildHead(columns); // eslint-disable-next-line no-shadow
|
|
33
|
+
|
|
34
|
+
const buildBody = data => {
|
|
35
|
+
if (!data.length) return '';
|
|
36
|
+
return data.reduce((soFar, row) => "".concat(soFar, "\"").concat(row.data.filter((_, index) => columns[index].download).map(columnData => escapeDangerousCSVCharacters(replaceDoubleQuoteInString(columnData))).join("\"".concat(options.downloadOptions.separator, "\"")), "\"\r\n"), '').trim();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const CSVBody = buildBody(data);
|
|
40
|
+
const csv = options.onDownload ? options.onDownload(buildHead, buildBody, columns, data) : "".concat(CSVHead).concat(CSVBody).trim();
|
|
41
|
+
return csv;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function downloadCSV(csv, filename) {
|
|
45
|
+
const blob = new Blob([csv], {
|
|
46
|
+
type: 'text/csv'
|
|
47
|
+
});
|
|
48
|
+
/* taken from react-csv */
|
|
49
|
+
|
|
50
|
+
if (navigator && navigator.msSaveOrOpenBlob) {
|
|
51
|
+
navigator.msSaveOrOpenBlob(blob, filename);
|
|
52
|
+
} else {
|
|
53
|
+
const dataURI = "data:text/csv;charset=utf-8,".concat(csv);
|
|
54
|
+
const URL = window.URL || window.webkitURL;
|
|
55
|
+
const downloadURI = typeof URL.createObjectURL === 'undefined' ? dataURI : URL.createObjectURL(blob);
|
|
56
|
+
const link = document.createElement('a');
|
|
57
|
+
link.setAttribute('href', downloadURI);
|
|
58
|
+
link.setAttribute('download', filename);
|
|
59
|
+
document.body.appendChild(link);
|
|
60
|
+
link.click();
|
|
61
|
+
document.body.removeChild(link);
|
|
62
|
+
}
|
|
63
|
+
} // eslint-disable-next-line no-shadow
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
function createCSVDownload(columns, data, options, downloadCSV) {
|
|
67
|
+
const csv = buildCSV(columns, data, options);
|
|
68
|
+
|
|
69
|
+
if (options.onDownload && csv === false) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
downloadCSV(csv, options.downloadOptions.filename);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function handleCSVDownload(props) {
|
|
77
|
+
const {
|
|
78
|
+
data,
|
|
79
|
+
displayData,
|
|
80
|
+
columns,
|
|
81
|
+
options,
|
|
82
|
+
columnOrder
|
|
83
|
+
} = props;
|
|
84
|
+
let dataToDownload = [];
|
|
85
|
+
let columnsToDownload = [];
|
|
86
|
+
let columnOrderCopy = Array.isArray(columnOrder) ? columnOrder.slice(0) : [];
|
|
87
|
+
|
|
88
|
+
if (columnOrderCopy.length === 0) {
|
|
89
|
+
columnOrderCopy = columns.map((item, idx) => idx);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
data.forEach(row => {
|
|
93
|
+
const newRow = {
|
|
94
|
+
index: row.index,
|
|
95
|
+
data: []
|
|
96
|
+
};
|
|
97
|
+
columnOrderCopy.forEach(idx => {
|
|
98
|
+
newRow.data.push(row.data[idx]);
|
|
99
|
+
});
|
|
100
|
+
dataToDownload.push(newRow);
|
|
101
|
+
});
|
|
102
|
+
columnOrderCopy.forEach(idx => {
|
|
103
|
+
columnsToDownload.push(columns[idx]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (options.downloadOptions && options.downloadOptions.filterOptions) {
|
|
107
|
+
// check rows first:
|
|
108
|
+
if (options.downloadOptions.filterOptions.useDisplayedRowsOnly) {
|
|
109
|
+
const filteredDataToDownload = displayData.map((row, index) => {
|
|
110
|
+
let i = -1; // Help to preserve sort order in custom render columns
|
|
111
|
+
|
|
112
|
+
row.index = index;
|
|
113
|
+
return {
|
|
114
|
+
data: row.data.map(column => {
|
|
115
|
+
i += 1; // if we have a custom render, which will appear as a react element, we must grab the actual value from data
|
|
116
|
+
// that matches the dataIndex and column
|
|
117
|
+
// TODO: Create a utility function for checking whether or not something is a react object
|
|
118
|
+
|
|
119
|
+
let val = typeof column === 'object' && column !== null && !Array.isArray(column) ? (0, _find.default)(data, d => d.index === row.dataIndex).data[i] : column;
|
|
120
|
+
val = typeof val === 'function' ? (0, _find.default)(data, d => d.index === row.dataIndex).data[i] : val;
|
|
121
|
+
return val;
|
|
122
|
+
})
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
dataToDownload = [];
|
|
126
|
+
filteredDataToDownload.forEach(row => {
|
|
127
|
+
const newRow = {
|
|
128
|
+
index: row.index,
|
|
129
|
+
data: []
|
|
130
|
+
};
|
|
131
|
+
columnOrderCopy.forEach(idx => {
|
|
132
|
+
newRow.data.push(row.data[idx]);
|
|
133
|
+
});
|
|
134
|
+
dataToDownload.push(newRow);
|
|
135
|
+
});
|
|
136
|
+
} // now, check columns:
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if (options.downloadOptions.filterOptions.useDisplayedColumnsOnly) {
|
|
140
|
+
columnsToDownload = columnsToDownload.filter(_ => _.display === 'true');
|
|
141
|
+
dataToDownload = dataToDownload.map(row => {
|
|
142
|
+
row.data = row.data.filter((_, index) => columns[columnOrderCopy[index]].display === 'true');
|
|
143
|
+
return row;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
createCSVDownload(columnsToDownload, dataToDownload, options, downloadCSV);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var _default = {
|
|
152
|
+
handleCSVDownload
|
|
153
|
+
};
|
|
154
|
+
exports.default = _default;
|
|
@@ -108,7 +108,7 @@ Header.propTypes = {
|
|
|
108
108
|
onToggleMenu: _propTypes.default.func.isRequired,
|
|
109
109
|
brand: _propTypes.default.string.isRequired,
|
|
110
110
|
brandAddon: _propTypes.default.object,
|
|
111
|
-
description: _propTypes.default.
|
|
111
|
+
description: _propTypes.default.any.isRequired,
|
|
112
112
|
children: _propTypes.default.any,
|
|
113
113
|
addons: _propTypes.default.any,
|
|
114
114
|
homeUrl: _propTypes.default.string,
|
|
@@ -131,7 +131,7 @@ Dashboard.propTypes = {
|
|
|
131
131
|
links: _propTypes.default.array.isRequired,
|
|
132
132
|
images: _propTypes.default.object.isRequired,
|
|
133
133
|
brandAddon: _propTypes.default.object,
|
|
134
|
-
description: _propTypes.default.
|
|
134
|
+
description: _propTypes.default.any.isRequired,
|
|
135
135
|
headerAddon: _propTypes.default.any,
|
|
136
136
|
prefix: _propTypes.default.string,
|
|
137
137
|
// 兼容旧版的设置,新版使用 fullWidth 进行设置
|
package/lib/index.js
CHANGED
|
@@ -69,6 +69,12 @@ Object.defineProperty(exports, "CountDown", {
|
|
|
69
69
|
return _CountDown.default;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
+
Object.defineProperty(exports, "Datatable", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function get() {
|
|
75
|
+
return _Datatable.default;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
72
78
|
Object.defineProperty(exports, "Earth", {
|
|
73
79
|
enumerable: true,
|
|
74
80
|
get: function get() {
|
|
@@ -230,6 +236,8 @@ var _Logo = _interopRequireDefault(require("./Logo"));
|
|
|
230
236
|
|
|
231
237
|
var _RelativeTime = _interopRequireDefault(require("./RelativeTime"));
|
|
232
238
|
|
|
239
|
+
var _Datatable = _interopRequireDefault(require("./Datatable"));
|
|
240
|
+
|
|
233
241
|
var _Tabs = _interopRequireDefault(require("./Tabs"));
|
|
234
242
|
|
|
235
243
|
var _Tag = _interopRequireDefault(require("./Tag"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"react": ">=18.1.0",
|
|
53
53
|
"react-ga": "^2.7.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "7a3efb456e1dbe3318ab8757feb9e58a88c08d8e",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/icons": "^2.1.
|
|
58
|
-
"@arcblock/react-hooks": "^2.1.
|
|
57
|
+
"@arcblock/icons": "^2.1.9",
|
|
58
|
+
"@arcblock/react-hooks": "^2.1.9",
|
|
59
59
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
60
60
|
"@emotion/react": "^11.9.0",
|
|
61
61
|
"@emotion/styled": "^11.8.1",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"js-cookie": "^2.2.0",
|
|
76
76
|
"lodash": "^4.17.21",
|
|
77
77
|
"mdi-material-ui": "^7.2.0",
|
|
78
|
+
"mui-datatables": "^4.2.2",
|
|
78
79
|
"notistack": "^2.0.5",
|
|
79
80
|
"react-cookie-consent": "^6.4.1",
|
|
80
81
|
"react-helmet": "^6.1.0",
|