Skip to content

Commit 89c66d3

Browse files
committed
Merge branch 'antonis/3859-newCaptureFeedbackAPI-Form' into antonis/4358-Feedback-Form-Autoinject
# Conflicts: # packages/core/src/js/feedback/FeedbackForm.tsx
2 parents 4408071 + 0588552 commit 89c66d3

File tree

11 files changed

+147
-129
lines changed

11 files changed

+147
-129
lines changed

CHANGELOG.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,11 @@
2222
email: "john@doe.com",
2323
message: "Hello World!",
2424
associatedEventId: eventId, // optional
25-
}, {
26-
captureContext: {
27-
tags: { "tag-key": "tag-value" },
28-
},
29-
attachments: [
30-
{
31-
filename: 'hello.txt',
32-
data: 'Hello, World!',
33-
},
34-
],
3525
});
3626
```
3727

28+
To learn how to attach context data to the feedback visit [the documentation](https://docs.sentry.io/platforms/react-native/user-feedback/).
29+
3830
- User Feedback Form Component Beta ([#4320](https://github.com/getsentry/sentry-react-native/pull/4328))
3931

4032
To collect user feedback from inside your application add the `FeedbackForm` component.
@@ -57,6 +49,7 @@
5749
```
5850

5951
- Export `Span` type from `@sentry/types` ([#4345](https://github.com/getsentry/sentry-react-native/pull/4345))
52+
- Add RN SDK package to `sdk.packages` on Android ([#4380](https://github.com/getsentry/sentry-react-native/pull/4380))
6053

6154
### Fixes
6255

@@ -77,9 +70,9 @@
7770
- Bump Android SDK from v7.18.0 to v7.19.0 ([#4329](https://github.com/getsentry/sentry-react-native/pull/4329), [#4365](https://github.com/getsentry/sentry-react-native/pull/4365))
7871
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#7190)
7972
- [diff](https://github.com/getsentry/sentry-java/compare/7.18.0...7.19.0)
80-
- Bump JavaScript SDK from v8.40.0 to v8.45.0 ([#4351](https://github.com/getsentry/sentry-react-native/pull/4351), [#4325](https://github.com/getsentry/sentry-react-native/pull/4325), [#4371](https://github.com/getsentry/sentry-react-native/pull/4371))
81-
- [changelog](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#8450)
82-
- [diff](https://github.com/getsentry/sentry-javascript/compare/8.40.0...8.45.0)
73+
- Bump JavaScript SDK from v8.40.0 to v8.45.1 ([#4351](https://github.com/getsentry/sentry-react-native/pull/4351), [#4325](https://github.com/getsentry/sentry-react-native/pull/4325), [#4371](https://github.com/getsentry/sentry-react-native/pull/4371), [#4382](https://github.com/getsentry/sentry-react-native/pull/4382))
74+
- [changelog](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#8451)
75+
- [diff](https://github.com/getsentry/sentry-javascript/compare/8.40.0...8.45.1)
8376

8477
## 6.4.0
8578

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"devDependencies": {
1414
"@babel/preset-env": "^7.25.3",
1515
"@babel/preset-typescript": "^7.18.6",
16-
"@sentry/core": "8.45.0",
16+
"@sentry/core": "8.45.1",
1717
"@sentry/react-native": "6.4.0",
1818
"@types/node": "^20.9.3",
1919
"@types/react": "^18.2.64",

packages/core/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ public class RNSentryModuleImpl {
9393

9494
public static final String NAME = "RNSentry";
9595

96-
private static final String NATIVE_SDK_NAME = "sentry.native.android.react-native";
97-
private static final String ANDROID_SDK_NAME = "sentry.java.android.react-native";
9896
private static final ILogger logger = new AndroidLogger(NAME);
9997
private static final BuildInfoProvider buildInfo = new BuildInfoProvider(logger);
10098
private static final String modulesPath = "modules.json";
@@ -191,13 +189,16 @@ protected void getSentryAndroidOptions(
191189
@NotNull SentryAndroidOptions options, @NotNull ReadableMap rnOptions, ILogger logger) {
192190
@Nullable SdkVersion sdkVersion = options.getSdkVersion();
193191
if (sdkVersion == null) {
194-
sdkVersion = new SdkVersion(ANDROID_SDK_NAME, BuildConfig.VERSION_NAME);
192+
sdkVersion = new SdkVersion(RNSentryVersion.ANDROID_SDK_NAME, BuildConfig.VERSION_NAME);
195193
} else {
196-
sdkVersion.setName(ANDROID_SDK_NAME);
194+
sdkVersion.setName(RNSentryVersion.ANDROID_SDK_NAME);
197195
}
196+
sdkVersion.addPackage(
197+
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_NAME,
198+
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_VERSION);
198199

199200
options.setSentryClientName(sdkVersion.getName() + "/" + sdkVersion.getVersion());
200-
options.setNativeSdkName(NATIVE_SDK_NAME);
201+
options.setNativeSdkName(RNSentryVersion.NATIVE_SDK_NAME);
201202
options.setSdkVersion(sdkVersion);
202203

203204
if (rnOptions.hasKey("debug") && rnOptions.getBoolean("debug")) {
@@ -970,10 +971,10 @@ private void setEventOriginTag(SentryEvent event) {
970971
SdkVersion sdk = event.getSdk();
971972
if (sdk != null) {
972973
switch (sdk.getName()) {
973-
case NATIVE_SDK_NAME:
974+
case RNSentryVersion.NATIVE_SDK_NAME:
974975
setEventEnvironmentTag(event, "native");
975976
break;
976-
case ANDROID_SDK_NAME:
977+
case RNSentryVersion.ANDROID_SDK_NAME:
977978
setEventEnvironmentTag(event, "java");
978979
break;
979980
default:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.sentry.react;
2+
3+
class RNSentryVersion {
4+
static final String REACT_NATIVE_SDK_PACKAGE_NAME = "npm:@sentry/react-native";
5+
static final String REACT_NATIVE_SDK_PACKAGE_VERSION = "6.4.0";
6+
static final String NATIVE_SDK_NAME = "sentry.native.android.react-native";
7+
static final String ANDROID_SDK_NAME = "sentry.java.android.react-native";
8+
}

packages/core/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@
6666
},
6767
"dependencies": {
6868
"@sentry/babel-plugin-component-annotate": "2.20.1",
69-
"@sentry/browser": "8.45.0",
69+
"@sentry/browser": "8.45.1",
7070
"@sentry/cli": "2.39.1",
71-
"@sentry/core": "8.45.0",
72-
"@sentry/react": "8.45.0",
73-
"@sentry/types": "8.45.0",
74-
"@sentry/utils": "8.45.0"
71+
"@sentry/core": "8.45.1",
72+
"@sentry/react": "8.45.1",
73+
"@sentry/types": "8.45.1",
74+
"@sentry/utils": "8.45.1"
7575
},
7676
"devDependencies": {
7777
"@babel/core": "^7.25.2",
7878
"@expo/metro-config": "0.19.5",
7979
"@mswjs/interceptors": "^0.25.15",
8080
"@react-native/babel-preset": "0.76.3",
81-
"@sentry-internal/eslint-config-sdk": "8.45.0",
82-
"@sentry-internal/eslint-plugin-sdk": "8.45.0",
83-
"@sentry-internal/typescript": "8.45.0",
81+
"@sentry-internal/eslint-config-sdk": "8.45.1",
82+
"@sentry-internal/eslint-plugin-sdk": "8.45.1",
83+
"@sentry-internal/typescript": "8.45.1",
8484
"@sentry/wizard": "3.36.0",
8585
"@testing-library/react-native": "^12.7.2",
8686
"@types/jest": "^29.5.3",

packages/core/src/js/feedback/FeedbackForm.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { FeedbackFormStyles } from './FeedbackForm.types';
22

33
const PURPLE = 'rgba(88, 74, 192, 1)';
44
const FORGROUND_COLOR = '#2b2233';
5-
const BACKROUND_COLOR = '#fff';
5+
const BACKROUND_COLOR = '#ffffff';
66
const BORDER_COLOR = 'rgba(41, 35, 47, 0.13)';
77

88
const defaultStyles: FeedbackFormStyles = {

packages/core/src/js/feedback/FeedbackForm.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import type { SendFeedbackParams } from '@sentry/core';
12
import { captureFeedback, getCurrentScope, lastEventId, logger } from '@sentry/core';
2-
import type { SendFeedbackParams } from '@sentry/types';
33
import * as React from 'react';
44
import type { KeyboardTypeOptions } from 'react-native';
55
import {
@@ -49,23 +49,24 @@ export const showFeedbackForm = (navigation: Navigation): void => {
4949
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
5050
*/
5151
export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFormState> {
52-
private _config: FeedbackFormProps;
52+
public static defaultProps: Partial<FeedbackFormProps> = {
53+
...defaultConfiguration
54+
}
5355

5456
public constructor(props: FeedbackFormProps) {
5557
super(props);
5658

5759
const currentUser = {
5860
useSentryUser: {
59-
email: getCurrentScope().getUser().email || '',
60-
name: getCurrentScope().getUser().name || '',
61+
email: this.props?.useSentryUser?.email || getCurrentScope()?.getUser()?.email || '',
62+
name: this.props?.useSentryUser?.name || getCurrentScope()?.getUser()?.name || '',
6163
}
6264
}
6365

64-
this._config = { ...defaultConfiguration, ...currentUser, ...props };
6566
this.state = {
6667
isVisible: true,
67-
name: this._config.useSentryUser.name,
68-
email: this._config.useSentryUser.email,
68+
name: currentUser.useSentryUser.name,
69+
email: currentUser.useSentryUser.email,
6970
description: '',
7071
};
7172
}
@@ -79,19 +80,19 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
7980

8081
public handleFeedbackSubmit: () => void = () => {
8182
const { name, email, description } = this.state;
82-
const { onFormClose } = this._config;
83-
const text: FeedbackTextConfiguration = this._config;
83+
const { onFormClose } = this.props;
84+
const text: FeedbackTextConfiguration = this.props;
8485

8586
const trimmedName = name?.trim();
8687
const trimmedEmail = email?.trim();
8788
const trimmedDescription = description?.trim();
8889

89-
if ((this._config.isNameRequired && !trimmedName) || (this._config.isEmailRequired && !trimmedEmail) || !trimmedDescription) {
90+
if ((this.props.isNameRequired && !trimmedName) || (this.props.isEmailRequired && !trimmedEmail) || !trimmedDescription) {
9091
Alert.alert(text.errorTitle, text.formError);
9192
return;
9293
}
9394

94-
if (this._config.shouldValidateEmail && (this._config.isEmailRequired || trimmedEmail.length > 0) && !this._isValidEmail(trimmedEmail)) {
95+
if (this.props.shouldValidateEmail && (this.props.isEmailRequired || trimmedEmail.length > 0) && !this._isValidEmail(trimmedEmail)) {
9596
Alert.alert(text.errorTitle, text.emailError);
9697
return;
9798
}
@@ -116,9 +117,9 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
116117
*/
117118
public render(): React.ReactNode {
118119
const { name, email, description } = this.state;
119-
const { onFormClose } = this._config;
120-
const config: FeedbackGeneralConfiguration = this._config;
121-
const text: FeedbackTextConfiguration = this._config;
120+
const { onFormClose } = this.props;
121+
const config: FeedbackGeneralConfiguration = this.props;
122+
const text: FeedbackTextConfiguration = this.props;
122123
const styles: FeedbackFormStyles = { ...defaultStyles, ...this.props.styles };
123124
const onCancel = (): void => {
124125
onFormClose();

packages/core/test/feedback/FeedbackForm.test.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ import { FeedbackForm } from '../../src/js/feedback/FeedbackForm';
77
import type { FeedbackFormProps } from '../../src/js/feedback/FeedbackForm.types';
88

99
const mockOnFormClose = jest.fn();
10+
const mockGetUser = jest.fn(() => ({
11+
email: 'test@example.com',
12+
name: 'Test User',
13+
}));
1014

1115
jest.spyOn(Alert, 'alert');
1216

1317
jest.mock('@sentry/core', () => ({
1418
captureFeedback: jest.fn(),
1519
getCurrentScope: jest.fn(() => ({
16-
getUser: jest.fn(() => ({
17-
email: 'test@example.com',
18-
name: 'Test User',
19-
})),
20+
getUser: mockGetUser,
2021
})),
2122
lastEventId: jest.fn(),
2223
}));
@@ -68,6 +69,17 @@ describe('FeedbackForm', () => {
6869
expect(emailInput.props.value).toBe('test@example.com');
6970
});
7071

72+
it('ensure getUser is called only after the component is rendered', () => {
73+
// Ensure getUser is not called before render
74+
expect(mockGetUser).not.toHaveBeenCalled();
75+
76+
// Render the component
77+
render(<FeedbackForm />);
78+
79+
// After rendering, check that getUser was called twice (email and name)
80+
expect(mockGetUser).toHaveBeenCalledTimes(2);
81+
});
82+
7183
it('shows an error message if required fields are empty', async () => {
7284
const { getByText } = render(<FeedbackForm {...defaultProps} />);
7385

samples/react-native-macos/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"@react-navigation/bottom-tabs": "^6.5.12",
1717
"@react-navigation/native": "^6.1.9",
1818
"@react-navigation/stack": "^6.3.20",
19-
"@sentry/core": "8.45.0",
20-
"@sentry/react": "8.45.0",
19+
"@sentry/core": "8.45.1",
20+
"@sentry/react": "8.45.1",
2121
"@sentry/react-native": "6.4.0",
22-
"@sentry/types": "8.45.0",
22+
"@sentry/types": "8.45.1",
2323
"delay": "^6.0.0",
2424
"react": "18.2.0",
2525
"react-native": "0.73.9",

scripts/version-bump.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const replace = require('replace-in-file');
44
const pjson = require('../packages/core/package.json');
55

66
replace({
7-
files: ['packages/core/src/js/version.ts'],
7+
files: [
8+
'packages/core/src/js/version.ts',
9+
'packages/core/android/src/main/java/io/sentry/react/RNSentryVersion.java',
10+
],
811
from: /\d+\.\d+.\d+(?:-\w+(?:\.\w+)?)?/g,
912
to: pjson.version,
1013
})

0 commit comments

Comments
 (0)