@bento-core/paginated-table 1.0.1-ins.19 → 1.0.1-ins.20

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.
@@ -53,13 +53,7 @@ const getPaginatedQueryVariables = (queryVariables, table) => {
53
53
  variables.sort_direction = sortOrder;
54
54
  return variables;
55
55
  };
56
-
57
- /**
58
- * @param {*} queryVariables
59
- * @param {*} table (table state)
60
- * @param {*} tab (tab)
61
- * @returns table data
62
- */
56
+ let callCounter = 0;
63
57
  const getTableData = _ref => {
64
58
  let {
65
59
  queryVariables,
@@ -84,19 +78,21 @@ const getTableData = _ref => {
84
78
  const [tableData, setTableData] = (0, _react.useState)(null);
85
79
  (0, _react.useEffect)(() => {
86
80
  const controller = new AbortController();
87
- const timeoutId = setTimeout(() => {
88
- getData().then(result => {
81
+ callCounter += 1;
82
+ const currentCall = callCounter;
83
+ getData().then(result => {
84
+ // Only update the table data if this is the most recent call
85
+ if (currentCall === callCounter) {
89
86
  if (table.paginationAPIField && result[table.paginationAPIField]) {
90
87
  setTableData(result[table.paginationAPIField]);
91
88
  } else {
92
89
  setTableData(result);
93
90
  }
94
- });
95
- }, 5000);
91
+ }
92
+ });
96
93
  return () => {
97
94
  // cancel the request before component unmounts
98
95
  controller.abort();
99
- clearTimeout(timeoutId); // Clear the timeout if dependencies change or component unmounts
100
96
  };
101
97
  }, [queryVariables, page, rowsPerPage, sortOrder, sortBy]);
102
98
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/paginated-table",
3
- "version": "1.0.1-ins.19",
3
+ "version": "1.0.1-ins.20",
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",
@@ -37,12 +37,7 @@ const getPaginatedQueryVariables = (queryVariables, table) => {
37
37
  return variables;
38
38
  };
39
39
 
40
- /**
41
- * @param {*} queryVariables
42
- * @param {*} table (table state)
43
- * @param {*} tab (tab)
44
- * @returns table data
45
- */
40
+ let callCounter = 0;
46
41
  export const getTableData = ({ queryVariables, table }) => {
47
42
  const client = useApolloClient();
48
43
  const {
@@ -64,19 +59,21 @@ export const getTableData = ({ queryVariables, table }) => {
64
59
  const [tableData, setTableData] = useState(null);
65
60
  useEffect(() => {
66
61
  const controller = new AbortController();
67
- const timeoutId = setTimeout(() => {
68
- getData().then((result) => {
62
+ callCounter += 1;
63
+ const currentCall = callCounter;
64
+ getData().then((result) => {
65
+ // Only update the table data if this is the most recent call
66
+ if (currentCall === callCounter) {
69
67
  if (table.paginationAPIField && result[table.paginationAPIField]) {
70
68
  setTableData(result[table.paginationAPIField]);
71
69
  } else {
72
70
  setTableData(result);
73
71
  }
74
- });
75
- }, 5000);
72
+ }
73
+ });
76
74
  return () => {
77
75
  // cancel the request before component unmounts
78
76
  controller.abort();
79
- clearTimeout(timeoutId); // Clear the timeout if dependencies change or component unmounts
80
77
  };
81
78
  }, [queryVariables, page, rowsPerPage, sortOrder, sortBy]);
82
79
  return { tableData };