@arcblock/ux 2.1.38 → 2.1.41

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.
@@ -43,7 +43,7 @@ function TableSearch(_ref) {
43
43
  searchPlaceholder,
44
44
  searchAlwaysOpen
45
45
  } = options;
46
- const [inputExpand, setInputExpand] = (0, _react.useState)(searchOpen || false);
46
+ const [inputExpand, setInputExpand] = (0, _react.useState)(!!searchText || searchOpen || false);
47
47
  const [innerSearchText, setInnerSearchText] = (0, _react.useState)('');
48
48
  const inputTimer = (0, _react.useRef)(null);
49
49
  const {
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = Datatable;
7
+ exports.getDurableData = void 0;
7
8
 
8
9
  var _react = require("react");
9
10
 
@@ -31,7 +32,7 @@ var _DatatableContext = require("./DatatableContext");
31
32
 
32
33
  var _jsxRuntime = require("react/jsx-runtime");
33
34
 
34
- const _excluded = ["data", "columns", "locale", "options", "style", "customButtons", "onChange", "loading", "disabled", "stripped", "verticalKeyWidth", "hideTableHeader", "components", "emptyNode"];
35
+ const _excluded = ["data", "columns", "locale", "options", "style", "customButtons", "onChange", "loading", "disabled", "stripped", "verticalKeyWidth", "hideTableHeader", "components", "emptyNode", "durable", "durableKeys"];
35
36
 
36
37
  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); }
37
38
 
@@ -80,7 +81,9 @@ function ReDatatable(_ref2) {
80
81
  verticalKeyWidth,
81
82
  hideTableHeader,
82
83
  components,
83
- emptyNode
84
+ emptyNode,
85
+ durable,
86
+ durableKeys
84
87
  } = _ref2,
85
88
  rest = _objectWithoutProperties(_ref2, _excluded);
86
89
 
@@ -284,43 +287,55 @@ function ReDatatable(_ref2) {
284
287
  }
285
288
 
286
289
  (0, _react.useEffect)(() => setFilterLabel(textLabels.filter.title), [textLabels.filter.title]);
290
+ const durableData = getDurableData(durable);
287
291
 
