Skip to content

Commit 0e54497

Browse files
committed
Merge branch 'antonis/3859-newCaptureFeedbackAPI' into antonis/3859-newCaptureFeedbackAPI-hint
# Conflicts: # CHANGELOG.md # packages/core/src/js/client.ts # packages/core/src/js/sdk.tsx # packages/core/test/client.test.ts
2 parents fa41526 + f9d2b59 commit 0e54497

File tree

6 files changed

+492
-116
lines changed

6 files changed

+492
-116
lines changed

CHANGELOG.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,25 @@
1212

1313
- Adds new `captureFeedback` and deprecates the `captureUserFeedback` API ([#4320](https://github.com/getsentry/sentry-react-native/pull/4320), [#4322](https://github.com/getsentry/sentry-react-native/pull/4322))
1414

15+
1516
```jsx
16-
import * as Sentry from '@sentry/react-native';
17-
import { SendFeedbackParams } from '@sentry/react-native';
17+
import * as Sentry from "@sentry/react-native";
1818

19-
const eventId = Sentry.captureMessage('My Message');
20-
// OR: const eventId = Sentry.lastEventId();
19+
const eventId = Sentry.lastEventId();
2120

22-
const userFeedback: SendFeedbackParams = {
23-
name: 'John Doe',
24-
25-
message: 'Hello World!',
26-
associatedEventId: eventId,// Optional
27-
};
28-
Sentry.captureFeedback(userFeedback, {
21+
Sentry.captureFeedback({
22+
name: "John Doe",
23+
24+
message: "Hello World!",
25+
associatedEventId: eventId, // optional
26+
}, {
2927
captureContext: {
30-
tags: { 'tag-key': 'tag-value' },
28+
tags: { "tag-key": "tag-value" },
3129
},
3230
attachments: [
3331
{
34-
filename: 'screenshot.png',
35-
data: 'base64-encoded-image',
32+
filename: "screenshot.png",
33+
data: "base64-encoded-image",
3634
},
3735
],
3836
});

packages/core/src/js/client.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureFeedback as captureFeedbackApi, eventFromException, eventFromMessage } from '@sentry/browser';
1+
import { eventFromException, eventFromMessage } from '@sentry/browser';
22
import { BaseClient } from '@sentry/core';
33
import type {
44
ClientReportEnvelope,
@@ -7,7 +7,6 @@ import type {
77
Event,
88
EventHint,
99
Outcome,
10-
SendFeedbackParams,
1110
SeverityLevel,
1211
TransportMakeRequestResponse,
1312
} from '@sentry/types';
@@ -83,13 +82,6 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
8382
});
8483
}
8584

86-
/**
87-
* Sends user feedback to Sentry.
88-
*/
89-
public captureFeedback(feedback: SendFeedbackParams, hint?: EventHint): void {
90-
captureFeedbackApi(feedback, hint);
91-
}
92-
9385
/**
9486
* @inheritdoc
9587
*/

packages/core/src/js/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
addBreadcrumb,
1818
captureException,
1919
captureEvent,
20+
captureFeedback,
2021
captureMessage,
2122
Scope,
2223
setContext,
@@ -60,17 +61,7 @@ export { SDK_NAME, SDK_VERSION } from './version';
6061
export type { ReactNativeOptions } from './options';
6162
export { ReactNativeClient } from './client';
6263

63-
export {
64-
init,
65-
wrap,
66-
nativeCrash,
67-
flush,
68-
close,
69-
captureFeedback,
70-
captureUserFeedback,
71-
withScope,
72-
crashedLastRun,
73-
} from './sdk';
64+
export { init, wrap, nativeCrash, flush, close, captureUserFeedback, withScope, crashedLastRun } from './sdk';
7465
export { TouchEventBoundary, withTouchEventBoundary } from './touchevents';
7566

7667
export {

packages/core/src/js/sdk.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable complexity */
2-
import { getClient, getGlobalScope,getIntegrationsToSetup, getIsolationScope,initAndBind, withScope as coreWithScope } from '@sentry/core';
2+
import { captureFeedback, getClient, getGlobalScope,getIntegrationsToSetup, getIsolationScope,initAndBind, withScope as coreWithScope } from '@sentry/core';
33
import {
44
defaultStackParser,
55
makeFetchTransport,
@@ -222,7 +222,7 @@ export async function close(): Promise<void> {
222222
* @deprecated Use `Sentry.captureFeedback` instead.
223223
*/
224224
export function captureUserFeedback(feedback: UserFeedback): void {
225-
const feedbackParams = {
225+
const feedbackParams: SendFeedbackParams = {
226226
name: feedback.name,
227227
email: feedback.email,
228228
message: feedback.comments,
@@ -231,13 +231,6 @@ export function captureUserFeedback(feedback: UserFeedback): void {
231231
captureFeedback(feedbackParams);
232232
}
233233

234-
/**
235-
* Captures user feedback and sends it to Sentry.
236-
*/
237-
export function captureFeedback(feedbackParams: SendFeedbackParams, hint?: EventHint): void {
238-
getClient<ReactNativeClient>()?.captureFeedback(feedbackParams, hint);
239-
}
240-
241234
/**
242235
* Creates a new scope with and executes the given operation within.
243236
* The scope is automatically removed once the operation

packages/core/test/client.test.ts

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import * as mockedtimetodisplaynative from './tracing/mockedtimetodisplaynative';
22
jest.mock('../src/js/tracing/timetodisplaynative', () => mockedtimetodisplaynative);
33

4-
import { captureFeedback as captureFeedbackApi, defaultStackParser } from '@sentry/browser';
5-
import type {
6-
Envelope,
7-
Event,
8-
Outcome,
9-
SendFeedbackParams,
10-
Transport,
11-
TransportMakeRequestResponse,
12-
} from '@sentry/types';
4+
import { defaultStackParser } from '@sentry/browser';
5+
import type { Envelope, Event, Outcome, Transport, TransportMakeRequestResponse } from '@sentry/types';
136
import { rejectedSyncPromise, SentryError } from '@sentry/utils';
147
import * as RN from 'react-native';
158

@@ -82,14 +75,6 @@ jest.mock(
8275
}),
8376
);
8477

85-
jest.mock('@sentry/browser', () => {
86-
const actual = jest.requireActual('@sentry/browser');
87-
return {
88-
...actual,
89-
captureFeedback: jest.fn(),
90-
};
91-
});
92-
9378
const EXAMPLE_DSN = 'https://[email protected]/148053';
9479

9580
const DEFAULT_OPTIONS: ReactNativeClientOptions = {
@@ -294,62 +279,6 @@ describe('Tests ReactNativeClient', () => {
294279
});
295280
});
296281

297-
describe('UserFeedback', () => {
298-
test('sends UserFeedback', () => {
299-
const client = new ReactNativeClient({
300-
...DEFAULT_OPTIONS,
301-
dsn: EXAMPLE_DSN,
302-
});
303-
jest.mock('@sentry/browser', () => ({
304-
captureFeedback: jest.fn(),
305-
}));
306-
307-
const feedback: SendFeedbackParams = {
308-
message: 'Test Comments',
309-
310-
name: 'Test User',
311-
associatedEventId: 'testEvent123',
312-
};
313-
314-
client.captureFeedback(feedback);
315-
316-
expect(captureFeedbackApi).toHaveBeenCalledWith(feedback, undefined);
317-
});
318-
319-
test('sends UserFeedback with hint', () => {
320-
const client = new ReactNativeClient({
321-
...DEFAULT_OPTIONS,
322-
dsn: EXAMPLE_DSN,
323-
});
324-
jest.mock('@sentry/browser', () => ({
325-
captureFeedback: jest.fn(),
326-
}));
327-
328-
const feedback: SendFeedbackParams = {
329-
message: 'Test Comments',
330-
331-
name: 'Test User',
332-
associatedEventId: 'testEvent123',
333-
};
334-
335-
const hint = {
336-
captureContext: {
337-
tags: { testtag: 'testvalue' },
338-
},
339-
attachments: [
340-
{
341-
filename: 'screenshot.png',
342-
data: 'base64Image',
343-
},
344-
],
345-
};
346-
347-
client.captureFeedback(feedback, hint);
348-
349-
expect(captureFeedbackApi).toHaveBeenCalledWith(feedback, hint);
350-
});
351-
});
352-
353282
describe('attachStacktrace', () => {
354283
let mockTransportSend: jest.Mock;
355284
let client: ReactNativeClient;

0 commit comments

Comments
 (0)