Skip to content

Commit

Permalink
Merge branch 'antonis/3859-newCaptureFeedbackAPI-Form' into antonis/3…
Browse files Browse the repository at this point in the history
…959-captureFeedback-attachements

# Conflicts:
#	packages/core/test/feedback/FeedbackForm.test.tsx
  • Loading branch information
antonis committed Dec 17, 2024
2 parents 03215dd + 0588552 commit 85e3484
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 134 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@aa578102511db1f4524ed59b8cc2bae4f6e88195 # [email protected].6
uses: github/codeql-action/init@df409f7d9260372bd5f19e5b04e83cb3c43714ae # [email protected].9
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -55,7 +55,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@aa578102511db1f4524ed59b8cc2bae4f6e88195 # [email protected].6
uses: github/codeql-action/autobuild@df409f7d9260372bd5f19e5b04e83cb3c43714ae # [email protected].9

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
Expand All @@ -66,4 +66,4 @@ jobs:
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@aa578102511db1f4524ed59b8cc2bae4f6e88195 # [email protected].6
uses: github/codeql-action/analyze@df409f7d9260372bd5f19e5b04e83cb3c43714ae # [email protected].9
23 changes: 8 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,14 @@
email: "[email protected]",
message: "Hello World!",
associatedEventId: eventId, // optional
}, {
captureContext: {
tags: { "tag-key": "tag-value" },
},
attachments: [
{
filename: 'hello.txt',
data: 'Hello, World!',
},
],
});
```

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

- User Feedback Form Component Beta ([#4320](https://github.com/getsentry/sentry-react-native/pull/4328))

To collect user feedback from inside your application add the `FeedbackFrom` component.
To collect user feedback from inside your application add the `FeedbackForm` component.

```jsx
import { FeedbackForm } from "@sentry/react-native";
Expand All @@ -46,6 +38,7 @@
```

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

### Fixes

Expand All @@ -66,9 +59,9 @@
- 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))
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#7190)
- [diff](https://github.com/getsentry/sentry-java/compare/7.18.0...7.19.0)
- Bump JavaScript SDK from v8.40.0 to v8.44.0 ([#4351](https://github.com/getsentry/sentry-react-native/pull/4351), [#4325](https://github.com/getsentry/sentry-react-native/pull/4325))
- [changelog](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#8440)
- [diff](https://github.com/getsentry/sentry-javascript/compare/8.40.0...8.44.0)
- 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))
- [changelog](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#8451)
- [diff](https://github.com/getsentry/sentry-javascript/compare/8.40.0...8.45.1)

## 6.4.0

Expand Down
2 changes: 1 addition & 1 deletion dev-packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@babel/preset-env": "^7.25.3",
"@babel/preset-typescript": "^7.18.6",
"@sentry/core": "8.44.0",
"@sentry/core": "8.45.1",
"@sentry/react-native": "6.4.0",
"@types/node": "^20.9.3",
"@types/react": "^18.2.64",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public class RNSentryModuleImpl {

public static final String NAME = "RNSentry";

private static final String NATIVE_SDK_NAME = "sentry.native.android.react-native";
private static final String ANDROID_SDK_NAME = "sentry.java.android.react-native";
private static final ILogger logger = new AndroidLogger(NAME);
private static final BuildInfoProvider buildInfo = new BuildInfoProvider(logger);
private static final String modulesPath = "modules.json";
Expand Down Expand Up @@ -191,13 +189,16 @@ protected void getSentryAndroidOptions(
@NotNull SentryAndroidOptions options, @NotNull ReadableMap rnOptions, ILogger logger) {
@Nullable SdkVersion sdkVersion = options.getSdkVersion();
if (sdkVersion == null) {
sdkVersion = new SdkVersion(ANDROID_SDK_NAME, BuildConfig.VERSION_NAME);
sdkVersion = new SdkVersion(RNSentryVersion.ANDROID_SDK_NAME, BuildConfig.VERSION_NAME);
} else {
sdkVersion.setName(ANDROID_SDK_NAME);
sdkVersion.setName(RNSentryVersion.ANDROID_SDK_NAME);
}
sdkVersion.addPackage(
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_NAME,
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_VERSION);

options.setSentryClientName(sdkVersion.getName() + "/" + sdkVersion.getVersion());
options.setNativeSdkName(NATIVE_SDK_NAME);
options.setNativeSdkName(RNSentryVersion.NATIVE_SDK_NAME);
options.setSdkVersion(sdkVersion);

if (rnOptions.hasKey("debug") && rnOptions.getBoolean("debug")) {
Expand Down Expand Up @@ -970,10 +971,10 @@ private void setEventOriginTag(SentryEvent event) {
SdkVersion sdk = event.getSdk();
if (sdk != null) {
switch (sdk.getName()) {
case NATIVE_SDK_NAME:
case RNSentryVersion.NATIVE_SDK_NAME:
setEventEnvironmentTag(event, "native");
break;
case ANDROID_SDK_NAME:
case RNSentryVersion.ANDROID_SDK_NAME:
setEventEnvironmentTag(event, "java");
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.sentry.react;

class RNSentryVersion {
static final String REACT_NATIVE_SDK_PACKAGE_NAME = "npm:@sentry/react-native";
static final String REACT_NATIVE_SDK_PACKAGE_VERSION = "6.4.0";
static final String NATIVE_SDK_NAME = "sentry.native.android.react-native";
static final String ANDROID_SDK_NAME = "sentry.java.android.react-native";
}
16 changes: 8 additions & 8 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@
},
"dependencies": {
"@sentry/babel-plugin-component-annotate": "2.20.1",
"@sentry/browser": "8.44.0",
"@sentry/browser": "8.45.1",
"@sentry/cli": "2.39.1",
"@sentry/core": "8.44.0",
"@sentry/react": "8.44.0",
"@sentry/types": "8.44.0",
"@sentry/utils": "8.44.0"
"@sentry/core": "8.45.1",
"@sentry/react": "8.45.1",
"@sentry/types": "8.45.1",
"@sentry/utils": "8.45.1"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@expo/metro-config": "0.19.5",
"@mswjs/interceptors": "^0.25.15",
"@react-native/babel-preset": "0.76.3",
"@sentry-internal/eslint-config-sdk": "8.44.0",
"@sentry-internal/eslint-plugin-sdk": "8.44.0",
"@sentry-internal/typescript": "8.44.0",
"@sentry-internal/eslint-config-sdk": "8.45.1",
"@sentry-internal/eslint-plugin-sdk": "8.45.1",
"@sentry-internal/typescript": "8.45.1",
"@sentry/wizard": "3.36.0",
"@testing-library/react-native": "^12.7.2",
"@types/jest": "^29.5.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/feedback/FeedbackForm.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FeedbackFormStyles } from './FeedbackForm.types';

const PURPLE = 'rgba(88, 74, 192, 1)';
const FORGROUND_COLOR = '#2b2233';
const BACKROUND_COLOR = '#fff';
const BACKROUND_COLOR = '#ffffff';
const BORDER_COLOR = 'rgba(41, 35, 47, 0.13)';

const defaultStyles: FeedbackFormStyles = {
Expand Down
29 changes: 15 additions & 14 deletions packages/core/src/js/feedback/FeedbackForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SendFeedbackParams } from '@sentry/core';
import { captureFeedback, getCurrentScope, lastEventId } from '@sentry/core';
import type { SendFeedbackParams } from '@sentry/types';
import * as React from 'react';
import type { KeyboardTypeOptions } from 'react-native';
import {
Expand All @@ -25,42 +25,43 @@ import type { FeedbackFormProps, FeedbackFormState, FeedbackFormStyles,FeedbackG
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
*/
export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFormState> {
private _config: FeedbackFormProps;
public static defaultProps: Partial<FeedbackFormProps> = {
...defaultConfiguration
}

public constructor(props: FeedbackFormProps) {
super(props);

const currentUser = {
useSentryUser: {
email: getCurrentScope().getUser().email || '',
name: getCurrentScope().getUser().name || '',
email: this.props?.useSentryUser?.email || getCurrentScope()?.getUser()?.email || '',
name: this.props?.useSentryUser?.name || getCurrentScope()?.getUser()?.name || '',
}
}

this._config = { ...defaultConfiguration, ...currentUser, ...props };
this.state = {
isVisible: true,
name: this._config.useSentryUser.name,
email: this._config.useSentryUser.email,
name: currentUser.useSentryUser.name,
email: currentUser.useSentryUser.email,
description: '',
};
}

public handleFeedbackSubmit: () => void = () => {
const { name, email, description } = this.state;
const { onFormClose } = this._config;
const text: FeedbackTextConfiguration = this._config;
const { onFormClose } = this.props;
const text: FeedbackTextConfiguration = this.props;

const trimmedName = name?.trim();
const trimmedEmail = email?.trim();
const trimmedDescription = description?.trim();

if ((this._config.isNameRequired && !trimmedName) || (this._config.isEmailRequired && !trimmedEmail) || !trimmedDescription) {
if ((this.props.isNameRequired && !trimmedName) || (this.props.isEmailRequired && !trimmedEmail) || !trimmedDescription) {
Alert.alert(text.errorTitle, text.formError);
return;
}

if (this._config.shouldValidateEmail && (this._config.isEmailRequired || trimmedEmail.length > 0) && !this._isValidEmail(trimmedEmail)) {
if (this.props.shouldValidateEmail && (this.props.isEmailRequired || trimmedEmail.length > 0) && !this._isValidEmail(trimmedEmail)) {
Alert.alert(text.errorTitle, text.emailError);
return;
}
Expand Down Expand Up @@ -107,9 +108,9 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
*/
public render(): React.ReactNode {
const { name, email, description } = this.state;
const { onFormClose } = this._config;
const config: FeedbackGeneralConfiguration = this._config;
const text: FeedbackTextConfiguration = this._config;
const { onFormClose } = this.props;
const config: FeedbackGeneralConfiguration = this.props;
const text: FeedbackTextConfiguration = this.props;
const styles: FeedbackFormStyles = { ...defaultStyles, ...this.props.styles };
const onCancel = (): void => {
onFormClose();
Expand Down
20 changes: 16 additions & 4 deletions packages/core/test/feedback/FeedbackForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import type { FeedbackFormProps } from '../../src/js/feedback/FeedbackForm.types

const mockOnFormClose = jest.fn();
const mockOnFileChosen = jest.fn();
const mockGetUser = jest.fn(() => ({
email: '[email protected]',
name: 'Test User',
}));

jest.spyOn(Alert, 'alert');

jest.mock('@sentry/core', () => ({
captureFeedback: jest.fn(),
getCurrentScope: jest.fn(() => ({
getUser: jest.fn(() => ({
email: '[email protected]',
name: 'Test User',
})),
getUser: mockGetUser,
})),
lastEventId: jest.fn(),
}));
Expand Down Expand Up @@ -78,6 +79,17 @@ describe('FeedbackForm', () => {
expect(emailInput.props.value).toBe('[email protected]');
});

it('ensure getUser is called only after the component is rendered', () => {
// Ensure getUser is not called before render
expect(mockGetUser).not.toHaveBeenCalled();

// Render the component
render(<FeedbackForm />);

// After rendering, check that getUser was called twice (email and name)
expect(mockGetUser).toHaveBeenCalledTimes(2);
});

it('shows an error message if required fields are empty', async () => {
const { getByText } = render(<FeedbackForm {...defaultProps} />);

Expand Down
6 changes: 3 additions & 3 deletions samples/react-native-macos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"@react-navigation/bottom-tabs": "^6.5.12",
"@react-navigation/native": "^6.1.9",
"@react-navigation/stack": "^6.3.20",
"@sentry/core": "8.44.0",
"@sentry/react": "8.44.0",
"@sentry/core": "8.45.1",
"@sentry/react": "8.45.1",
"@sentry/react-native": "6.4.0",
"@sentry/types": "8.44.0",
"@sentry/types": "8.45.1",
"delay": "^6.0.0",
"react": "18.2.0",
"react-native": "0.73.9",
Expand Down
5 changes: 4 additions & 1 deletion scripts/version-bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const replace = require('replace-in-file');
const pjson = require('../packages/core/package.json');

replace({
files: ['packages/core/src/js/version.ts'],
files: [
'packages/core/src/js/version.ts',
'packages/core/android/src/main/java/io/sentry/react/RNSentryVersion.java',
],
from: /\d+\.\d+.\d+(?:-\w+(?:\.\w+)?)?/g,
to: pjson.version,
})
Expand Down
Loading

0 comments on commit 85e3484

Please sign in to comment.