@bento-core/paginated-table 1.0.1-ccdihub.147 → 1.0.1-ccdihub.149

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.
@@ -27,7 +27,11 @@ const PaginatedTable = _ref => {
27
27
  activeTab = true,
28
28
  server = true,
29
29
  tblRows = [],
30
- navigation = () => {}
30
+ navigation = () => {},
31
+ onSearch,
32
+ searchValue,
33
+ onSearchResultCount,
34
+ onColumnStateChange
31
35
  } = _ref;
32
36
  /**
33
37
  * Initailize useReducer state
@@ -182,6 +186,10 @@ const PaginatedTable = _ref => {
182
186
  dispatch((0, _Actions.onColumnViewChange)(_objectSpread(_objectSpread({}, table), {}, {
183
187
  columns
184
188
  })));
189
+ // Save column state for persistence across search state changes
190
+ if (onColumnStateChange) {
191
+ onColumnStateChange(columns);
192
+ }
185
193
  };
186
194
  const handleAllColumnViewChange = checked => {
187
195
  const columns = table.columns.map(col => {
@@ -195,6 +203,10 @@ const PaginatedTable = _ref => {
195
203
  dispatch((0, _Actions.onColumnViewChange)(_objectSpread(_objectSpread({}, table), {}, {
196
204
  columns
197
205
  })));
206
+ // Save column state for persistence across search state changes
207
+ if (onColumnStateChange) {
208
+ onColumnStateChange(columns);
209
+ }
198
210
  };
199
211
  /**
200
212
  * A. client table
@@ -212,7 +224,10 @@ const PaginatedTable = _ref => {
212
224
  onSortByColumn: handleSortByColumn,
213
225
  onColumnViewChange: handleColumnViewChange,
214
226
  onAllColumnViewChange: handleAllColumnViewChange,
215
- themeConfig: themeConfig
227
+ themeConfig: themeConfig,
228
+ onSearch: onSearch,
229
+ searchValue: searchValue,
230
+ onSearchResultCount: onSearchResultCount
216
231
  }));
217
232
  }
218
233
 
@@ -238,7 +253,10 @@ const PaginatedTable = _ref => {
238
253
  onColumnViewChange: handleColumnViewChange,
239
254
  onAllColumnViewChange: handleAllColumnViewChange,
240
255
  themeConfig: themeConfig,
241
- navigation: navigation
256
+ navigation: navigation,
257
+ onSearch: onSearch,
258
+ searchValue: searchValue,
259
+ onSearchResultCount: onSearchResultCount
242
260
  }));
243
261
  };
244
262
  var _default = PaginatedTable;
@@ -16,13 +16,15 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
16
16
  const TableController = props => {
17
17
  const {
18
18
  queryVariables,
19
- table
19
+ table,
20
+ onSearchResultCount
20
21
  } = props;
21
22
  const {
22
23
  tableData
23
24
  } = (0, _TableService.getTableData)({
24
25
  queryVariables,
25
- table
26
+ table,
27
+ onSearchResultCount
26
28
  });
27
29
  if (!tableData) {
28
30
  return /*#__PURE__*/_react.default.createElement(_core.Container, {
@@ -58,12 +58,14 @@ const getPaginatedQueryVariables = (queryVariables, table) => {
58
58
  * @param {*} queryVariables
59
59
  * @param {*} table (table state)
60
60
  * @param {*} tab (tab)
61
+ * @param {*} onSearchResultCount (callback to update search result count)
61
62
  * @returns table data
62
63
  */
63
64
  const getTableData = _ref => {
64
65
  let {
65
66
  queryVariables,
66
- table
67
+ table,
68
+ onSearchResultCount
67
69
  } = _ref;
68
70
  const client = (0, _client.useApolloClient)();
69
71
  const {
@@ -86,7 +88,26 @@ const getTableData = _ref => {
86
88
  const controller = new AbortController();
87
89
  getData().then(result => {
88
90
  if (table.paginationAPIField && result[table.paginationAPIField]) {
89
- setTableData(result[table.paginationAPIField]);
91
+ const apiResult = result[table.paginationAPIField];
92
+
93
+ // Check if this is the new getFilenames structure with files and totalCount
94
+ if (apiResult && typeof apiResult === 'object' && 'files' in apiResult && 'totalCount' in apiResult) {
95
+ // Handle getFilenames response structure
96
+ setTableData(apiResult.files);
97
+
98
+ // Update total count for search results
99
+ if (onSearchResultCount && apiResult.totalCount !== undefined) {
100
+ onSearchResultCount(apiResult.totalCount);
101
+ }
102
+ } else {
103
+ // Handle regular array response (fileOverview, etc.)
104
+ setTableData(apiResult);
105
+
106
+ // For non-search queries, don't update the count
107
+ if (onSearchResultCount) {
108
+ onSearchResultCount(null);
109
+ }
110
+ }
90
111
  } else {
91
112
  setTableData(result);
92
113
  }
@@ -95,7 +116,7 @@ const getTableData = _ref => {
95
116
  // cancel the request before component unmounts
96
117
  controller.abort();
97
118
  };
98
- }, [queryVariables, page, rowsPerPage, sortOrder, sortBy]);
119
+ }, [queryVariables, page, rowsPerPage, sortOrder, sortBy, query, table.paginationAPIField]);
99
120
  return {
100
121
  tableData
101
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/paginated-table",
3
- "version": "1.0.1-ccdihub.147",
3
+ "version": "1.0.1-ccdihub.149",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "npm run lint && cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@bento-core/cart": "1.0.1-ccdihub.9",
19
- "@bento-core/table": "1.0.1-ccdihub.117",
19
+ "@bento-core/table": "1.0.1-ccdihub.118",
20
20
  "@bento-core/tool-tip": "^1.0.0",
21
21
  "@bento-core/util": "^1.0.0"
22
22
  },
@@ -23,6 +23,10 @@ const PaginatedTable = ({
23
23
  server = true,
24
24
  tblRows = [],
25
25
  navigation = () => {},
26
+ onSearch,
27
+ searchValue,
28
+ onSearchResultCount,
29
+ onColumnStateChange,
26
30
  }) => {
27
31
  /**
28
32
  * Initailize useReducer state
@@ -176,6 +180,10 @@ const PaginatedTable = ({
176
180
  ...table,
177
181
  columns,
178
182
  }));
183
+ // Save column state for persistence across search state changes
184
+ if (onColumnStateChange) {
185
+ onColumnStateChange(columns);
186
+ }
179
187
  };
180
188
 
181
189
  const handleAllColumnViewChange = (checked) => {
@@ -193,6 +201,10 @@ const PaginatedTable = ({
193
201
  ...table,
194
202
  columns,
195
203
  }));
204
+ // Save column state for persistence across search state changes
205
+ if (onColumnStateChange) {
206
+ onColumnStateChange(columns);
207
+ }
196
208
  };
197
209
  /**
198
210
  * A. client table
@@ -213,6 +225,9 @@ const PaginatedTable = ({
213
225
  onColumnViewChange={handleColumnViewChange}
214
226
  onAllColumnViewChange={handleAllColumnViewChange}
215
227
  themeConfig={themeConfig}
228
+ onSearch={onSearch}
229
+ searchValue={searchValue}
230
+ onSearchResultCount={onSearchResultCount}
216
231
  />
217
232
  </>
218
233
  );
@@ -244,6 +259,9 @@ const PaginatedTable = ({
244
259
  onAllColumnViewChange={handleAllColumnViewChange}
245
260
  themeConfig={themeConfig}
246
261
  navigation={navigation}
262
+ onSearch={onSearch}
263
+ searchValue={searchValue}
264
+ onSearchResultCount={onSearchResultCount}
247
265
  />
248
266
  </>
249
267
  );
@@ -13,8 +13,8 @@ import {
13
13
  * Updates table row when table state is changed 1. (paginated action) and 2. filter action
14
14
  */
15
15
  const TableController = ((props) => {
16
- const { queryVariables, table } = props;
17
- const { tableData } = getTableData({ queryVariables, table });
16
+ const { queryVariables, table, onSearchResultCount } = props;
17
+ const { tableData } = getTableData({ queryVariables, table, onSearchResultCount });
18
18
  if (!tableData) {
19
19
  return (
20
20
  <Container maxWidth="xl">
@@ -41,9 +41,10 @@ const getPaginatedQueryVariables = (queryVariables, table) => {
41
41
  * @param {*} queryVariables
42
42
  * @param {*} table (table state)
43
43
  * @param {*} tab (tab)
44
+ * @param {*} onSearchResultCount (callback to update search result count)
44
45
  * @returns table data
45
46
  */
46
- export const getTableData = ({ queryVariables, table }) => {
47
+ export const getTableData = ({ queryVariables, table, onSearchResultCount }) => {
47
48
  const client = useApolloClient();
48
49
  const {
49
50
  page,
@@ -66,7 +67,26 @@ export const getTableData = ({ queryVariables, table }) => {
66
67
  const controller = new AbortController();
67
68
  getData().then((result) => {
68
69
  if (table.paginationAPIField && result[table.paginationAPIField]) {
69
- setTableData(result[table.paginationAPIField]);
70
+ const apiResult = result[table.paginationAPIField];
71
+
72
+ // Check if this is the new getFilenames structure with files and totalCount
73
+ if (apiResult && typeof apiResult === 'object' && 'files' in apiResult && 'totalCount' in apiResult) {
74
+ // Handle getFilenames response structure
75
+ setTableData(apiResult.files);
76
+
77
+ // Update total count for search results
78
+ if (onSearchResultCount && apiResult.totalCount !== undefined) {
79
+ onSearchResultCount(apiResult.totalCount);
80
+ }
81
+ } else {
82
+ // Handle regular array response (fileOverview, etc.)
83
+ setTableData(apiResult);
84
+
85
+ // For non-search queries, don't update the count
86
+ if (onSearchResultCount) {
87
+ onSearchResultCount(null);
88
+ }
89
+ }
70
90
  } else {
71
91
  setTableData(result);
72
92
  }
@@ -75,6 +95,6 @@ export const getTableData = ({ queryVariables, table }) => {
75
95
  // cancel the request before component unmounts
76
96
  controller.abort();
77
97
  };
78
- }, [queryVariables, page, rowsPerPage, sortOrder, sortBy]);
98
+ }, [queryVariables, page, rowsPerPage, sortOrder, sortBy, query, table.paginationAPIField]);
79
99
  return { tableData };
80
100
  };