-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
638377d
Auto-inject feedback form
antonis db407ce
Temporarily disable sample rotating indicator
antonis 7837b96
Merge branch 'feedback-ui' into antonis/feedback-autoinject
antonis e9f428d
Revert "Temporarily disable sample rotating indicator"
antonis 011fea7
Wrap Modal in a View
antonis a4962b9
Handles Android back button
antonis 2d4abb3
Make modal style configurable
antonis 84108f1
Print an error when the modal is not supported
antonis 587c3fc
Add changelog
antonis f4df57c
Adds tests
antonis 0d466d2
Get major, minor version with deconstruct declaration
antonis caa075b
Remove if condition
antonis 8071e8d
Prettier
antonis caa1237
Adds feedbackIntegration for configuring the feedback form
antonis a5a3fb4
Adds test
antonis d8ab914
Fix test import
antonis 016f77a
Update integration name to match existing convention
antonis b394960
Merge branch 'antonis/feedback-autoinject' into antonis/feedback-inte…
antonis 6f26740
Merge branch 'feedback-ui' into antonis/feedback-integration
antonis cbb1fd1
Simplify the integration by directly saving the passed options
antonis 8b81355
Fixes broken test
antonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { logger } from '@sentry/core'; | ||
| import * as React from 'react'; | ||
| 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 { | ||
| private static _isVisible = false; | ||
| private static _setVisibility: (visible: boolean) => void; | ||
|
|
||
| public static initialize(setVisibility: (visible: boolean) => void): void { | ||
| this._setVisibility = setVisibility; | ||
| } | ||
|
|
||
| public static show(): void { | ||
| if (this._setVisibility) { | ||
| this._isVisible = true; | ||
| this._setVisibility(true); | ||
| } | ||
| } | ||
|
|
||
| public static hide(): void { | ||
| if (this._setVisibility) { | ||
| this._isVisible = false; | ||
| this._setVisibility(false); | ||
| } | ||
| } | ||
|
|
||
| public static isFormVisible(): boolean { | ||
| return this._isVisible; | ||
| } | ||
| } | ||
|
|
||
| interface FeedbackFormProviderProps { | ||
| children: React.ReactNode; | ||
| styles?: FeedbackFormStyles; | ||
| } | ||
|
|
||
| class FeedbackFormProvider extends React.Component<FeedbackFormProviderProps> { | ||
| public state = { | ||
| isVisible: false, | ||
| }; | ||
|
|
||
| public constructor(props: FeedbackFormProviderProps) { | ||
| super(props); | ||
| FeedbackFormManager.initialize(this._setVisibilityFunction); | ||
| } | ||
|
|
||
| /** | ||
| * Renders the feedback form modal. | ||
| */ | ||
| public render(): React.ReactNode { | ||
| if (!isModalSupported()) { | ||
| logger.error('FeedbackForm Modal is not supported in React Native < 0.71 with Fabric renderer.'); | ||
| return <>{this.props.children}</>; | ||
| } | ||
|
|
||
| const { isVisible } = this.state; | ||
| const styles: FeedbackFormStyles = { ...defaultStyles, ...this.props.styles }; | ||
|
|
||
| // Wrapping the `Modal` component in a `View` component is necessary to avoid | ||
| // issues like https://github.com/software-mansion/react-native-reanimated/issues/6035 | ||
| return ( | ||
| <> | ||
| {this.props.children} | ||
| {isVisible && ( | ||
| <View> | ||
| <Modal visible={isVisible} transparent animationType="slide" onRequestClose={this._handleClose} testID="feedback-form-modal"> | ||
| <View style={styles.modalBackground}> | ||
| <FeedbackForm {...getFeedbackOptions()} | ||
| onFormClose={this._handleClose} | ||
| onFormSubmitted={this._handleClose} | ||
| /> | ||
| </View> | ||
| </Modal> | ||
| </View> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| private _setVisibilityFunction = (visible: boolean): void => { | ||
| this.setState({ isVisible: visible }); | ||
| }; | ||
|
|
||
| private _handleClose = (): void => { | ||
| FeedbackFormManager.hide(); | ||
| this.setState({ isVisible: false }); | ||
| }; | ||
| } | ||
|
|
||
| const showFeedbackForm = (): void => { | ||
| FeedbackFormManager.show(); | ||
| }; | ||
|
|
||
| export { showFeedbackForm, FeedbackFormProvider }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type { Integration } from '@sentry/core'; | ||
|
|
||
| import { defaultConfiguration } from './defaults'; | ||
| import defaultStyles from './FeedbackForm.styles'; | ||
| import type { FeedbackFormProps } from './FeedbackForm.types'; | ||
|
|
||
| export const FEEDBACK_FORM_INTEGRATION_NAME = 'Feedback Form'; | ||
|
|
||
| type FeedbackIntegration = Integration & { | ||
| options: Partial<FeedbackFormProps>; | ||
| }; | ||
|
|
||
| let savedOptions: Partial<FeedbackFormProps> = {}; | ||
|
|
||
| export const feedbackIntegration = (initOptions: FeedbackFormProps = {}): FeedbackIntegration => { | ||
| savedOptions = { | ||
| ...defaultConfiguration, | ||
| ...initOptions, | ||
| styles: { | ||
| ...defaultStyles, | ||
| ...initOptions.styles, | ||
krystofwoldrich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
|
|
||
| return { | ||
| name: FEEDBACK_FORM_INTEGRATION_NAME, | ||
| options: savedOptions, | ||
| }; | ||
| }; | ||
|
|
||
| export const getFeedbackOptions = (): Partial<FeedbackFormProps> => savedOptions; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { logger } from '@sentry/core'; | ||
| import { render } from '@testing-library/react-native'; | ||
| import * as React from 'react'; | ||
| import { Text } from 'react-native'; | ||
|
|
||
| import { FeedbackFormProvider, showFeedbackForm } from '../../src/js/feedback/FeedbackFormManager'; | ||
| import { feedbackIntegration } from '../../src/js/feedback/integration'; | ||
|
|
||
| jest.mock('../../src/js/feedback/utils', () => ({ | ||
| isModalSupported: jest.fn(), | ||
| })); | ||
|
|
||
| beforeEach(() => { | ||
| logger.error = jest.fn(); | ||
| }); | ||
|
|
||
| describe('FeedbackFormManager', () => { | ||
| it('showFeedbackForm displays the form when FeedbackFormProvider is used', () => { | ||
| require('../../src/js/feedback/utils').isModalSupported.mockReturnValue(true); | ||
| const { getByText, getByTestId } = render( | ||
| <FeedbackFormProvider> | ||
| <Text>App Components</Text> | ||
| </FeedbackFormProvider> | ||
| ); | ||
|
|
||
| showFeedbackForm(); | ||
|
|
||
| expect(getByTestId('feedback-form-modal')).toBeTruthy(); | ||
| expect(getByText('App Components')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('showFeedbackForm does not display the form when Modal is not available', () => { | ||
| require('../../src/js/feedback/utils').isModalSupported.mockReturnValue(false); | ||
| const { getByText, queryByTestId } = render( | ||
| <FeedbackFormProvider> | ||
| <Text>App Components</Text> | ||
| </FeedbackFormProvider> | ||
| ); | ||
|
|
||
| showFeedbackForm(); | ||
|
|
||
| expect(queryByTestId('feedback-form-modal')).toBeNull(); | ||
| expect(getByText('App Components')).toBeTruthy(); | ||
| expect(logger.error).toHaveBeenLastCalledWith( | ||
| 'FeedbackForm Modal is not supported in React Native < 0.71 with Fabric renderer.', | ||
| ); | ||
| }); | ||
|
|
||
| it('showFeedbackForm does not throw an error when FeedbackFormProvider is not used', () => { | ||
| expect(() => { | ||
| showFeedbackForm(); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| it('showFeedbackForm displays the form with the feedbackIntegration options', () => { | ||
| require('../../src/js/feedback/utils').isModalSupported.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(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.