Skip to content

Adds feedbackIntegration for configuring the feedback form #4485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/js/feedback/FeedbackFormManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Modal, View } from 'react-native';
import { FeedbackForm } from './FeedbackForm';
import defaultStyles from './FeedbackForm.styles';
import type { FeedbackFormStyles } from './FeedbackForm.types';
import { getFeedbackOptions } from './integration';
import { isModalSupported } from './utils';

class FeedbackFormManager {
Expand Down Expand Up @@ -70,7 +71,7 @@ class FeedbackFormProvider extends React.Component<FeedbackFormProviderProps> {
<View>
<Modal visible={isVisible} transparent animationType="slide" onRequestClose={this._handleClose} testID="feedback-form-modal">
<View style={styles.modalBackground}>
<FeedbackForm
<FeedbackForm {...getFeedbackOptions()}
onFormClose={this._handleClose}
onFormSubmitted={this._handleClose}
/>
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/js/feedback/integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Integration } from '@sentry/core';

import type { FeedbackFormProps } from './FeedbackForm.types';

export const FEEDBACK_FORM_INTEGRATION_NAME = 'MobileFeedback';

type FeedbackIntegration = Integration & {
options: Partial<FeedbackFormProps>;
};

let savedOptions: Partial<FeedbackFormProps> = {};

export const feedbackIntegration = (initOptions: FeedbackFormProps = {}): FeedbackIntegration => {
savedOptions = initOptions;

return {
name: FEEDBACK_FORM_INTEGRATION_NAME,
options: savedOptions,
};
};

export const getFeedbackOptions = (): Partial<FeedbackFormProps> => savedOptions;
1 change: 1 addition & 0 deletions packages/core/src/js/integrations/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { viewHierarchyIntegration } from './viewhierarchy';
export { expoContextIntegration } from './expocontext';
export { spotlightIntegration } from './spotlight';
export { mobileReplayIntegration } from '../replay/mobilereplay';
export { feedbackIntegration } from '../feedback/integration';
export { browserReplayIntegration } from '../replay/browserReplay';
export { appStartIntegration } from '../tracing/integrations/appStart';
export { nativeFramesIntegration, createNativeFramesIntegrations } from '../tracing/integrations/nativeFrames';
Expand Down
40 changes: 40 additions & 0 deletions packages/core/test/feedback/FeedbackFormManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { render } from '@testing-library/react-native';
import * as React from 'react';
import { Text } from 'react-native';

import { defaultConfiguration } from '../../src/js/feedback/defaults';
import { FeedbackFormProvider, showFeedbackForm } from '../../src/js/feedback/FeedbackFormManager';
import { feedbackIntegration } from '../../src/js/feedback/integration';
import { isModalSupported } from '../../src/js/feedback/utils';

jest.mock('../../src/js/feedback/utils', () => ({
Expand Down Expand Up @@ -53,4 +55,42 @@ describe('FeedbackFormManager', () => {
showFeedbackForm();
}).not.toThrow();
});

it('showFeedbackForm displays the form with the feedbackIntegration options', () => {
mockedIsModalSupported.mockReturnValue(true);
const { getByPlaceholderText, getByText } = render(
<FeedbackFormProvider>
<Text>App Components</Text>
</FeedbackFormProvider>
);

feedbackIntegration({
messagePlaceholder: 'Custom Message Placeholder',
submitButtonLabel: 'Custom Submit Button',
});

showFeedbackForm();

expect(getByPlaceholderText('Custom Message Placeholder')).toBeTruthy();
expect(getByText('Custom Submit Button')).toBeTruthy();
});

it('showFeedbackForm displays the form with the feedbackIntegration options merged with the defaults', () => {
mockedIsModalSupported.mockReturnValue(true);
const { getByPlaceholderText, getByText, queryByText } = render(
<FeedbackFormProvider>
<Text>App Components</Text>
</FeedbackFormProvider>
);

feedbackIntegration({
submitButtonLabel: 'Custom Submit Button',
}),

showFeedbackForm();

expect(queryByText(defaultConfiguration.submitButtonLabel)).toBeFalsy(); // overridden value
expect(getByText('Custom Submit Button')).toBeTruthy(); // overridden value
expect(getByPlaceholderText(defaultConfiguration.messagePlaceholder)).toBeTruthy(); // default configuration value
});
});
12 changes: 12 additions & 0 deletions samples/react-native/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ Sentry.init({
? false
: true,
}),
Sentry.feedbackIntegration({
styles:{
submitButton: {
backgroundColor: '#6a1b9a',
paddingVertical: 15,
borderRadius: 5,
alignItems: 'center',
marginBottom: 10,
},
},
namePlaceholder: 'Fullname',
}),
);
return integrations.filter(i => i.name !== 'Dedupe');
},
Expand Down
Loading