@trackunit/react-table 1.3.185 → 1.3.187

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.
Files changed (3) hide show
  1. package/index.cjs.js +11 -4
  2. package/index.esm.js +11 -4
  3. package/package.json +11 -11
package/index.cjs.js CHANGED
@@ -1314,11 +1314,18 @@ const useTableSelection = ({ data, idKey, defaultSelectedIds, enableRowSelection
1314
1314
  const [t] = useTranslation();
1315
1315
  const [rowSelection, setRowSelection] = react.useState({});
1316
1316
  react.useEffect(() => {
1317
- const initialSelection = {};
1318
- defaultSelectedIds?.forEach(id => {
1319
- initialSelection[String(id)] = true;
1317
+ if (!defaultSelectedIds) {
1318
+ return;
1319
+ }
1320
+ const initialSelection = defaultSelectedIds.reduce((selection, id) => {
1321
+ selection[String(id)] = true;
1322
+ return selection;
1323
+ }, {});
1324
+ setRowSelection(prev => {
1325
+ const hasChanged = sharedUtils.objectKeys(prev).length !== sharedUtils.objectKeys(initialSelection).length ||
1326
+ sharedUtils.objectEntries(initialSelection).some(([key, value]) => prev[key] !== value);
1327
+ return hasChanged ? { ...initialSelection } : prev;
1320
1328
  });
1321
- setRowSelection(() => ({ ...initialSelection }));
1322
1329
  }, [defaultSelectedIds]);
1323
1330
  const toggleRowSelectionState = react.useCallback((id) => {
1324
1331
  setRowSelection(prevRowSelection => {
package/index.esm.js CHANGED
@@ -1313,11 +1313,18 @@ const useTableSelection = ({ data, idKey, defaultSelectedIds, enableRowSelection
1313
1313
  const [t] = useTranslation();
1314
1314
  const [rowSelection, setRowSelection] = useState({});
1315
1315
  useEffect(() => {
1316
- const initialSelection = {};
1317
- defaultSelectedIds?.forEach(id => {
1318
- initialSelection[String(id)] = true;
1316
+ if (!defaultSelectedIds) {
1317
+ return;
1318
+ }
1319
+ const initialSelection = defaultSelectedIds.reduce((selection, id) => {
1320
+ selection[String(id)] = true;
1321
+ return selection;
1322
+ }, {});
1323
+ setRowSelection(prev => {
1324
+ const hasChanged = objectKeys(prev).length !== objectKeys(initialSelection).length ||
1325
+ objectEntries(initialSelection).some(([key, value]) => prev[key] !== value);
1326
+ return hasChanged ? { ...initialSelection } : prev;
1319
1327
  });
1320
- setRowSelection(() => ({ ...initialSelection }));
1321
1328
  }, [defaultSelectedIds]);
1322
1329
  const toggleRowSelectionState = useCallback((id) => {
1323
1330
  setRowSelection(prevRowSelection => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table",
3
- "version": "1.3.185",
3
+ "version": "1.3.187",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -15,16 +15,16 @@
15
15
  "jest-fetch-mock": "^3.0.3",
16
16
  "@tanstack/react-router": "1.114.29",
17
17
  "tailwind-merge": "^2.0.0",
18
- "@trackunit/react-components": "1.4.144",
19
- "@trackunit/shared-utils": "1.5.120",
20
- "@trackunit/css-class-variance-utilities": "1.3.120",
21
- "@trackunit/ui-icons": "1.3.121",
22
- "@trackunit/react-table-base-components": "1.3.164",
23
- "@trackunit/react-table-pagination": "1.3.120",
24
- "@trackunit/react-form-components": "1.3.164",
25
- "@trackunit/i18n-library-translation": "1.3.135",
26
- "@trackunit/react-core-contexts-api": "1.4.126",
27
- "@trackunit/react-test-setup": "1.0.10"
18
+ "@trackunit/react-components": "1.4.145",
19
+ "@trackunit/shared-utils": "1.5.121",
20
+ "@trackunit/css-class-variance-utilities": "1.3.121",
21
+ "@trackunit/ui-icons": "1.3.122",
22
+ "@trackunit/react-table-base-components": "1.3.165",
23
+ "@trackunit/react-table-pagination": "1.3.121",
24
+ "@trackunit/react-form-components": "1.3.165",
25
+ "@trackunit/i18n-library-translation": "1.3.136",
26
+ "@trackunit/react-core-contexts-api": "1.4.127",
27
+ "@trackunit/react-test-setup": "1.0.11"
28
28
  },
29
29
  "module": "./index.esm.js",
30
30
  "main": "./index.cjs.js",