@@ -4,7 +4,7 @@ import dataManualSelect from '@sb/mockData/FriendsManualSelect25.json';
44import dataTree from '@sb/mockData/FriendsTree.json' ;
55import type { Meta , StoryObj } from '@storybook/react' ;
66import InputType from '@ui5/webcomponents/dist/types/InputType.js' ;
7- import { useReducer , useState } from 'react' ;
7+ import { useCallback , useMemo , useReducer , useState } from 'react' ;
88import { AnalyticalTableSelectionMode , FlexBoxAlignItems , FlexBoxDirection } from '../../enums' ;
99import { Button , CheckBox , Input , Label , ToggleButton , Text } from '../../webComponents' ;
1010import { FlexBox } from '../FlexBox' ;
@@ -20,6 +20,7 @@ const pluginsMeta = {
2020export default pluginsMeta ;
2121type Story = StoryObj < typeof pluginsMeta > ;
2222
23+ const tableHooksEmptyCells = [ AnalyticalTableHooks . useAnnounceEmptyCells ] ;
2324export const PluginAnnounceEmptyCells : Story = {
2425 args : {
2526 data : [
@@ -41,19 +42,21 @@ export const PluginAnnounceEmptyCells: Story = {
4142 columns = { args . columns }
4243 data = { args . data }
4344 visibleRows = { args . visibleRows }
44- tableHooks = { [ AnalyticalTableHooks . useAnnounceEmptyCells ] }
45+ tableHooks = { tableHooksEmptyCells }
4546 />
4647 ) ;
4748 } ,
4849} ;
4950
51+ const disableRowFunc = ( row ) => row . original . age < 40 ;
52+ const tableHooksDisableRowSel = [ AnalyticalTableHooks . useRowDisableSelection ( disableRowFunc ) ] ;
53+ const tableHooksDisableRowSel1 = [ AnalyticalTableHooks . useRowDisableSelection ( 'disableSelection' ) ] ;
5054export const PluginDisableRowSelection : Story = {
5155 args : {
5256 data : dataLarge . map ( ( item ) => ( { ...item , disableSelection : Math . random ( ) < 0.5 } ) ) ,
5357 selectionMode : AnalyticalTableSelectionMode . Multiple ,
5458 } ,
5559 render : ( args ) => {
56- const disableRowFunc = ( row ) => row . original . age < 40 ;
5760 const [ isFunc , setIsFunc ] = useState ( true ) ;
5861 return (
5962 < >
@@ -78,7 +81,7 @@ export const PluginDisableRowSelection: Story = {
7881 data = { args . data }
7982 columns = { args . columns }
8083 selectionMode = { args . selectionMode }
81- tableHooks = { [ AnalyticalTableHooks . useRowDisableSelection ( disableRowFunc ) ] }
84+ tableHooks = { tableHooksDisableRowSel }
8285 visibleRows = { 10 }
8386 header = "All under 40 are not selectable"
8487 />
@@ -88,7 +91,7 @@ export const PluginDisableRowSelection: Story = {
8891 columns = { args . columns }
8992 selectionMode = { args . selectionMode }
9093 selectionBehavior = { args . selectionBehavior }
91- tableHooks = { [ AnalyticalTableHooks . useRowDisableSelection ( 'disableSelection' ) ] }
94+ tableHooks = { tableHooksDisableRowSel1 }
9295 visibleRows = { 10 }
9396 header = { `All with "disableSelection: true" are not selectable` }
9497 />
@@ -98,6 +101,7 @@ export const PluginDisableRowSelection: Story = {
98101 } ,
99102} ;
100103
104+ const tableHooksIndeterminateRowSel = [ AnalyticalTableHooks . useIndeterminateRowSelection ( ) ] ;
101105export const PluginIndeterminateRowSelection : Story = {
102106 render : ( args ) => {
103107 const [ selectSubRows , setSelectSubRows ] = useReducer ( ( prev ) => ! prev , true ) ;
@@ -111,14 +115,15 @@ export const PluginIndeterminateRowSelection: Story = {
111115 data = { dataTree }
112116 columns = { args . columns }
113117 isTreeTable
114- tableHooks = { [ AnalyticalTableHooks . useIndeterminateRowSelection ( ) ] }
118+ tableHooks = { tableHooksIndeterminateRowSel }
115119 reactTableOptions = { { selectSubRows : selectSubRows } }
116120 />
117121 </ >
118122 ) ;
119123 } ,
120124} ;
121125
126+ const tableHooksManualRowSel = [ AnalyticalTableHooks . useManualRowSelect ( 'isSelected' ) ] ;
122127export const PluginManualRowSelect : Story = {
123128 args : {
124129 data : dataManualSelect ,
@@ -146,7 +151,7 @@ export const PluginManualRowSelect: Story = {
146151 selectionMode = { AnalyticalTableSelectionMode . Multiple }
147152 data = { data }
148153 columns = { args . columns }
149- tableHooks = { [ AnalyticalTableHooks . useManualRowSelect ( 'isSelected' ) ] }
154+ tableHooks = { tableHooksManualRowSel }
150155 />
151156 < Button onClick = { setCollapsedCode } > Show first entries in data array</ Button >
152157 { ! collapsedCode && (
@@ -175,9 +180,17 @@ export const PluginOnColumnResize: Story = {
175180 const handleWaitChange = ( e ) => {
176181 setWait ( parseInt ( e . target . value ) ) ;
177182 } ;
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+ ) ;
181194 return (
182195 < >
183196 < AnalyticalTable
@@ -196,7 +209,7 @@ export const PluginOnColumnResize: Story = {
196209 }
197210 data = { args . data }
198211 columns = { args . columns }
199- tableHooks = { [ AnalyticalTableHooks . useOnColumnResize ( handleColWidthUpdate , { liveUpdate , wait } ) ] }
212+ tableHooks = { tableHooksColResize }
200213 />
201214 { ! ! Object . keys ( useColResizeEvent ) . length && (
202215 < FlexBox direction = { FlexBoxDirection . Column } >
@@ -266,12 +279,16 @@ export const PluginOrderedMultiSort = {
266279 } ,
267280 } ,
268281 render ( args ) {
282+ const tableHooksOrderedMultiSort = useMemo (
283+ ( ) => [ AnalyticalTableHooks . useOrderedMultiSort ( args . orderedIds ) ] ,
284+ [ args . orderedIds ] ,
285+ ) ;
269286 return (
270287 < AnalyticalTable
271288 columns = { orderedMultiSortColumns }
272289 data = { orderedMultiSortData }
273290 sortable
274- tableHooks = { [ AnalyticalTableHooks . useOrderedMultiSort ( args . orderedIds ) ] }
291+ tableHooks = { tableHooksOrderedMultiSort }
275292 />
276293 ) ;
277294 } ,
0 commit comments