@@ -4,7 +4,7 @@ import dataManualSelect from '@sb/mockData/FriendsManualSelect25.json';
4
4
import dataTree from '@sb/mockData/FriendsTree.json' ;
5
5
import type { Meta , StoryObj } from '@storybook/react' ;
6
6
import InputType from '@ui5/webcomponents/dist/types/InputType.js' ;
7
- import { useReducer , useState } from 'react' ;
7
+ import { useCallback , useMemo , useReducer , useState } from 'react' ;
8
8
import { AnalyticalTableSelectionMode , FlexBoxAlignItems , FlexBoxDirection } from '../../enums' ;
9
9
import { Button , CheckBox , Input , Label , ToggleButton , Text } from '../../webComponents' ;
10
10
import { FlexBox } from '../FlexBox' ;
@@ -20,6 +20,7 @@ const pluginsMeta = {
20
20
export default pluginsMeta ;
21
21
type Story = StoryObj < typeof pluginsMeta > ;
22
22
23
+ const tableHooksEmptyCells = [ AnalyticalTableHooks . useAnnounceEmptyCells ] ;
23
24
export const PluginAnnounceEmptyCells : Story = {
24
25
args : {
25
26
data : [
@@ -41,19 +42,21 @@ export const PluginAnnounceEmptyCells: Story = {
41
42
columns = { args . columns }
42
43
data = { args . data }
43
44
visibleRows = { args . visibleRows }
44
- tableHooks = { [ AnalyticalTableHooks . useAnnounceEmptyCells ] }
45
+ tableHooks = { tableHooksEmptyCells }
45
46
/>
46
47
) ;
47
48
} ,
48
49
} ;
49
50
51
+ const disableRowFunc = ( row ) => row . original . age < 40 ;
52
+ const tableHooksDisableRowSel = [ AnalyticalTableHooks . useRowDisableSelection ( disableRowFunc ) ] ;
53
+ const tableHooksDisableRowSel1 = [ AnalyticalTableHooks . useRowDisableSelection ( 'disableSelection' ) ] ;
50
54
export const PluginDisableRowSelection : Story = {
51
55
args : {
52
56
data : dataLarge . map ( ( item ) => ( { ...item , disableSelection : Math . random ( ) < 0.5 } ) ) ,
53
57
selectionMode : AnalyticalTableSelectionMode . Multiple ,
54
58
} ,
55
59
render : ( args ) => {
56
- const disableRowFunc = ( row ) => row . original . age < 40 ;
57
60
const [ isFunc , setIsFunc ] = useState ( true ) ;
58
61
return (
59
62
< >
@@ -78,7 +81,7 @@ export const PluginDisableRowSelection: Story = {
78
81
data = { args . data }
79
82
columns = { args . columns }
80
83
selectionMode = { args . selectionMode }
81
- tableHooks = { [ AnalyticalTableHooks . useRowDisableSelection ( disableRowFunc ) ] }
84
+ tableHooks = { tableHooksDisableRowSel }
82
85
visibleRows = { 10 }
83
86
header = "All under 40 are not selectable"
84
87
/>
@@ -88,7 +91,7 @@ export const PluginDisableRowSelection: Story = {
88
91
columns = { args . columns }
89
92
selectionMode = { args . selectionMode }
90
93
selectionBehavior = { args . selectionBehavior }
91
- tableHooks = { [ AnalyticalTableHooks . useRowDisableSelection ( 'disableSelection' ) ] }
94
+ tableHooks = { tableHooksDisableRowSel1 }
92
95
visibleRows = { 10 }
93
96
header = { `All with "disableSelection: true" are not selectable` }
94
97
/>
@@ -98,6 +101,7 @@ export const PluginDisableRowSelection: Story = {
98
101
} ,
99
102
} ;
100
103
104
+ const tableHooksIndeterminateRowSel = [ AnalyticalTableHooks . useIndeterminateRowSelection ( ) ] ;
101
105
export const PluginIndeterminateRowSelection : Story = {
102
106
render : ( args ) => {
103
107
const [ selectSubRows , setSelectSubRows ] = useReducer ( ( prev ) => ! prev , true ) ;
@@ -111,14 +115,15 @@ export const PluginIndeterminateRowSelection: Story = {
111
115
data = { dataTree }
112
116
columns = { args . columns }
113
117
isTreeTable
114
- tableHooks = { [ AnalyticalTableHooks . useIndeterminateRowSelection ( ) ] }
118
+ tableHooks = { tableHooksIndeterminateRowSel }
115
119
reactTableOptions = { { selectSubRows : selectSubRows } }
116
120
/>
117
121
</ >
118
122
) ;
119
123
} ,
120
124
} ;
121
125
126
+ const tableHooksManualRowSel = [ AnalyticalTableHooks . useManualRowSelect ( 'isSelected' ) ] ;
122
127
export const PluginManualRowSelect : Story = {
123
128
args : {
124
129
data : dataManualSelect ,
@@ -146,7 +151,7 @@ export const PluginManualRowSelect: Story = {
146
151
selectionMode = { AnalyticalTableSelectionMode . Multiple }
147
152
data = { data }
148
153
columns = { args . columns }
149
- tableHooks = { [ AnalyticalTableHooks . useManualRowSelect ( 'isSelected' ) ] }
154
+ tableHooks = { tableHooksManualRowSel }
150
155
/>
151
156
< Button onClick = { setCollapsedCode } > Show first entries in data array</ Button >
152
157
{ ! collapsedCode && (
@@ -175,9 +180,17 @@ export const PluginOnColumnResize: Story = {
175
180
const handleWaitChange = ( e ) => {
176
181
setWait ( parseInt ( e . target . value ) ) ;
177
182
} ;
178
- const handleColWidthUpdate = ( e ) => {
179
- setUseColResizeEvent ( e ) ;
180
- } ;
183
+ const handleColWidthUpdate = useCallback (
184
+ ( e ) => {
185
+ setUseColResizeEvent ( e ) ;
186
+ } ,
187
+ [ setUseColResizeEvent ] ,
188
+ ) ;
189
+
190
+ const tableHooksColResize = useMemo (
191
+ ( ) => [ AnalyticalTableHooks . useOnColumnResize ( handleColWidthUpdate , { liveUpdate, wait } ) ] ,
192
+ [ handleColWidthUpdate , liveUpdate , wait ] ,
193
+ ) ;
181
194
return (
182
195
< >
183
196
< AnalyticalTable
@@ -196,7 +209,7 @@ export const PluginOnColumnResize: Story = {
196
209
}
197
210
data = { args . data }
198
211
columns = { args . columns }
199
- tableHooks = { [ AnalyticalTableHooks . useOnColumnResize ( handleColWidthUpdate , { liveUpdate , wait } ) ] }
212
+ tableHooks = { tableHooksColResize }
200
213
/>
201
214
{ ! ! Object . keys ( useColResizeEvent ) . length && (
202
215
< FlexBox direction = { FlexBoxDirection . Column } >
@@ -266,12 +279,16 @@ export const PluginOrderedMultiSort = {
266
279
} ,
267
280
} ,
268
281
render ( args ) {
282
+ const tableHooksOrderedMultiSort = useMemo (
283
+ ( ) => [ AnalyticalTableHooks . useOrderedMultiSort ( args . orderedIds ) ] ,
284
+ [ args . orderedIds ] ,
285
+ ) ;
269
286
return (
270
287
< AnalyticalTable
271
288
columns = { orderedMultiSortColumns }
272
289
data = { orderedMultiSortData }
273
290
sortable
274
- tableHooks = { [ AnalyticalTableHooks . useOrderedMultiSort ( args . orderedIds ) ] }
291
+ tableHooks = { tableHooksOrderedMultiSort }
275
292
/>
276
293
) ;
277
294
} ,
0 commit comments