@@ -18,14 +18,9 @@ import {
18
18
SUCCESS_MESSAGE_TEXT ,
19
19
} from '../constants' ;
20
20
import type { DialogComponent } from '../modal/components/Dialog' ;
21
- import type { DialogLifecycleCallbacks , feedback2ModalIntegration } from '../modal/integration' ;
21
+ import type { feedback2ModalIntegration } from '../modal/integration' ;
22
22
import type { feedback2ScreenshotIntegration } from '../screenshot/integration' ;
23
- import type {
24
- FeedbackCallbacks ,
25
- FeedbackFormData ,
26
- FeedbackInternalOptions ,
27
- OptionalFeedbackConfiguration ,
28
- } from '../types' ;
23
+ import type { FeedbackCallbacks , FeedbackInternalOptions , OptionalFeedbackConfiguration } from '../types' ;
29
24
import { DEBUG_BUILD } from '../util/debug-build' ;
30
25
import { mergeOptions } from '../util/mergeOptions' ;
31
26
import { Actor } from './components/Actor' ;
@@ -70,21 +65,21 @@ export class Feedback2 implements Integration {
70
65
*/
71
66
private _shadow : ShadowRoot | null ;
72
67
73
- /**
74
- * The sentry-provided button to trigger the modal
75
- */
76
- private _triggerButton : null | any ;
68
+ // / **
69
+ // * The sentry-provided button to trigger the modal
70
+ // */
71
+ // private _triggerButton: null | any;
77
72
78
- /**
79
- * The integration that we will use to render the modal
80
- * This value can be either passed in, or will be async loaded
81
- */
82
- private _dialogRenderStrategy : null | any ;
73
+ // / **
74
+ // * The integration that we will use to render the modal
75
+ // * This value can be either passed in, or will be async loaded
76
+ // */
77
+ // private _dialogRenderStrategy: null | any;
83
78
84
79
/**
85
- * The ModalComponent itself, as rendered on the screen
80
+ * The DialogComponent itself, as rendered on the screen
86
81
*/
87
- private _modal : null | any ;
82
+ private _dialog : null | DialogComponent ;
88
83
89
84
public constructor ( {
90
85
// FeedbackGeneralConfiguration
@@ -169,6 +164,8 @@ export class Feedback2 implements Integration {
169
164
170
165
this . _host = null ;
171
166
this . _shadow = null ;
167
+
168
+ this . _dialog = null ;
172
169
}
173
170
174
171
/**
@@ -196,13 +193,9 @@ export class Feedback2 implements Integration {
196
193
insertActor ( ) ;
197
194
options . onFormClose && options . onFormClose ( ) ;
198
195
} ,
199
- onSubmitSuccess ( data : FeedbackFormData ) {
200
- insertActor ( ) ;
201
- options . onSubmitSuccess && options . onSubmitSuccess ( data ) ;
202
- } ,
203
- onSubmitError ( ) {
196
+ onFormSubmitted ( ) {
204
197
insertActor ( ) ;
205
- options . onSubmitError && options . onSubmitError ( ) ;
198
+ options . onFormSubmitted && options . onFormSubmitted ( ) ;
206
199
} ,
207
200
} ) ;
208
201
@@ -237,19 +230,8 @@ export class Feedback2 implements Integration {
237
230
}
238
231
239
232
const handleClick = async ( ) : Promise < void > => {
240
- const shadow = this . _getShadow ( options ) ; // options have not changed, because optionOverrides is a subset!
241
-
242
- await this . _loadAndRenderDialog ( options , {
243
- onCreate : ( dialog : DialogComponent ) => {
244
- shadow . appendChild ( dialog . style ) ;
245
- shadow . appendChild ( dialog . el ) ;
246
- } ,
247
- onSubmit : sendFeedback ,
248
- onDone ( dialog : DialogComponent ) {
249
- shadow . removeChild ( dialog . el ) ;
250
- shadow . removeChild ( dialog . style ) ;
251
- } ,
252
- } ) ;
233
+ const dialog = await this . _loadAndRenderDialog ( options ) ;
234
+ dialog . open ( ) ;
253
235
} ;
254
236
targetEl . addEventListener ( 'click' , handleClick ) ;
255
237
return ( ) => {
@@ -260,29 +242,19 @@ export class Feedback2 implements Integration {
260
242
/**
261
243
* Creates a new widget. Accepts partial options to override any options passed to constructor.
262
244
*/
263
- public createWidget ( optionOverrides : OptionalFeedbackConfiguration & { shouldCreateActor ?: boolean } = { } ) : null {
264
- // FeedbackWidget
245
+ public createWidget (
246
+ optionOverrides : OptionalFeedbackConfiguration & { shouldCreateActor ?: boolean } = { } ,
247
+ ) : Promise < DialogComponent > {
265
248
const options = mergeOptions ( this . options , optionOverrides ) ;
266
249
267
- // the dialog should have some standard callbacks:
268
- // onFormClose: () => this._triggerButton.show(); this.options.onFormClose()
269
- // onFormOpen: () => this._triggerButton.hide(); this.options.onFormOpen()
270
- // onSubmitError: () => this._triggerButton.show(); this.options.onSubmitError();
271
- // onSubmitSuccess: () => this._triggerButton.show(); this.options.onSubmitSuccss();
272
- //
273
- // actually, we might want to rename the callbacks that the form itself takes... or expand the list so that
274
- // we can allow the form to render the SuccessMessage
275
-
276
- return null ;
250
+ return this . _loadAndRenderDialog ( options ) ;
277
251
}
278
252
279
253
/**
280
- * Returns the default (first-created) widget
254
+ * Returns the default widget, if it exists
281
255
*/
282
- public getWidget ( ) : null {
283
- // FeedbackWidget (incl dialog!)
284
- //
285
- return null ;
256
+ public getWidget ( ) : DialogComponent | null {
257
+ return this . _dialog ;
286
258
}
287
259
288
260
/**
@@ -291,21 +263,25 @@ export class Feedback2 implements Integration {
291
263
* created during initialization of the integration.
292
264
*/
293
265
public openDialog ( ) : void {
294
- //
266
+ this . _dialog && this . _dialog . open ( ) ;
295
267
}
296
268
297
269
/**
298
270
* Closes the dialog for the default widget, if it exists
299
271
*/
300
272
public closeDialog ( ) : void {
301
- //
273
+ this . _dialog && this . _dialog . close ( ) ;
302
274
}
303
275
304
276
/**
305
- * Removes a single widget
277
+ * Removes the rendered widget, if it exists
306
278
*/
307
279
public removeWidget ( _widget : null | undefined ) : void {
308
- //
280
+ if ( this . _shadow && this . _dialog ) {
281
+ this . _shadow . removeChild ( this . _dialog . el ) ;
282
+ this . _shadow . removeChild ( this . _dialog . style ) ;
283
+ }
284
+ this . _dialog = null ;
309
285
}
310
286
311
287
/**
@@ -348,10 +324,11 @@ export class Feedback2 implements Integration {
348
324
/**
349
325
*
350
326
*/
351
- protected async _loadAndRenderDialog (
352
- options : FeedbackInternalOptions ,
353
- callbacks : DialogLifecycleCallbacks ,
354
- ) : Promise < void > {
327
+ protected async _loadAndRenderDialog ( options : FeedbackInternalOptions ) : Promise < DialogComponent > {
328
+ if ( this . _dialog ) {
329
+ return this . _dialog ;
330
+ }
331
+
355
332
const client = getClient < BrowserClient > ( ) ;
356
333
if ( ! client ) {
357
334
throw new Error ( 'Sentry Client is not initialized correctly' ) ;
@@ -387,7 +364,21 @@ export class Feedback2 implements Integration {
387
364
throw new Error ( 'Not implemented yet' ) ;
388
365
}
389
366
367
+ const shadow = this . _getShadow ( options ) ;
368
+
390
369
// TODO: some combination stuff when screenshots exists:
391
- modalIntegration . renderDialog ( options , callbacks ) ;
370
+ this . _dialog = modalIntegration . createDialog ( options , {
371
+ onCreate : ( dialog : DialogComponent ) => {
372
+ shadow . appendChild ( dialog . style ) ;
373
+ shadow . appendChild ( dialog . el ) ;
374
+ } ,
375
+ onSubmit : sendFeedback ,
376
+ onDone : ( dialog : DialogComponent ) => {
377
+ shadow . removeChild ( dialog . el ) ;
378
+ shadow . removeChild ( dialog . style ) ;
379
+ this . _dialog = null ;
380
+ } ,
381
+ } ) ;
382
+ return this . _dialog ;
392
383
}
393
384
}
0 commit comments