@@ -108,13 +108,30 @@ interface StudioRecorderState {
108
108
canAccessStudioAI : boolean
109
109
showUrlPrompt : boolean
110
110
cloudStudioRequested : boolean
111
- cloudStudioSessionId ?: string
111
+ sessionId ?: string
112
112
_isStudioCreatedTest : boolean
113
113
newTestLineNumber ?: number
114
114
}
115
115
116
+ function getUrlParams ( ) {
117
+ const url = new URL ( window . location . href )
118
+ const hashParams = new URLSearchParams ( url . hash )
119
+
120
+ const testId = hashParams . get ( 'testId' )
121
+ const suiteId = hashParams . get ( 'suiteId' )
122
+ const visitUrl = hashParams . get ( 'url' )
123
+ const newTestLineNumber = hashParams . get ( 'newTestLineNumber' ) ? Number ( hashParams . get ( 'newTestLineNumber' ) ) : undefined
124
+ const sessionId = hashParams . get ( 'sessionId' )
125
+
126
+ return { testId, suiteId, url : visitUrl , newTestLineNumber, sessionId }
127
+ }
128
+
116
129
export const useStudioStore = defineStore ( 'studioRecorder' , {
117
130
state : ( ) : StudioRecorderState => {
131
+ // try to restore sessionId from URL parameters
132
+ const urlParams = getUrlParams ( )
133
+ const persistedSessionId = urlParams . sessionId || undefined
134
+
118
135
return {
119
136
saveModalIsOpen : false ,
120
137
instructionModalIsOpen : false ,
@@ -128,7 +145,7 @@ export const useStudioStore = defineStore('studioRecorder', {
128
145
canAccessStudioAI : false ,
129
146
showUrlPrompt : true ,
130
147
cloudStudioRequested : false ,
131
- cloudStudioSessionId : undefined ,
148
+ sessionId : persistedSessionId ,
132
149
newTestLineNumber : undefined ,
133
150
_isStudioCreatedTest : false ,
134
151
}
@@ -160,8 +177,14 @@ export const useStudioStore = defineStore('studioRecorder', {
160
177
this . canAccessStudioAI = canAccessStudioAI
161
178
} ,
162
179
163
- setCloudStudioSessionId ( cloudStudioSessionId : string ) {
164
- this . cloudStudioSessionId = cloudStudioSessionId
180
+ setSessionId ( sessionId : string ) {
181
+ this . sessionId = sessionId
182
+ this . _updateUrlParams ( [ 'sessionId' ] )
183
+ } ,
184
+
185
+ clearSessionId ( ) {
186
+ this . sessionId = undefined
187
+ this . _removeUrlParams ( [ 'sessionId' ] )
165
188
} ,
166
189
167
190
setNewTestLineNumber ( newTestLineNumber : number ) {
@@ -213,7 +236,7 @@ export const useStudioStore = defineStore('studioRecorder', {
213
236
} ,
214
237
215
238
setup ( config ) {
216
- const studio = this . _getUrlParams ( )
239
+ const studio = this . getUrlParams ( )
217
240
218
241
if ( studio . newTestLineNumber ) {
219
242
this . setNewTestLineNumber ( studio . newTestLineNumber )
@@ -227,6 +250,10 @@ export const useStudioStore = defineStore('studioRecorder', {
227
250
this . _initialUrl = studio . url
228
251
}
229
252
253
+ if ( studio . sessionId ) {
254
+ this . sessionId = studio . sessionId
255
+ }
256
+
230
257
// if we have an existing test or are creating a new test, we need to start loading
231
258
// otherwise if we have a suite, we can just set the studio active
232
259
if ( this . testId || studio . newTestLineNumber ) {
@@ -308,6 +335,7 @@ export const useStudioStore = defineStore('studioRecorder', {
308
335
this . clearRunnableIds ( )
309
336
this . _removeUrlParams ( )
310
337
this . _initialUrl = undefined
338
+ this . clearSessionId ( )
311
339
} ,
312
340
313
341
startSave ( ) {
@@ -436,21 +464,11 @@ export const useStudioStore = defineStore('studioRecorder', {
436
464
}
437
465
} ,
438
466
439
- _getUrlParams ( ) {
440
- const url = new URL ( window . location . href )
441
- const hashParams = new URLSearchParams ( url . hash )
442
-
443
- const testId = hashParams . get ( 'testId' )
444
- const suiteId = hashParams . get ( 'suiteId' )
445
- const visitUrl = hashParams . get ( 'url' )
446
- const newTestLineNumber = hashParams . get ( 'newTestLineNumber' ) ? Number ( hashParams . get ( 'newTestLineNumber' ) ) : undefined
447
-
448
- return { testId, suiteId, url : visitUrl , newTestLineNumber }
449
- } ,
467
+ getUrlParams,
450
468
451
- _updateUrlParams ( filter : string [ ] = [ 'testId' , 'suiteId' , 'url' , 'newTestLineNumber' ] ) {
469
+ _updateUrlParams ( filter : string [ ] = [ 'testId' , 'suiteId' , 'url' , 'newTestLineNumber' , 'sessionId' ] ) {
452
470
// if we don't have studio params, we don't need to update them
453
- if ( ! this . testId && ! this . suiteId && ! this . url && ! this . newTestLineNumber ) return
471
+ if ( ! this . testId && ! this . suiteId && ! this . url && ! this . newTestLineNumber && ! this . sessionId ) return
454
472
455
473
// if we have studio params, we need to remove them before adding them back
456
474
this . _removeUrlParams ( filter )
@@ -469,7 +487,7 @@ export const useStudioStore = defineStore('studioRecorder', {
469
487
window . history . replaceState ( { } , '' , url . toString ( ) )
470
488
} ,
471
489
472
- _removeUrlParams ( filter : string [ ] = [ 'testId' , 'suiteId' , 'url' , 'newTestLineNumber' ] ) {
490
+ _removeUrlParams ( filter : string [ ] = [ 'testId' , 'suiteId' , 'url' , 'newTestLineNumber' , 'sessionId' ] ) {
473
491
const url = new URL ( window . location . href )
474
492
const hashParams = new URLSearchParams ( url . hash )
475
493
@@ -482,7 +500,7 @@ export const useStudioStore = defineStore('studioRecorder', {
482
500
} )
483
501
484
502
// if there are no studio specific params left, we can also remove the studio param
485
- if ( ! hashParams . has ( 'testId' ) && ! hashParams . has ( 'suiteId' ) && ! hashParams . has ( 'url' ) && ! hashParams . has ( 'newTestLineNumber' ) ) {
503
+ if ( ! hashParams . has ( 'testId' ) && ! hashParams . has ( 'suiteId' ) && ! hashParams . has ( 'url' ) && ! hashParams . has ( 'newTestLineNumber' ) && ! hashParams . has ( 'sessionId' ) ) {
486
504
hashParams . delete ( 'studio' )
487
505
}
488
506
0 commit comments