@bento-core/paginated-table 1.0.1-icdc.21 → 1.0.1-icdc.23

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/index.js CHANGED
@@ -69,6 +69,12 @@ Object.defineProperty(exports, "onColumnViewChange", {
69
69
  return _Actions.onColumnViewChange;
70
70
  }
71
71
  });
72
+ Object.defineProperty(exports, "onInputSearchQueryChange", {
73
+ enumerable: true,
74
+ get: function get() {
75
+ return _Actions.onInputSearchQueryChange;
76
+ }
77
+ });
72
78
  Object.defineProperty(exports, "onPageAndTotalCountChange", {
73
79
  enumerable: true,
74
80
  get: function get() {
@@ -38,7 +38,8 @@ const TableController = props => {
38
38
  rowsPerPage = 10,
39
39
  sortBy,
40
40
  sortOrder,
41
- groupBy
41
+ groupBy,
42
+ searchQuery
42
43
  } = table;
43
44
 
44
45
  /**
@@ -120,13 +121,30 @@ const TableController = props => {
120
121
  return alphaNumericSort(b, a);
121
122
  };
122
123
 
124
+ // filter rows based on input serch query
125
+ const filterBySearchQuery = rows => {
126
+ if (!searchQuery) return rows;
127
+ const query = searchQuery.toLowerCase();
128
+ const viewRows = rows.filter(row => {
129
+ const rowValues = Object.keys(row).map(key => "".concat(row[key]).toLowerCase()).join(' ');
130
+ return rowValues.includes(query);
131
+ });
132
+ return viewRows;
133
+ };
134
+
123
135
  // sort based on row grouping
124
136
  // groupBy column name
125
137
  const sortedRows = groupBy ? sortWithRowGrouping(updateRows) : [...updateRows].sort((a, b) => sortRows(a, b));
138
+
139
+ // filter by search Query
140
+ const filterRows = filterBySearchQuery(sortedRows);
126
141
  const startIndex = page * rowsPerPage;
127
142
  const endIndex = startIndex + rowsPerPage;
128
- const displayRows = [...sortedRows].slice(startIndex, endIndex);
143
+ const displayRows = [...filterRows].slice(startIndex, endIndex);
129
144
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_table.TableView, _extends({}, props, {
145
+ table: _objectSpread(_objectSpread({}, table), {}, {
146
+ totalRowCount: filterRows.length
147
+ }),
130
148
  totalRows: tblRows,
131
149
  tableRows: displayRows
132
150
  })));
@@ -99,7 +99,8 @@ const PaginatedTable = _ref => {
99
99
  customizeChangeRowsPerPage,
100
100
  customizeColumnViewChange,
101
101
  customizeDeleteRow,
102
- customizeDeleteAllRows
102
+ customizeDeleteAllRows,
103
+ customizeSearchQueryChange
103
104
  } = paginationOptions;
104
105
 
105
106
  /**
@@ -192,6 +193,15 @@ const PaginatedTable = _ref => {
192
193
  }));
193
194
  };
194
195
 
196
+ /**
197
+ * Filter table rows based on Search query
198
+ */
199
+ const handleSeachQueryChange = value => {
200
+ dispatch((0, _Actions.onInputSearchQueryChange)({
201
+ searchQuery: value
202
+ }));
203
+ };
204
+
195
205
  /**
196
206
  * A. client table
197
207
  * table data provide by bento app (tblRows)
@@ -209,6 +219,7 @@ const PaginatedTable = _ref => {
209
219
  onColumnViewChange: customizeColumnViewChange || handleColumnViewChange,
210
220
  onDeleteRow: customizeDeleteRow || onDeleteRow,
211
221
  onDeleteAllFiles: customizeDeleteAllRows || onDeleteAllRows,
222
+ onSearchQueryChange: customizeSearchQueryChange || handleSeachQueryChange,
212
223
  themeConfig: themeConfig
213
224
  }));
214
225
  }
@@ -236,6 +247,7 @@ const PaginatedTable = _ref => {
236
247
  onColumnViewChange: customizeColumnViewChange || handleColumnViewChange,
237
248
  onDeleteRow: customizeDeleteRow || onDeleteRow,
238
249
  onDeleteAllFiles: customizeDeleteAllRows || onDeleteAllRows,
250
+ onSearchQueryChange: customizeSearchQueryChange || handleSeachQueryChange,
239
251
  themeConfig: themeConfig
240
252
  }));
241
253
  };
@@ -47,13 +47,15 @@ const getPaginatedQueryVariables = (queryVariables, table) => {
47
47
  page,
48
48
  rowsPerPage,
49
49
  sortBy,
50
- sortOrder
50
+ sortOrder,
51
+ searchQuery
51
52
  } = table;
52
53
  const offset = page * rowsPerPage;
53
54
  variables.offset = offset;
54
55
  variables.order_by = sortBy;
55
56
  variables.first = rowsPerPage;
56
57
  variables.sort_direction = sortOrder;
58
+ variables.search_query = searchQuery;
57
59
  return variables;
58
60
  };
59
61
 
@@ -74,7 +76,8 @@ const getTableData = _ref => {
74
76
  rowsPerPage,
75
77
  sortOrder,
76
78
  query,
77
- sortBy
79
+ sortBy,
80
+ searchQuery = ''
78
81
  } = table;
79
82
  async function getData() {
80
83
  const paginatedqueryVariable = getPaginatedQueryVariables(queryVariables, table);
@@ -98,7 +101,7 @@ const getTableData = _ref => {
98
101
  // cancel the request before component unmounts
99
102
  controller.abort();
100
103
  };
101
- }, [queryVariables, page, rowsPerPage, sortOrder, sortBy]);
104
+ }, [queryVariables, page, rowsPerPage, sortOrder, sortBy, searchQuery]);
102
105
  return {
103
106
  tableData
104
107
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setTotalRowCount = exports.onRowsPerPageChange = exports.onRowSeclect = exports.onRowDelete = exports.onPageChange = exports.onPageAndTotalCountChange = exports.onColumnViewChange = exports.onColumnSort = exports.onClearCart = exports.onChangeSortDirection = exports.customPaginationAction = exports.actionTypes = void 0;
6
+ exports.setTotalRowCount = exports.onRowsPerPageChange = exports.onRowSeclect = exports.onRowDelete = exports.onPageChange = exports.onPageAndTotalCountChange = exports.onInputSearchQueryChange = exports.onColumnViewChange = exports.onColumnSort = exports.onClearCart = exports.onChangeSortDirection = exports.customPaginationAction = exports.actionTypes = void 0;
7
7
  const actionTypes = {
8
8
  VIEW_COLUMN_CHANGE: 'VIEW_COLUMN_CHANGE',
9
9
  ON_COLUMN_SORT: 'ON_COLUMN_SORT',
@@ -15,7 +15,8 @@ const actionTypes = {
15
15
  ON_PAGE_AND_TOTAL_COUNT_CHANGE: 'ON_PAGE_AND_TOTAL_COUNT_CHANGE',
16
16
  CUSTOMIZE_PAGINATION_ACTION: 'CUSTOMIZE_PAGINATION_ACTION',
17
17
  ON_ROWS_DELETE: 'ON_ROWS_DELETE',
18
- ON_ROW_DELETE: 'ON_ROW_DELETE'
18
+ ON_ROW_DELETE: 'ON_ROW_DELETE',
19
+ ON_SEARCH_QUERY_CHANGE: 'ON_SEARCH_QUERY_CHANGE'
19
20
  };
20
21
  exports.actionTypes = actionTypes;
21
22
  const onColumnViewChange = columns => ({
@@ -72,4 +73,9 @@ const onRowDelete = value => ({
72
73
  type: actionTypes.ON_ROW_DELETE,
73
74
  payload: value
74
75
  });
75
- exports.onRowDelete = onRowDelete;
76
+ exports.onRowDelete = onRowDelete;
77
+ const onInputSearchQueryChange = value => ({
78
+ type: actionTypes.ON_SEARCH_QUERY_CHANGE,
79
+ payload: value
80
+ });
81
+ exports.onInputSearchQueryChange = onInputSearchQueryChange;
@@ -57,6 +57,10 @@ const reducer = (state, action) => {
57
57
  deletedRows: payload.deleteRows,
58
58
  selectedRows: payload.selectedRows
59
59
  });
60
+ case _Actions.actionTypes.ON_SEARCH_QUERY_CHANGE:
61
+ return _objectSpread(_objectSpread({}, state), {}, {
62
+ searchQuery: payload.searchQuery
63
+ });
60
64
  default:
61
65
  return state;
62
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/paginated-table",
3
- "version": "1.0.1-icdc.21",
3
+ "version": "1.0.1-icdc.23",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -13,6 +13,7 @@ export {
13
13
  onRowSeclect,
14
14
  setTotalRowCount,
15
15
  customPaginationAction,
16
+ onInputSearchQueryChange,
16
17
  } from './table/state/Actions';
17
18
  export { default as Wrapper, types } from './wrapper/Wrapper';
18
19
  export { btnTypes } from './wrapper/components/AddFiles';
@@ -26,6 +26,7 @@ const TableController = ((props) => {
26
26
  sortBy,
27
27
  sortOrder,
28
28
  groupBy,
29
+ searchQuery,
29
30
  } = table;
30
31
 
31
32
  /**
@@ -115,18 +116,38 @@ const TableController = ((props) => {
115
116
  return alphaNumericSort(b, a);
116
117
  };
117
118
 
119
+ // filter rows based on input serch query
120
+ const filterBySearchQuery = (rows) => {
121
+ if (!searchQuery) return rows;
122
+ const query = searchQuery.toLowerCase();
123
+ const viewRows = rows.filter((row) => {
124
+ const rowValues = Object.keys(row)
125
+ .map((key) => `${row[key]}`.toLowerCase()).join(' ');
126
+ return rowValues.includes(query);
127
+ });
128
+ return viewRows;
129
+ };
130
+
118
131
  // sort based on row grouping
119
132
  // groupBy column name
120
133
  const sortedRows = (groupBy) ? sortWithRowGrouping(updateRows)
121
134
  : [...updateRows].sort((a, b) => sortRows(a, b));
135
+
136
+ // filter by search Query
137
+ const filterRows = filterBySearchQuery(sortedRows);
138
+
122
139
  const startIndex = page * rowsPerPage;
123
140
  const endIndex = startIndex + rowsPerPage;
124
- const displayRows = [...sortedRows].slice(startIndex, endIndex);
141
+ const displayRows = [...filterRows].slice(startIndex, endIndex);
125
142
 
126
143
  return (
127
144
  <>
128
145
  <TableView
129
146
  {...props}
147
+ table={{
148
+ ...table,
149
+ totalRowCount: filterRows.length,
150
+ }}
130
151
  totalRows={tblRows}
131
152
  tableRows={displayRows}
132
153
  />
@@ -15,6 +15,7 @@ import {
15
15
  onColumnViewChange,
16
16
  onRowDelete,
17
17
  onClearCart,
18
+ onInputSearchQueryChange,
18
19
  } from './state/Actions';
19
20
  import { TableContext } from './ContextProvider';
20
21
  import reducer from './state/Reducer';
@@ -91,6 +92,7 @@ const PaginatedTable = ({
91
92
  customizeColumnViewChange,
92
93
  customizeDeleteRow,
93
94
  customizeDeleteAllRows,
95
+ customizeSearchQueryChange,
94
96
  } = paginationOptions;
95
97
 
96
98
  /**
@@ -181,6 +183,15 @@ const PaginatedTable = ({
181
183
  }));
182
184
  };
183
185
 
186
+ /**
187
+ * Filter table rows based on Search query
188
+ */
189
+ const handleSeachQueryChange = (value) => {
190
+ dispatch(onInputSearchQueryChange({
191
+ searchQuery: value,
192
+ }));
193
+ };
194
+
184
195
  /**
185
196
  * A. client table
186
197
  * table data provide by bento app (tblRows)
@@ -200,6 +211,7 @@ const PaginatedTable = ({
200
211
  onColumnViewChange={customizeColumnViewChange || handleColumnViewChange}
201
212
  onDeleteRow={customizeDeleteRow || onDeleteRow}
202
213
  onDeleteAllFiles={customizeDeleteAllRows || onDeleteAllRows}
214
+ onSearchQueryChange={customizeSearchQueryChange || handleSeachQueryChange}
203
215
  themeConfig={themeConfig}
204
216
  />
205
217
  </>
@@ -232,6 +244,7 @@ const PaginatedTable = ({
232
244
  onColumnViewChange={customizeColumnViewChange || handleColumnViewChange}
233
245
  onDeleteRow={customizeDeleteRow || onDeleteRow}
234
246
  onDeleteAllFiles={customizeDeleteAllRows || onDeleteAllRows}
247
+ onSearchQueryChange={customizeSearchQueryChange || handleSeachQueryChange}
235
248
  themeConfig={themeConfig}
236
249
  />
237
250
  </>
@@ -31,12 +31,14 @@ const getPaginatedQueryVariables = (queryVariables, table) => {
31
31
  rowsPerPage,
32
32
  sortBy,
33
33
  sortOrder,
34
+ searchQuery,
34
35
  } = table;
35
36
  const offset = page * rowsPerPage;
36
37
  variables.offset = offset;
37
38
  variables.order_by = sortBy;
38
39
  variables.first = rowsPerPage;
39
40
  variables.sort_direction = sortOrder;
41
+ variables.search_query = searchQuery;
40
42
  return variables;
41
43
  };
42
44
 
@@ -54,6 +56,7 @@ export const getTableData = ({ queryVariables, table }) => {
54
56
  sortOrder,
55
57
  query,
56
58
  sortBy,
59
+ searchQuery = '',
57
60
  } = table;
58
61
  async function getData() {
59
62
  const paginatedqueryVariable = getPaginatedQueryVariables(queryVariables, table);
@@ -78,6 +81,6 @@ export const getTableData = ({ queryVariables, table }) => {
78
81
  // cancel the request before component unmounts
79
82
  controller.abort();
80
83
  };
81
- }, [queryVariables, page, rowsPerPage, sortOrder, sortBy]);
84
+ }, [queryVariables, page, rowsPerPage, sortOrder, sortBy, searchQuery]);
82
85
  return { tableData };
83
86
  };
@@ -10,6 +10,7 @@ export const actionTypes = {
10
10
  CUSTOMIZE_PAGINATION_ACTION: 'CUSTOMIZE_PAGINATION_ACTION',
11
11
  ON_ROWS_DELETE: 'ON_ROWS_DELETE',
12
12
  ON_ROW_DELETE: 'ON_ROW_DELETE',
13
+ ON_SEARCH_QUERY_CHANGE: 'ON_SEARCH_QUERY_CHANGE',
13
14
  };
14
15
 
15
16
  export const onColumnViewChange = (columns) => ({
@@ -66,3 +67,8 @@ export const onRowDelete = (value) => ({
66
67
  type: actionTypes.ON_ROW_DELETE,
67
68
  payload: value,
68
69
  });
70
+
71
+ export const onInputSearchQueryChange = (value) => ({
72
+ type: actionTypes.ON_SEARCH_QUERY_CHANGE,
73
+ payload: value,
74
+ });
@@ -58,6 +58,11 @@ const reducer = (state, action) => {
58
58
  deletedRows: payload.deleteRows,
59
59
  selectedRows: payload.selectedRows,
60
60
  };
61
+ case actionTypes.ON_SEARCH_QUERY_CHANGE:
62
+ return {
63
+ ...state,
64
+ searchQuery: payload.searchQuery,
65
+ };
61
66
  default:
62
67
  return state;
63
68
  }