Skip to content

Commit 1f32141

Browse files
committed
Add support for associated event ID in user feedback dialog
Cleaned SentryUserFeedbackDialog.Builder methods SentryFeedbackOptions is not Internal anymore
1 parent 561dee1 commit 1f32141

File tree

13 files changed

+87
-48
lines changed

13 files changed

+87
-48
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

77
- Add `SentryUserFeedbackButton` Composable ([#4559](https://github.com/getsentry/sentry-java/pull/4559))
8+
- Also added `Sentry.showUserFeedbackDialog` static method
89

910
### Fixes
1011

sentry-android-core/api/sentry-android-core.api

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,10 @@ public final class io/sentry/android/core/SentryUserFeedbackDialog : android/app
402402
public class io/sentry/android/core/SentryUserFeedbackDialog$Builder {
403403
public fun <init> (Landroid/content/Context;)V
404404
public fun <init> (Landroid/content/Context;I)V
405-
public fun <init> (Landroid/content/Context;ILio/sentry/android/core/SentryUserFeedbackDialog$OptionsConfiguration;Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;)V
406-
public fun <init> (Landroid/content/Context;Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;)V
405+
public fun <init> (Landroid/content/Context;ILio/sentry/android/core/SentryUserFeedbackDialog$OptionsConfiguration;)V
407406
public fun <init> (Landroid/content/Context;Lio/sentry/android/core/SentryUserFeedbackDialog$OptionsConfiguration;)V
407+
public fun associatedEventId (Lio/sentry/protocol/SentryId;)Lio/sentry/android/core/SentryUserFeedbackDialog$Builder;
408+
public fun configurator (Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;)Lio/sentry/android/core/SentryUserFeedbackDialog$Builder;
408409
public fun create ()Lio/sentry/android/core/SentryUserFeedbackDialog;
409410
}
410411

sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
1717
import io.sentry.protocol.Mechanism;
1818
import io.sentry.protocol.SdkVersion;
19+
import io.sentry.protocol.SentryId;
1920
import org.jetbrains.annotations.ApiStatus;
2021
import org.jetbrains.annotations.NotNull;
2122
import org.jetbrains.annotations.Nullable;
@@ -615,7 +616,9 @@ public void setEnableAutoTraceIdGeneration(final boolean enableAutoTraceIdGenera
615616

616617
static class AndroidUserFeedbackIDialogHandler implements SentryFeedbackOptions.IDialogHandler {
617618
@Override
618-
public void showDialog(final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
619+
public void showDialog(
620+
final @Nullable SentryId associatedEventId,
621+
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
619622
final @Nullable Activity activity = CurrentActivityHolder.getInstance().getActivity();
620623
if (activity == null) {
621624
Sentry.getCurrentScopes()
@@ -628,7 +631,11 @@ public void showDialog(final @Nullable SentryFeedbackOptions.OptionsConfigurator
628631
return;
629632
}
630633

631-
new SentryUserFeedbackDialog.Builder(activity, configurator).create().show();
634+
new SentryUserFeedbackDialog.Builder(activity)
635+
.associatedEventId(associatedEventId)
636+
.configurator(configurator)
637+
.create()
638+
.show();
632639
}
633640
}
634641
}

sentry-android-core/src/main/java/io/sentry/android/core/SentryUserFeedbackDialog.java

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public final class SentryUserFeedbackDialog extends AlertDialog {
2525

2626
private boolean isCancelable = false;
2727
private @Nullable SentryId currentReplayId;
28+
private final @Nullable SentryId associatedEventId;
2829
private @Nullable OnDismissListener delegate;
2930

3031
private final @Nullable OptionsConfiguration configuration;
@@ -33,9 +34,11 @@ public final class SentryUserFeedbackDialog extends AlertDialog {
3334
SentryUserFeedbackDialog(
3435
final @NotNull Context context,
3536
final int themeResId,
37+
final @Nullable SentryId associatedEventId,
3638
final @Nullable OptionsConfiguration configuration,
3739
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
3840
super(context, themeResId);
41+
this.associatedEventId = associatedEventId;
3942
this.configuration = configuration;
4043
this.configurator = configurator;
4144
SentryIntegrationPackageStorage.getInstance().addIntegration("UserFeedbackWidget");
@@ -151,6 +154,9 @@ protected void onCreate(Bundle savedInstanceState) {
151154
final @NotNull Feedback feedback = new Feedback(message);
152155
feedback.setName(name);
153156
feedback.setContactEmail(email);
157+
if (associatedEventId != null) {
158+
feedback.setAssociatedEventId(associatedEventId);
159+
}
154160
if (currentReplayId != null) {
155161
feedback.setReplayId(currentReplayId);
156162
}
@@ -233,6 +239,7 @@ public static class Builder {
233239

234240
@Nullable OptionsConfiguration configuration;
235241
@Nullable SentryFeedbackOptions.OptionsConfigurator configurator;
242+
@Nullable SentryId associatedEventId;
236243
final @NotNull Context context;
237244
final int themeResId;
238245

@@ -271,7 +278,7 @@ public Builder(final @NotNull Context context) {
271278
* {@code 0} to use the parent {@code context}'s default alert dialog theme
272279
*/
273280
public Builder(Context context, int themeResId) {
274-
this(context, themeResId, null, null);
281+
this(context, themeResId, null);
275282
}
276283

277284
/**
@@ -288,25 +295,7 @@ public Builder(Context context, int themeResId) {
288295
*/
289296
public Builder(
290297
final @NotNull Context context, final @Nullable OptionsConfiguration configuration) {
291-
this(context, 0, configuration, null);
292-
}
293-
294-
/**
295-
* Creates a builder for a {@link SentryUserFeedbackDialog} that uses the default alert dialog
296-
* theme. The {@code configuration} can be used to configure the feedback options for this
297-
* specific dialog.
298-
*
299-
* <p>The default alert dialog theme is defined by {@link android.R.attr#alertDialogTheme}
300-
* within the parent {@code context}'s theme.
301-
*
302-
* @param context the parent context
303-
* @param configurator the configuration for the feedback options, can be {@code null} to use
304-
* the global feedback options.
305-
*/
306-
public Builder(
307-
final @NotNull Context context,
308-
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
309-
this(context, 0, null, configurator);
298+
this(context, 0, configuration);
310299
}
311300

312301
/**
@@ -336,12 +325,33 @@ public Builder(
336325
public Builder(
337326
final @NotNull Context context,
338327
final int themeResId,
339-
final @Nullable OptionsConfiguration configuration,
340-
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
328+
final @Nullable OptionsConfiguration configuration) {
341329
this.context = context;
342330
this.themeResId = themeResId;
343331
this.configuration = configuration;
332+
}
333+
334+
/**
335+
* Sets the configuration for the feedback options.
336+
*
337+
* @param configurator the configuration for the feedback options, can be {@code null} to use
338+
* the global feedback options.
339+
*/
340+
public Builder configurator(
341+
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
344342
this.configurator = configurator;
343+
return this;
344+
}
345+
346+
/**
347+
* Sets the associated event ID for the feedback.
348+
*
349+
* @param associatedEventId the associated event ID for the feedback, can be {@code null} to
350+
* avoid associating the feedback to an event.
351+
*/
352+
public Builder associatedEventId(final @Nullable SentryId associatedEventId) {
353+
this.associatedEventId = associatedEventId;
354+
return this;
345355
}
346356

347357
/**
@@ -351,7 +361,8 @@ public Builder(
351361
* @return a new instance of {@link SentryUserFeedbackDialog}
352362
*/
353363
public SentryUserFeedbackDialog create() {
354-
return new SentryUserFeedbackDialog(context, themeResId, configuration, configurator);
364+
return new SentryUserFeedbackDialog(
365+
context, themeResId, associatedEventId, configuration, configurator);
355366
}
356367
}
357368

sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/UserFeedbackUiTest.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import io.sentry.android.core.R
2929
import io.sentry.android.core.SentryUserFeedbackButton
3030
import io.sentry.android.core.SentryUserFeedbackDialog
3131
import io.sentry.assertEnvelopeFeedback
32+
import io.sentry.protocol.SentryId
3233
import io.sentry.protocol.User
3334
import io.sentry.test.getProperty
3435
import kotlin.test.Test
@@ -477,7 +478,9 @@ class UserFeedbackUiTest : BaseUiTest() {
477478
}
478479
}
479480

480-
showDialogAndCheck {
481+
val sentryId = SentryId()
482+
483+
showDialogAndCheck(sentryId) {
481484
// Send the feedback
482485
fillFormAndSend()
483486
}
@@ -497,6 +500,7 @@ class UserFeedbackUiTest : BaseUiTest() {
497500
assertEquals("Description filled", feedback.message)
498501
// The screen name should be set in the url
499502
assertEquals("io.sentry.uitest.android.EmptyActivity", feedback.url)
503+
assertEquals(sentryId, feedback.associatedEventId)
500504

501505
if (enableReplay) {
502506
// The current replay should be set in the replayId
@@ -629,11 +633,11 @@ class UserFeedbackUiTest : BaseUiTest() {
629633
onView(withId(R.id.sentry_dialog_user_feedback_btn_send)).perform(click())
630634
}
631635

632-
private fun showDialogAndCheck(checker: (dialog: SentryUserFeedbackDialog) -> Unit = {}) {
636+
private fun showDialogAndCheck(associatedEventId: SentryId? = null, checker: (dialog: SentryUserFeedbackDialog) -> Unit = {}) {
633637
lateinit var dialog: SentryUserFeedbackDialog
634638
val feedbackScenario = launchActivity<EmptyActivity>()
635639
feedbackScenario.onActivity {
636-
dialog = SentryUserFeedbackDialog.Builder(it).create()
640+
dialog = SentryUserFeedbackDialog.Builder(it).associatedEventId(associatedEventId).create()
637641
dialog.show()
638642
}
639643

sentry-compose/api/android/sentry-compose.api

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ public final class io/sentry/compose/BuildConfig {
66
public fun <init> ()V
77
}
88

9-
public final class io/sentry/compose/ComposableSingletons$SentryUserFeedbackButtonKt {
10-
public static final field INSTANCE Lio/sentry/compose/ComposableSingletons$SentryUserFeedbackButtonKt;
11-
public static field lambda-1 Lkotlin/jvm/functions/Function3;
12-
public fun <init> ()V
13-
public final fun getLambda-1$sentry_compose_release ()Lkotlin/jvm/functions/Function3;
14-
}
15-
169
public final class io/sentry/compose/SentryComposeHelperKt {
1710
public static final fun boundsInWindow (Landroidx/compose/ui/layout/LayoutCoordinates;Landroidx/compose/ui/layout/LayoutCoordinates;)Landroidx/compose/ui/geometry/Rect;
1811
}
@@ -34,7 +27,7 @@ public final class io/sentry/compose/SentryNavigationIntegrationKt {
3427
}
3528

3629
public final class io/sentry/compose/SentryUserFeedbackButtonKt {
37-
public static final fun SentryUserFeedbackButton (Landroidx/compose/ui/Modifier;Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;Landroidx/compose/runtime/Composer;II)V
30+
public static final fun SentryUserFeedbackButton (Landroidx/compose/ui/Modifier;Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;Ljava/lang/String;Landroidx/compose/runtime/Composer;II)V
3831
}
3932

4033
public final class io/sentry/compose/gestures/ComposeGestureTargetLocator : io/sentry/internal/gestures/GestureTargetLocator {

sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryUserFeedbackButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import io.sentry.SentryFeedbackOptions
1919
public fun SentryUserFeedbackButton(
2020
modifier: Modifier = Modifier,
2121
configurator: SentryFeedbackOptions.OptionsConfigurator? = null,
22-
text: "Report a Bug",
22+
text: String = "Report a Bug",
2323
) {
2424
Button(modifier = modifier, onClick = { Sentry.showUserFeedbackDialog(configurator) }) {
2525
Row(
@@ -31,7 +31,7 @@ public fun SentryUserFeedbackButton(
3131
contentDescription = null,
3232
)
3333
Spacer(Modifier.padding(horizontal = 4.dp))
34-
Text(text = text)
34+
Text(text = text)
3535
}
3636
}
3737
}

sentry/api/sentry.api

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,7 @@ public final class io/sentry/Sentry {
25892589
public static fun setUser (Lio/sentry/protocol/User;)V
25902590
public static fun showUserFeedbackDialog ()V
25912591
public static fun showUserFeedbackDialog (Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;)V
2592+
public static fun showUserFeedbackDialog (Lio/sentry/protocol/SentryId;Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;)V
25922593
public static fun startProfiler ()V
25932594
public static fun startSession ()V
25942595
public static fun startTransaction (Lio/sentry/TransactionContext;)Lio/sentry/ITransaction;
@@ -3013,7 +3014,7 @@ public final class io/sentry/SentryFeedbackOptions {
30133014
}
30143015

30153016
public abstract interface class io/sentry/SentryFeedbackOptions$IDialogHandler {
3016-
public abstract fun showDialog (Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;)V
3017+
public abstract fun showDialog (Lio/sentry/protocol/SentryId;Lio/sentry/SentryFeedbackOptions$OptionsConfigurator;)V
30173018
}
30183019

30193020
public abstract interface class io/sentry/SentryFeedbackOptions$OptionsConfigurator {

sentry/src/main/java/io/sentry/Sentry.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,13 @@ public static void showUserFeedbackDialog() {
12961296

12971297
public static void showUserFeedbackDialog(
12981298
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
1299+
showUserFeedbackDialog(null, configurator);
1300+
}
1301+
1302+
public static void showUserFeedbackDialog(
1303+
final @Nullable SentryId associatedEventId,
1304+
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator) {
12991305
final @NotNull SentryOptions options = getCurrentScopes().getOptions();
1300-
options.getFeedbackOptions().getDialogHandler().showDialog(configurator);
1306+
options.getFeedbackOptions().getDialogHandler().showDialog(associatedEventId, configurator);
13011307
}
13021308
}

sentry/src/main/java/io/sentry/SentryFeedbackOptions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package io.sentry;
22

33
import io.sentry.protocol.Feedback;
4+
import io.sentry.protocol.SentryId;
45
import org.jetbrains.annotations.ApiStatus;
56
import org.jetbrains.annotations.NotNull;
67
import org.jetbrains.annotations.Nullable;
78

8-
@ApiStatus.Internal
99
public final class SentryFeedbackOptions {
1010
// User and Form
1111
/** Requires the name field on the feedback form to be filled in. Defaults to false. */
@@ -584,7 +584,9 @@ public interface SentryFeedbackCallback {
584584

585585
@ApiStatus.Internal
586586
public interface IDialogHandler {
587-
void showDialog(final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator);
587+
void showDialog(
588+
final @Nullable SentryId associatedEventId,
589+
final @Nullable SentryFeedbackOptions.OptionsConfigurator configurator);
588590
}
589591

590592
/** Configuration callback for feedback options. */

0 commit comments

Comments
 (0)