288
- const opts = _objectSpread({
292
+ const opts = _objectSpread(_objectSpread(_objectSpread({
289
293
  selectableRows: 'none',
290
294
  textLabels,
291
295
  rowsPerPage: 10,
292
296
  rowsPerPageOptions: [10, 20, 50]
293
- }, options);
297
+ }, durableData), options), {}, {
298
+ // Wrap the more friendly onChange callback by listening to onTableChange,
299
+ // which will only be triggered when the table key state changes
300
+ onTableChange: (action, tableState) => {
301
+ if (action === 'propsUpdate') {
302
+ return;
303
+ }
294
304
 
295
- if (onChange) {
296
- Object.assign(opts, {
297
- serverSide: true,
298
- // Wrap the more friendly onChange callback by listening to onTableChange,
299
- // which will only be triggered when the table key state changes
300
- onTableChange: (action, tableState) => {
301
- if (action === 'propsUpdate') {
302
- return;
303
- }
305
+ const state = {
306
+ count: tableState.count,
307
+ page: tableState.page,
308
+ rowsPerPage: tableState.rowsPerPage,
309
+ searchText: tableState.searchText,
310
+ sortOrder: tableState.sortOrder,
311
+ //
312
+ filterList: tableState.filterList
313
+ };
304
314
 
305
- const state = {
306
- count: tableState.count,
307
- page: tableState.page,
308
- rowsPerPage: tableState.rowsPerPage,
309
- searchText: tableState.searchText,
310
- sortOrder: tableState.sortOrder,
311
- //
312
- filterList: tableState.filterList
313
- };
314
- const stateStr = JSON.stringify(state);
315
-
316
- if (stateStr === oldState.current) {
317
- return;
318
- }
315
+ if (durable) {
316
+ const needSaveState = {};
317
+ durableKeys.forEach(key => {
318
+ needSaveState[key] = state[key];
319
+ });
320
+ localStorage.setItem("datatable-durable-".concat(durable), JSON.stringify(needSaveState));
321
+ }
322
+
323
+ const stateStr = JSON.stringify(state);
324
+
325
+ if (stateStr === oldState.current) {
326
+ return;
327
+ }
328
+
329
+ oldState.current = stateStr;
319
330
 
320
- oldState.current = stateStr;
331
+ if (onChange) {
321
332
  onChange(state, action);
322
333
  }
323
- });
334
+ }
335
+ });
336
+
337
+ if (onChange) {
338
+ opts.serverSide = true;
324
339
  }
325
340
 
326
341
  const props = _objectSpread(_objectSpread({
@@ -361,7 +376,9 @@ ReDatatable.propTypes = {
361
376
  verticalKeyWidth: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
362
377
  hideTableHeader: _propTypes.default.bool,
363
378
  components: _propTypes.default.object,
364
- emptyNode: _propTypes.default.node
379
+ emptyNode: _propTypes.default.node,
380
+ durable: _propTypes.default.string,
381
+ durableKeys: _propTypes.default.array
365
382
  };
366
383
  ReDatatable.defaultProps = {
367
384
  options: {},
@@ -375,8 +392,27 @@ ReDatatable.defaultProps = {
375
392
  verticalKeyWidth: '',
376
393
  hideTableHeader: false,
377
394
  components: {},
378
- emptyNode: ''
395
+ emptyNode: '',
396
+ durable: '',
397
+ durableKeys: ['page', 'rowsPerPage', 'searchText', 'sortOrder']
379
398
  };
399
+
400
+ const getDurableData = key => {
401
+ const durableKey = "datatable-durable-".concat(key);
402
+ let localData = localStorage[durableKey];
403
+
404
+ if (localData) {
405
+ try {
406
+ localData = JSON.parse(localData);
407
+ } catch (err) {
408
+ console.error("parse durable data error (key:".concat(key, ") => "), err);
409
+ }
410
+ }
411
+
412
+ return localData || {};
413
+ };
414
+
415
+ exports.getDurableData = getDurableData;
380
416
  const alignCss = (0, _styledComponents.css)([".MuiTableCell-head{[class*='MUIDataTableHeadCell-toolButton']{width:100%;> [class*='MUIDataTableHeadCell-sortAction']{width:100%;}}&.pc-align-center{text-align:center;[class*='MUIDataTableHeadCell-toolButton'] > [class*='MUIDataTableHeadCell-sortAction']{justify-content:center;}}&.pc-align-right{text-align:right;[class*='MUIDataTableHeadCell-toolButton']{margin-right:0;padding-right:0;& > [class*='MUIDataTableHeadCell-sortAction']{justify-content:flex-end;}}}}.MuiTableCell-body{&.pc-align-center{text-align:center;}&.pc-align-right{text-align:right;}}"]);
381
417
 
382
418
  const TableContainer = _styledComponents.default.div.withConfig({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.1.38",
3
+ "version": "2.1.41",
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": "fe155dec83163a19c97ce7e15c6c40e846456498",
55
+ "gitHead": "25763a7a35fdb64d13e9871c3f2590868939a43f",
56
56
  "dependencies": {
57
- "@arcblock/icons": "^2.1.38",
58
- "@arcblock/react-hooks": "^2.1.38",
57
+ "@arcblock/icons": "^2.1.41",
58
+ "@arcblock/react-hooks": "^2.1.41",
59
59
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
60
60
  "@emotion/react": "^11.9.0",
61
61
  "@emotion/styled": "^11.8.1",
@@ -11,7 +11,7 @@ import { useDatatableContext } from './DatatableContext';
11
11
 
12
12
  export default function TableSearch({ search, options, searchText, searchTextUpdate, searchClose, onSearchOpen }) {
13
13
  const { searchOpen, searchPlaceholder, searchAlwaysOpen } = options;
14
- const [inputExpand, setInputExpand] = useState(searchOpen || false);
14
+ const [inputExpand, setInputExpand] = useState(!!searchText || searchOpen || false);
15
15
  const [innerSearchText, setInnerSearchText] = useState('');
16
16
  const inputTimer = useRef(null);
17
17
  const { loading } = useDatatableContext();
@@ -42,6 +42,8 @@ function ReDatatable({
42
42
  hideTableHeader,
43
43
  components,
44
44
  emptyNode,
45
+ durable,
46
+ durableKeys,
45
47
  ...rest
46
48
  }) {
47
49
  const oldState = useRef(null);
@@ -216,39 +218,53 @@ function ReDatatable({
216
218
 
217
219
  useEffect(() => setFilterLabel(textLabels.filter.title), [textLabels.filter.title]);
218
220
 
221
+ const durableData = getDurableData(durable);
222
+
219
223
  const opts = {
220
224
  selectableRows: 'none',
221
225
  textLabels,
222
226
  rowsPerPage: 10,
223
227
  rowsPerPageOptions: [10, 20, 50],
228
+ ...durableData,
224
229
  ...options,
230
+ // Wrap the more friendly onChange callback by listening to onTableChange,
231
+ // which will only be triggered when the table key state changes
232
+ onTableChange: (action, tableState) => {
233
+ if (action === 'propsUpdate') {
234
+ return;
235
+ }
236
+ const state = {
237
+ count: tableState.count,
238
+ page: tableState.page,
239
+ rowsPerPage: tableState.rowsPerPage,
240
+ searchText: tableState.searchText,
241
+ sortOrder: tableState.sortOrder, //
242
+ filterList: tableState.filterList,
243
+ };
244
+
245
+ if (durable) {
246
+ const needSaveState = {};
247
+
248
+ durableKeys.forEach((key) => {
249
+ needSaveState[key] = state[key];
250
+ });
251
+
252
+ localStorage.setItem(`datatable-durable-${durable}`, JSON.stringify(needSaveState));
253
+ }
254
+
255
+ const stateStr = JSON.stringify(state);
256
+ if (stateStr === oldState.current) {
257
+ return;
258
+ }
259
+ oldState.current = stateStr;
260
+ if (onChange) {
261
+ onChange(state, action);
262
+ }
263
+ },
225
264
  };
226
265
 
227
266
  if (onChange) {
228
- Object.assign(opts, {
229
- serverSide: true,
230
- // Wrap the more friendly onChange callback by listening to onTableChange,
231
- // which will only be triggered when the table key state changes
232
- onTableChange: (action, tableState) => {
233
- if (action === 'propsUpdate') {
234
- return;
235
- }
236
- const state = {
237
- count: tableState.count,
238
- page: tableState.page,
239
- rowsPerPage: tableState.rowsPerPage,
240
- searchText: tableState.searchText,
241
- sortOrder: tableState.sortOrder, //
242
- filterList: tableState.filterList,
243
- };
244
- const stateStr = JSON.stringify(state);
245
- if (stateStr === oldState.current) {
246
- return;
247
- }
248
- oldState.current = stateStr;
249
- onChange(state, action);
250
- },
251
- });
267
+ opts.serverSide = true;
252
268
  }
253
269
 
254
270
  const props = {
@@ -290,6 +306,8 @@ ReDatatable.propTypes = {
290
306
  hideTableHeader: PropTypes.bool,
291
307
  components: PropTypes.object,
292
308
  emptyNode: PropTypes.node,
309
+ durable: PropTypes.string,
310
+ durableKeys: PropTypes.array,
293
311
  };
294
312
 
295
313
  ReDatatable.defaultProps = {
@@ -305,6 +323,21 @@ ReDatatable.defaultProps = {
305
323
  hideTableHeader: false,
306
324
  components: {},
307
325
  emptyNode: '',
326
+ durable: '',
327
+ durableKeys: ['page', 'rowsPerPage', 'searchText', 'sortOrder'],
328
+ };
329
+
330
+ export const getDurableData = (key) => {
331
+ const durableKey = `datatable-durable-${key}`;
332
+ let localData = localStorage[durableKey];
333
+ if (localData) {
334
+ try {
335
+ localData = JSON.parse(localData);
336
+ } catch (err) {
337
+ console.error(`parse durable data error (key:${key}) => `, err);
338
+ }
339
+ }
340
+ return localData || {};
308
341
  };
309
342
 
310
343
  const alignCss = css`