1
1
import { actions } from 'react-table' ;
2
2
3
- export const stateReducer = ( prevState , action ) => {
3
+ export const stateReducer = ( state , action , _prevState , instance ) => {
4
4
const { payload } = action ;
5
5
6
- if ( prevState . isRtl && action . type === actions . columnResizing ) {
6
+ if ( state . isRtl && action . type === actions . columnResizing ) {
7
7
const { clientX } = action ;
8
- const { startX, columnWidth, headerIdWidths } = prevState . columnResizing ;
8
+ const { startX, columnWidth, headerIdWidths } = state . columnResizing ;
9
9
10
10
const deltaX = startX - clientX ;
11
11
const percentageDeltaX = deltaX / columnWidth ;
@@ -17,45 +17,53 @@ export const stateReducer = (prevState, action) => {
17
17
} ) ;
18
18
19
19
return {
20
- ...prevState ,
20
+ ...state ,
21
21
columnResizing : {
22
- ...prevState . columnResizing ,
22
+ ...state . columnResizing ,
23
23
columnWidths : {
24
- ...prevState . columnResizing . columnWidths ,
24
+ ...state . columnResizing . columnWidths ,
25
25
...newColumnWidths
26
26
}
27
27
}
28
28
} ;
29
29
}
30
-
31
30
switch ( action . type ) {
31
+ case 'toggleRowExpanded' :
32
+ // this flag disables scrolling to the top of the table if a table is collapsed
33
+ if ( ! state . expanded [ action . id ] ) {
34
+ instance . dispatch ( {
35
+ type : 'ROW_COLLAPSED_FLAG' ,
36
+ payload : true
37
+ } ) ;
38
+ }
39
+ return state ;
32
40
case 'TABLE_RESIZE' :
33
- return { ...prevState , tableClientWidth : payload . tableClientWidth } ;
41
+ return { ...state , tableClientWidth : payload . tableClientWidth } ;
34
42
case 'VISIBLE_ROWS' :
35
- return { ...prevState , visibleRows : payload . visibleRows } ;
43
+ return { ...state , visibleRows : payload . visibleRows } ;
36
44
case 'TABLE_SCROLLING_ENABLED' :
37
- return { ...prevState , isScrollable : payload . isScrollable } ;
45
+ return { ...state , isScrollable : payload . isScrollable } ;
38
46
case 'SET_SELECTED_ROW_IDS' :
39
- return { ...prevState , selectedRowIds : payload . selectedRowIds } ;
47
+ return { ...state , selectedRowIds : payload . selectedRowIds } ;
40
48
case 'SET_POPIN_COLUMNS' :
41
- return { ...prevState , popInColumns : payload } ;
49
+ return { ...state , popInColumns : payload } ;
42
50
case 'INTERACTIVE_ROWS_HAVE_POPIN' :
43
- return { ...prevState , interactiveRowsHavePopIn : payload } ;
51
+ return { ...state , interactiveRowsHavePopIn : payload } ;
44
52
case 'IS_RTL' :
45
- return { ...prevState , isRtl : payload . isRtl } ;
53
+ return { ...state , isRtl : payload . isRtl } ;
46
54
case 'SUB_COMPONENTS_HEIGHT' :
47
- return { ...prevState , subComponentsHeight : payload } ;
55
+ return { ...state , subComponentsHeight : payload } ;
48
56
case 'TABLE_COL_RESIZED' :
49
- return { ...prevState , tableColResized : payload } ;
57
+ return { ...state , tableColResized : payload } ;
50
58
case 'SELECT_ROW_CB' :
51
- return { ...prevState , selectedRowPayload : payload } ;
59
+ return { ...state , selectedRowPayload : payload } ;
52
60
case 'ROW_COLLAPSED_FLAG' :
53
- return { ...prevState , rowCollapsed : payload } ;
61
+ return { ...state , rowCollapsed : payload } ;
54
62
case 'COLUMN_DND_START' :
55
- return { ...prevState , dndColumn : payload } ;
63
+ return { ...state , dndColumn : payload } ;
56
64
case 'COLUMN_DND_END' :
57
- return { ...prevState , dndColumn : '' } ;
65
+ return { ...state , dndColumn : '' } ;
58
66
default :
59
- return prevState ;
67
+ return state ;
60
68
}
61
69
} ;
0 commit comments