Skip to content

Commit 8278f4b

Browse files
authored
fix(AnalyticalTable): only apply selectedRowIds prop if its value has changed (#685)
1 parent 95a1078 commit 8278f4b

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@rollup/plugin-replace": "^2.3.2",
5353
"@storybook/storybook-deployer": "^2.8.6",
5454
"@testing-library/jest-dom": "^5.11.4",
55-
"@testing-library/react": "^11.0.0-beta.1",
55+
"@testing-library/react": "^11.0.2",
5656
"@types/enzyme": "^3.10.5",
5757
"@types/jest": "^26.0.8",
5858
"@types/react": "^16.9.34",

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface TableProps extends CommonProps {
102102
*
103103
* - **Default**: Every column without fixed width gets the maximum available space of the table.
104104
* - **Smart**: Every column gets the space it needs for displaying the full header text. If all headers need more space than the available table width, horizontal scrolling will be enabled. If there is space left, columns with a long content will get more space until there is no more table space left.
105-
* - **Grow**: Every column gets the space it needs for displaying it's full header text and full content of all cells. If it requires more space than the table has, horizontal scrolling will be enabled.
105+
* - **Grow**: Every column gets the space it needs for displaying its full header text and full content of all cells. If it requires more space than the table has, horizontal scrolling will be enabled.
106106
*
107107
*/
108108
scaleWidthMode?: TableScaleWidthMode;
@@ -290,17 +290,8 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
290290
}, [groupBy, setGroupBy]);
291291

292292
useEffect(() => {
293-
toggleAllRowsSelected(false);
294-
const validChars = /^\d+(\.\d+)*$/;
295-
// eslint-disable-next-line guard-for-in
296-
for (const row in selectedRowIds) {
297-
if (reactTableOptions?.getRowId) {
298-
toggleRowSelected(row, selectedRowIds[row]);
299-
} else if (validChars.test(row)) {
300-
toggleRowSelected(row, selectedRowIds[row]);
301-
}
302-
}
303-
}, [toggleRowSelected, toggleAllRowsSelected, selectedRowIds, reactTableOptions?.getRowId]);
293+
dispatch({ type: 'SET_SELECTED_ROW_IDS', payload: { selectedRowIds } });
294+
}, [selectedRowIds]);
304295

305296
const calcRowHeight = parseInt(
306297
getComputedStyle(tableRef.current ?? document.body).getPropertyValue('--sapWcrAnalyticalTableRowHeight') || '44'

packages/main/src/components/AnalyticalTable/tableReducer/stateReducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export const stateReducer = (newState, action) => {
55
return { ...newState, tableClientWidth: payload.tableClientWidth };
66
case 'TABLE_SCROLLING_ENABLED':
77
return { ...newState, isScrollable: payload.isScrollable };
8+
case 'SET_SELECTED_ROW_IDS':
9+
return { ...newState, selectedRowIds: payload.selectedRowIds };
810
default:
911
return newState;
1012
}

yarn.lock

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@
20762076
core-js-pure "^3.0.0"
20772077
regenerator-runtime "^0.13.4"
20782078

2079-
"@babel/[email protected]", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2":
2079+
"@babel/[email protected]", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.11.2", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2":
20802080
version "7.11.0"
20812081
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.11.0.tgz#f10245877042a815e07f7e693faff0ae9d3a2aac"
20822082
integrity sha512-qArkXsjJq7H+T86WrIFV0Fnu/tNOkZ4cgXmjkzAu3b/58D5mFIO8JH/y77t7C9q0OdDRdh9s7Ue5GasYssxtXw==
@@ -4390,14 +4390,16 @@
43904390
dependencies:
43914391
defer-to-connect "^2.0.0"
43924392

4393-
"@testing-library/dom@^7.22.3":
4394-
version "7.23.0"
4395-
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.23.0.tgz#c54c0fa53705ad867bcefb52fc0c96487fbc10f6"
4396-
integrity sha512-H5m090auYH+obdZmsaYLrSWC5OauWD2CvNbz88KBxQJoXgkJzbU0DpAG8BS7Evj5WqCC3nAAKrLS6vw0ljUYLg==
4393+
"@testing-library/dom@^7.24.2":
4394+
version "7.24.2"
4395+
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.24.2.tgz#6d2b7dd21efbd5358b98c2777fc47c252f3ae55e"
4396+
integrity sha512-ERxcZSoHx0EcN4HfshySEWmEf5Kkmgi+J7O79yCJ3xggzVlBJ2w/QjJUC+EBkJJ2OeSw48i3IoePN4w8JlVUIA==
43974397
dependencies:
4398+
"@babel/code-frame" "^7.10.4"
43984399
"@babel/runtime" "^7.10.3"
43994400
"@types/aria-query" "^4.2.0"
44004401
aria-query "^4.2.2"
4402+
chalk "^4.1.0"
44014403
dom-accessibility-api "^0.5.1"
44024404
pretty-format "^26.4.2"
44034405

@@ -4415,13 +4417,13 @@
44154417
lodash "^4.17.15"
44164418
redent "^3.0.0"
44174419

4418-
"@testing-library/react@^11.0.0-beta.1":
4419-
version "11.0.0-beta.1"
4420-
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.0.0-beta.1.tgz#14b4a418f8e9a1fb48ca7ac5d69b4a017a4bab54"
4421-
integrity sha512-tbuEjYCQiYGIYw7IG2V5uCwo+E5rpZXd5bEHH+FcLVncMvCOenWC5mMwhgt1YPaLJyBtYeQ1MoDNvpMFKm1rpQ==
4420+
"@testing-library/react@^11.0.2":
4421+
version "11.0.4"
4422+
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.0.4.tgz#c84082bfe1593d8fcd475d46baee024452f31dee"
4423+
integrity sha512-U0fZO2zxm7M0CB5h1+lh31lbAwMSmDMEMGpMT3BUPJwIjDEKYWOV4dx7lb3x2Ue0Pyt77gmz/VropuJnSz/Iew==
44224424
dependencies:
4423-
"@babel/runtime" "^7.10.3"
4424-
"@testing-library/dom" "^7.22.3"
4425+
"@babel/runtime" "^7.11.2"
4426+
"@testing-library/dom" "^7.24.2"
44254427

44264428
"@types/anymatch@*":
44274429
version "1.3.1"
@@ -7064,7 +7066,7 @@ chalk@^3.0.0:
70647066
ansi-styles "^4.1.0"
70657067
supports-color "^7.1.0"
70667068

7067-
chalk@^4.0.0:
7069+
chalk@^4.0.0, chalk@^4.1.0:
70687070
version "4.1.0"
70697071
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a"
70707072
integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==

0 commit comments

Comments
 (0)