@@ -30,7 +30,7 @@ import {
3030 UseBulkSelectionProps ,
3131 UseBulkSelectionReturnType ,
3232} from './types'
33- import { CHECKBOX_VALUE , noop } from '../../../Common'
33+ import { CHECKBOX_VALUE , noop , useEffectAfterMount } from '../../../Common'
3434
3535// giving type any here since not exporting this context, rather using it through useBulkSelection hook which is typed
3636const BulkSelectionContext = createContext < UseBulkSelectionReturnType < any > > ( {
@@ -39,6 +39,7 @@ const BulkSelectionContext = createContext<UseBulkSelectionReturnType<any>>({
3939 isChecked : false ,
4040 checkboxValue : CHECKBOX_VALUE . CHECKED ,
4141 isBulkSelectionApplied : false ,
42+ setIdentifiers : noop ,
4243 getSelectedIdentifiersCount : noop ,
4344} )
4445
@@ -52,10 +53,17 @@ export const useBulkSelection = <T,>() => {
5253
5354export const BulkSelectionProvider = < T , > ( {
5455 children,
55- identifiers,
56+ identifiers = null ,
5657 getSelectAllDialogStatus,
5758} : UseBulkSelectionProps < T > ) => {
5859 const [ selectedIdentifiers , setSelectedIdentifiers ] = useState < T > ( { } as T )
60+ const [ identifiersOnCurrentPage , setIdentifiersOnCurrentPage ] = useState ( identifiers ?? ( { } as T ) )
61+
62+ useEffectAfterMount ( ( ) => {
63+ if ( identifiers ) {
64+ setIdentifiersOnCurrentPage ( identifiers )
65+ }
66+ } , [ identifiers ] )
5967
6068 const isBulkSelectionApplied = selectedIdentifiers [ SELECT_ALL_ACROSS_PAGES_LOCATOR ]
6169
@@ -96,7 +104,7 @@ export const BulkSelectionProvider = <T,>({
96104 variant : ToastVariantType . info ,
97105 description : CLEAR_SELECTIONS_WARNING ,
98106 } )
99- setIdentifiersAfterClear ( identifiers , selectedIds )
107+ setIdentifiersAfterClear ( identifiersOnCurrentPage , selectedIds )
100108 break
101109 }
102110
@@ -137,7 +145,7 @@ export const BulkSelectionProvider = <T,>({
137145 } )
138146 }
139147
140- setIdentifiersAfterPageSelection ( identifiers )
148+ setIdentifiersAfterPageSelection ( identifiersOnCurrentPage )
141149 break
142150 }
143151
@@ -169,7 +177,7 @@ export const BulkSelectionProvider = <T,>({
169177 }
170178
171179 // if all the identifiers are selected then CHECKED else intermediate
172- const areAllPresentIdentifiersSelected = Object . keys ( identifiers ) . every (
180+ const areAllPresentIdentifiersSelected = Object . keys ( identifiersOnCurrentPage ) . every (
173181 ( identifierId ) => selectedIdentifiers [ identifierId ] ,
174182 )
175183
@@ -196,8 +204,17 @@ export const BulkSelectionProvider = <T,>({
196204 checkboxValue,
197205 isBulkSelectionApplied,
198206 getSelectedIdentifiersCount,
207+ setIdentifiers : setIdentifiersOnCurrentPage ,
199208 } ) ,
200- [ selectedIdentifiers , handleBulkSelection , isChecked , checkboxValue , getSelectedIdentifiersCount ] ,
209+ [
210+ selectedIdentifiers ,
211+ handleBulkSelection ,
212+ isChecked ,
213+ checkboxValue ,
214+ getSelectedIdentifiersCount ,
215+ identifiersOnCurrentPage ,
216+ isBulkSelectionApplied ,
217+ ] ,
201218 )
202219
203220 return < BulkSelectionContext . Provider value = { value } > { children } </ BulkSelectionContext . Provider >
0 commit comments