@insticc/react-datagrid-2 1.1.25 → 1.1.27

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.
@@ -144,7 +144,7 @@ var DataGrid = function DataGrid(_ref) {
144
144
  // get the selected rows (if is a int that means that the row is selected if is a double that means that is a subrow)
145
145
  // so if is a subrow we need to go to the parent row and get the id that is on the position after the .
146
146
  // 308.1 this is a subrow so we need to get the 308 row and get the id of the subrow that is in the position 1 of the array
147
- var getSelectedRows = function getSelectedRows(rows) {
147
+ var getSelectedRows = (0, _react.useCallback)(function (rows) {
148
148
  var data = createRows;
149
149
  return Object.keys(rows).filter(function (key) {
150
150
  return rows[key];
@@ -167,7 +167,7 @@ var DataGrid = function DataGrid(_ref) {
167
167
  }).filter(function (row) {
168
168
  return row;
169
169
  });
170
- };
170
+ }, [createRows]);
171
171
 
172
172
  // implemented to update selectedIds when props change
173
173
  (0, _react.useEffect)(function () {
@@ -184,27 +184,6 @@ var DataGrid = function DataGrid(_ref) {
184
184
  setRowSelection(newSelection);
185
185
  }
186
186
  }, [selectedIds]);
187
- (0, _react.useEffect)(function () {
188
- if (hasSubRows) {
189
- if (Object.keys(rowSelection).length > 0) {
190
- selectData(getSelectedRows(rowSelection));
191
- }
192
- } else {
193
- // DEPRECATED:
194
- // selectData(table.getSelectedRowModel().rows.map(row => row.original));
195
-
196
- var selectedRowIds = Object.keys(table.getState().rowSelection);
197
- var selectedRows = selectedRowIds.map(function (rowId) {
198
- var matchingRow = table.getSelectedRowModel().rows.find(function (row) {
199
- return "".concat(row.id) === rowId;
200
- });
201
- return matchingRow ? matchingRow.original : null; // Return original if found
202
- }).filter(function (row) {
203
- return row !== null;
204
- }); // Filter out any null values
205
- selectData(selectedRows);
206
- }
207
- }, [rowSelection]);
208
187
  (0, _react.useEffect)(function () {
209
188
  if (typeof window !== 'undefined') {
210
189
  setIsLoading(false);
@@ -294,23 +273,20 @@ var DataGrid = function DataGrid(_ref) {
294
273
  flexWrap: 'wrap'
295
274
  },
296
275
  children: (actions === null || actions === void 0 ? void 0 : actions.length) > 0 && actions.map(function (e) {
297
- var isVisible = e.visible !== undefined ? e.visible : true;
298
- if (isVisible) {
299
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton["default"], {
300
- table: table,
301
- toggle: e.toggle,
302
- active: e.active,
303
- name: e.name,
304
- tooltip: e.tooltip,
305
- onClick: e["function"],
306
- icon: e.icon,
307
- color: e.color,
308
- selectionMode: e.selectionMode,
309
- confirmMessage: e.confirmMessage,
310
- hasConfirmMessage: e.hasConfirmMessage,
311
- disabled: e.disabled
312
- }, e.key || e.name);
313
- }
276
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton["default"], {
277
+ table: table,
278
+ toggle: e.toggle,
279
+ active: e.active,
280
+ name: e.name,
281
+ tooltip: e.tooltip,
282
+ onClick: e["function"],
283
+ icon: e.icon,
284
+ color: e.color,
285
+ selectionMode: e.selectionMode,
286
+ confirmMessage: e.confirmMessage,
287
+ hasConfirmMessage: e.hasConfirmMessage,
288
+ disabled: e.disabled
289
+ }, e.key || e.name);
314
290
  })
315
291
  }), !disableSideActions && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
316
292
  style: {
@@ -791,7 +767,6 @@ var DataGrid = function DataGrid(_ref) {
791
767
  var row = _ref8.row;
792
768
  return {
793
769
  checked: rowSelection[row.id] || false,
794
- indeterminate: false,
795
770
  onChange: function onChange() {
796
771
  var rowId = row.id.toString();
797
772
  setRowSelection(function (prev) {
@@ -817,15 +792,33 @@ var DataGrid = function DataGrid(_ref) {
817
792
  // </div>
818
793
  // )}
819
794
  });
795
+ (0, _react.useEffect)(function () {
796
+ if (hasSubRows) {
797
+ if (Object.keys(rowSelection).length > 0) {
798
+ selectData(getSelectedRows(rowSelection));
799
+ }
800
+ } else {
801
+ var selectedRowIds = Object.keys(table.getState().rowSelection);
802
+ var selectedRows = selectedRowIds.map(function (rowId) {
803
+ var matchingRow = table.getSelectedRowModel().rows.find(function (row) {
804
+ return "".concat(row.id) === rowId;
805
+ });
806
+ return matchingRow ? matchingRow.original : null;
807
+ }).filter(function (row) {
808
+ return row !== null;
809
+ });
810
+ selectData(selectedRows);
811
+ }
812
+ }, [rowSelection, table, hasSubRows, selectData, getSelectedRows]);
820
813
  (0, _react.useEffect)(function () {
821
814
  var rows = table.getRowModel().rows.map(function (r) {
822
815
  return r.original;
823
816
  });
824
- onVisibleRowsChange === null || onVisibleRowsChange === void 0 || onVisibleRowsChange(rows);
825
- }, [table.getRowModel().rows]);
817
+ if (onVisibleRowsChange) onVisibleRowsChange(rows);
818
+ }, [table, onVisibleRowsChange]);
826
819
  (0, _react.useEffect)(function () {
827
- return enableFixedHeader && (0, _gridFixedHeader["default"])('fixed-header', enableFixedActions);
828
- }, []);
820
+ if (enableFixedHeader) (0, _gridFixedHeader["default"])('fixed-header', enableFixedActions);
821
+ }, [enableFixedHeader, enableFixedActions]);
829
822
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_xDatePickers.LocalizationProvider, {
830
823
  dateAdapter: _AdapterDateFns.AdapterDateFns,
831
824
  children: [open && /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridHelper["default"], {
@@ -60,14 +60,23 @@ var DEFAULT_CELL_TYPES = exports.DEFAULT_CELL_TYPES = {
60
60
  var cell = _ref.cell;
61
61
  return cell.getValue();
62
62
  },
63
- textTitle: function textTitle(_ref2) {
63
+ textJustify: function textJustify(_ref2) {
64
64
  var cell = _ref2.cell;
65
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
65
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
66
+ style: {
67
+ textAlign: "justify"
68
+ },
66
69
  children: cell.getValue()
67
70
  });
68
71
  },
69
- textDescription: function textDescription(_ref3) {
72
+ textTitle: function textTitle(_ref3) {
70
73
  var cell = _ref3.cell;
74
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
75
+ children: cell.getValue()
76
+ });
77
+ },
78
+ textDescription: function textDescription(_ref4) {
79
+ var cell = _ref4.cell;
71
80
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
72
81
  style: {
73
82
  color: '#666'
@@ -75,65 +84,65 @@ var DEFAULT_CELL_TYPES = exports.DEFAULT_CELL_TYPES = {
75
84
  children: cell.getValue()
76
85
  });
77
86
  },
78
- textSmall: function textSmall(_ref4) {
79
- var cell = _ref4.cell;
87
+ textSmall: function textSmall(_ref5) {
88
+ var cell = _ref5.cell;
80
89
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("small", {
81
90
  children: cell.getValue()
82
91
  });
83
92
  },
84
- date: function date(_ref5) {
85
- var cell = _ref5.cell,
86
- column = _ref5.column;
93
+ date: function date(_ref6) {
94
+ var cell = _ref6.cell,
95
+ column = _ref6.column;
87
96
  return (0, _FormatDate["default"])(cell.getValue(), {
88
97
  onlyDate: true,
89
98
  locale: column.locale || 'pt-PT'
90
99
  });
91
100
  },
92
- datetime: function datetime(_ref6) {
93
- var cell = _ref6.cell,
94
- column = _ref6.column;
101
+ datetime: function datetime(_ref7) {
102
+ var cell = _ref7.cell,
103
+ column = _ref7.column;
95
104
  return (0, _FormatDate["default"])(cell.getValue(), {
96
105
  onlyDate: false,
97
106
  locale: column.locale || 'pt-PT'
98
107
  });
99
108
  },
100
- number: function number(_ref7) {
101
- var cell = _ref7.cell;
109
+ number: function number(_ref8) {
110
+ var cell = _ref8.cell;
102
111
  return cell.getValue();
103
112
  },
104
- integer: function integer(_ref8) {
105
- var cell = _ref8.cell;
113
+ integer: function integer(_ref9) {
114
+ var cell = _ref9.cell;
106
115
  return Number.isFinite(cell.getValue()) ? Math.round(cell.getValue()) : cell.getValue();
107
116
  },
108
- currency: function currency(_ref9) {
109
- var cell = _ref9.cell;
117
+ currency: function currency(_ref10) {
118
+ var cell = _ref10.cell;
110
119
  var v = cell.getValue();
111
120
  return typeof v === 'number' ? v.toLocaleString(undefined, {
112
121
  style: 'currency',
113
122
  currency: 'EUR'
114
123
  }) : v;
115
124
  },
116
- percentage: function percentage(_ref10) {
117
- var cell = _ref10.cell;
125
+ percentage: function percentage(_ref11) {
126
+ var cell = _ref11.cell;
118
127
  var v = cell.getValue();
119
128
  return typeof v === 'number' ? "".concat((v * 100).toFixed(2), "%") : v;
120
129
  },
121
- email: function email(_ref11) {
122
- var cell = _ref11.cell;
130
+ email: function email(_ref12) {
131
+ var cell = _ref12.cell;
123
132
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
124
133
  href: "mailto:".concat(cell.getValue()),
125
134
  children: cell.getValue()
126
135
  });
127
136
  },
128
- phone: function phone(_ref12) {
129
- var cell = _ref12.cell;
137
+ phone: function phone(_ref13) {
138
+ var cell = _ref13.cell;
130
139
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
131
140
  href: "tel:".concat(cell.getValue()),
132
141
  children: cell.getValue()
133
142
  });
134
143
  },
135
- link: function link(_ref13) {
136
- var cell = _ref13.cell;
144
+ link: function link(_ref14) {
145
+ var cell = _ref14.cell;
137
146
  var value = cell.getValue();
138
147
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
139
148
  title: value,
@@ -145,8 +154,8 @@ var DEFAULT_CELL_TYPES = exports.DEFAULT_CELL_TYPES = {
145
154
  })
146
155
  });
147
156
  },
148
- array: function array(_ref14) {
149
- var cell = _ref14.cell;
157
+ array: function array(_ref15) {
158
+ var cell = _ref15.cell;
150
159
  var value = cell.getValue();
151
160
  var arr = Array.isArray(value) ? value : [];
152
161
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
@@ -154,8 +163,8 @@ var DEFAULT_CELL_TYPES = exports.DEFAULT_CELL_TYPES = {
154
163
  children: arr.join(', ')
155
164
  });
156
165
  },
157
- json: function json(_ref15) {
158
- var cell = _ref15.cell;
166
+ json: function json(_ref16) {
167
+ var cell = _ref16.cell;
159
168
  var value = cell.getValue();
160
169
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
161
170
  title: JSON.stringify(value),
@@ -164,9 +173,9 @@ var DEFAULT_CELL_TYPES = exports.DEFAULT_CELL_TYPES = {
164
173
  })
165
174
  });
166
175
  },
167
- countryFlag: function countryFlag(_ref16) {
168
- var cell = _ref16.cell,
169
- column = _ref16.column;
176
+ countryFlag: function countryFlag(_ref17) {
177
+ var cell = _ref17.cell,
178
+ column = _ref17.column;
170
179
  var v = cell.getValue();
171
180
  if (!v) return "";
172
181
  var iso2 = String(v).toUpperCase();
@@ -189,9 +198,9 @@ var DEFAULT_CELL_TYPES = exports.DEFAULT_CELL_TYPES = {
189
198
  })]
190
199
  });
191
200
  },
192
- persons: function persons(_ref17) {
193
- var cell = _ref17.cell,
194
- column = _ref17.column;
201
+ persons: function persons(_ref18) {
202
+ var cell = _ref18.cell,
203
+ column = _ref18.column;
195
204
  var value = cell.getValue();
196
205
  var arr;
197
206
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insticc/react-datagrid-2",
3
- "version": "1.1.25",
3
+ "version": "1.1.27",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "files": [