@@ -23,24 +23,25 @@ export class ActionManager implements IActionManager {
2323
2424 protected events = new Emitter < { busy : { busy : boolean } ; [ viewId : string ] : any } > ( ) ;
2525
26- protected appIdByTriggerId = new Map < string , string | undefined > ( ) ;
26+ protected triggerIdInfo = new Map < string , { appId : string | undefined ; rid : string | undefined } > ( ) ;
2727
2828 protected viewInstances = new Map <
2929 string ,
3030 {
3131 payload ?: {
3232 view : UiKit . ContextualBarView ;
3333 } ;
34+ rid ?: string ;
3435 close : ( ) => void ;
3536 }
3637 > ( ) ;
3738
3839 public constructor ( protected router : ContextType < typeof RouterContext > ) { }
3940
4041 protected invalidateTriggerId ( id : string ) {
41- const appId = this . appIdByTriggerId . get ( id ) ;
42- this . appIdByTriggerId . delete ( id ) ;
43- return appId ;
42+ const info = this . triggerIdInfo . get ( id ) ;
43+ this . triggerIdInfo . delete ( id ) ;
44+ return info ;
4445 }
4546
4647 public on ( viewId : string , listener : ( data : any ) => void ) : void ;
@@ -67,15 +68,20 @@ export class ActionManager implements IActionManager {
6768 this . events . emit ( 'busy' , { busy : false } ) ;
6869 }
6970
70- public generateTriggerId ( appId : string | undefined ) {
71+ public generateTriggerId ( appId : string | undefined , rid ?: string ) {
7172 const triggerId = Random . id ( ) ;
72- this . appIdByTriggerId . set ( triggerId , appId ) ;
73+ this . triggerIdInfo . set ( triggerId , { appId, rid } ) ;
7374 setTimeout ( ( ) => this . invalidateTriggerId ( triggerId ) , ActionManager . TRIGGER_TIMEOUT ) ;
7475 return triggerId ;
7576 }
7677
7778 public async emitInteraction ( appId : string , userInteraction : DistributiveOmit < UiKit . UserInteraction , 'triggerId' > ) {
78- const triggerId = this . generateTriggerId ( appId ) ;
79+ // Get rid from interaction, or fallback to the rid stored for the view
80+ let rid = 'rid' in userInteraction ? userInteraction . rid : undefined ;
81+ if ( ! rid && 'viewId' in userInteraction && userInteraction . viewId ) {
82+ rid = this . getRidByViewId ( userInteraction . viewId ) ;
83+ }
84+ const triggerId = this . generateTriggerId ( appId , rid ) ;
7985
8086 return this . runWithTimeout (
8187 async ( ) => {
@@ -138,11 +144,13 @@ export class ActionManager implements IActionManager {
138144 public handleServerInteraction ( interaction : UiKit . ServerInteraction ) : UiKit . ServerInteraction [ 'type' ] | undefined {
139145 const { triggerId } = interaction ;
140146
141- const appId = this . invalidateTriggerId ( triggerId ) ;
142- if ( ! appId ) {
147+ const triggerInfo = this . invalidateTriggerId ( triggerId ) ;
148+ if ( ! triggerInfo ?. appId ) {
143149 return ;
144150 }
145151
152+ const { rid } = triggerInfo ;
153+
146154 switch ( interaction . type ) {
147155 case 'errors' : {
148156 const { type, triggerId, viewId, appId, errors } = interaction ;
@@ -158,7 +166,7 @@ export class ActionManager implements IActionManager {
158166
159167 case 'modal.open' : {
160168 const { view } = interaction ;
161- this . openModal ( view ) ;
169+ this . openModal ( view , rid ) ;
162170 break ;
163171 }
164172
@@ -230,6 +238,10 @@ export class ActionManager implements IActionManager {
230238 return this . viewInstances . get ( viewId ) ?. payload ;
231239 }
232240
241+ public getRidByViewId ( viewId : string ) {
242+ return this . viewInstances . get ( viewId ) ?. rid ;
243+ }
244+
233245 public openView ( surface : 'modal' , view : UiKit . ModalView ) : void ;
234246
235247 public openView ( surface : 'banner' , view : UiKit . BannerView ) : void ;
@@ -252,16 +264,18 @@ export class ActionManager implements IActionManager {
252264 }
253265 }
254266
255- private openModal ( view : UiKit . ModalView ) {
267+ private openModal ( view : UiKit . ModalView , rid ?: string ) {
256268 const instance = imperativeModal . open ( {
257269 component : UiKitModal ,
258270 props : {
259271 key : view . id ,
260272 initialView : view ,
273+ rid,
261274 } ,
262275 } ) ;
263276
264277 this . viewInstances . set ( view . id , {
278+ rid,
265279 close : ( ) => {
266280 instance . close ( ) ;
267281 this . viewInstances . delete ( view . id ) ;
0 commit comments