Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
38a6085
Save form state for unsubmitted data
antonis Feb 14, 2025
56a113e
Show selected screenshot
antonis Feb 14, 2025
d2dd1f3
Use image uri instead of UInt8Array in onAddScreenshot callback
antonis Feb 14, 2025
9212cb8
Merge branch 'feedback-ui' into antonis/feedback-save-state
antonis Feb 17, 2025
1efb23e
Omit isVisible from state
antonis Feb 17, 2025
59f2f57
Save/clear form state on unmount
antonis Feb 17, 2025
797611f
Pass the missing attachment parameter in the onSubmitSuccess
antonis Feb 17, 2025
dbf8c90
Merge branch 'antonis/feedback-save-state' into antonis/feedback-show…
antonis Feb 17, 2025
91117e3
Merge branch 'antonis/feedback-show-screenshot' into antonis/feedback…
antonis Feb 17, 2025
f14197d
Use only the uri parameter for the onAddScreenshot callback
antonis Feb 17, 2025
e63ee11
Merge branch 'feedback-ui' into antonis/feedback-save-state
antonis Feb 17, 2025
f220540
Merge branch 'antonis/feedback-save-state' into antonis/feedback-show…
antonis Feb 17, 2025
aae3a98
Merge branch 'antonis/feedback-show-screenshot' into antonis/feedback…
antonis Feb 17, 2025
41cb1ca
Handle attachments on the web
antonis Feb 17, 2025
f5c306f
Use window for showing alerts on the web
antonis Feb 17, 2025
42ab16c
Disable keyboard handling on the web
antonis Feb 17, 2025
f17106e
Use instance variable for _didSubmitForm
antonis Feb 18, 2025
f95ed97
Fixed callback function parameter name for clarity
antonis Feb 18, 2025
869f22b
Merge branch 'antonis/feedback-save-state' into antonis/feedback-show…
antonis Feb 18, 2025
6e2d6ec
Fixes lint issue
antonis Feb 18, 2025
082ef57
Merge branch 'antonis/feedback-save-state' into antonis/feedback-show…
antonis Feb 18, 2025
e5a9bcc
Merge branch 'antonis/feedback-show-screenshot' into antonis/feedback…
antonis Feb 18, 2025
4336622
Merge branch 'antonis/feedback-simplify-onaddscreenshot' into antonis…
antonis Feb 18, 2025
28738bf
Use RN_GLOBAL_OBJ for web alert
antonis Feb 18, 2025
01cb31d
Merge branch 'feedback-ui' into antonis/feedback-webfixes
antonis Feb 18, 2025
5713417
misc(feedback): Improve Feedback Sheet interactions
krystofwoldrich Feb 19, 2025
a74f36f
small fixes
krystofwoldrich Feb 19, 2025
2eeaa46
update snapshots
krystofwoldrich Feb 19, 2025
040fd4a
Merge branch 'feedback-ui' into kw-improve-feedback-interactions
antonis Feb 20, 2025
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
57 changes: 34 additions & 23 deletions packages/core/src/js/feedback/FeedbackWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
...defaultConfiguration
}

private static _savedState: FeedbackFormState = {
isVisible: false,
private static _didSubmitForm: boolean = false;
private static _savedState: Omit<FeedbackWidgetState, 'isVisible'> = {
name: '',
email: '',
description: '',
Expand All @@ -43,7 +43,7 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
attachmentUri: undefined,
};

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

const currentUser = {
Expand All @@ -55,12 +55,12 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac

this.state = {
isVisible: true,
name: FeedbackForm._savedState.name || currentUser.useSentryUser.name,
email: FeedbackForm._savedState.email || currentUser.useSentryUser.email,
description: FeedbackForm._savedState.description || '',
filename: FeedbackForm._savedState.filename || undefined,
attachment: FeedbackForm._savedState.attachment || undefined,
attachmentUri: FeedbackForm._savedState.attachmentUri || undefined,
name: FeedbackWidget._savedState.name || currentUser.useSentryUser.name,
email: FeedbackWidget._savedState.email || currentUser.useSentryUser.email,
description: FeedbackWidget._savedState.description || '',
filename: FeedbackWidget._savedState.filename || undefined,
attachment: FeedbackWidget._savedState.attachment || undefined,
attachmentUri: FeedbackWidget._savedState.attachmentUri || undefined,
};
}

Expand Down Expand Up @@ -103,10 +103,10 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
try {
this.setState({ isVisible: false });
captureFeedback(userFeedback, attachments ? { attachments } : undefined);
onSubmitSuccess({ name: trimmedName, email: trimmedEmail, message: trimmedDescription, attachments: undefined });
onSubmitSuccess({ name: trimmedName, email: trimmedEmail, message: trimmedDescription, attachments: attachments });
Alert.alert(text.successMessageText);
onFormSubmitted();
this._clearFormState();
FeedbackWidget._didSubmitForm = true;
} catch (error) {
const errorString = `Feedback form submission failed: ${error}`;
onSubmitError(new Error(errorString));
Expand Down Expand Up @@ -143,25 +143,37 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
const imageUri = result.assets[0].uri;
NATIVE.getDataFromUri(imageUri).then((data) => {
if (data != null) {
this.setState({ filename, attachment: data, attachmentUri: imageUri }, this._saveFormState);
this.setState({ filename, attachment: data, attachmentUri: imageUri });
} else {
logger.error('Failed to read image data from uri:', imageUri);
}
})
.catch((error) => {
logger.error('Failed to read image data from uri:', imageUri, 'error: ', error);
});
.catch((error) => {
logger.error('Failed to read image data from uri:', imageUri, 'error: ', error);
});
}
} else {
// Defaulting to the onAddScreenshot callback
const { onAddScreenshot } = { ...defaultConfiguration, ...this.props };
onAddScreenshot((filename: string, attachement: Uint8Array) => {
// TODO: Add support for image uri when using onAddScreenshot
this.setState({ filename, attachment: attachement, attachmentUri: undefined }, this._saveFormState);
this.setState({ filename, attachment: attachement, attachmentUri: undefined });
});
}
} else {
this.setState({ filename: undefined, attachment: undefined, attachmentUri: undefined }, this._saveFormState);
this.setState({ filename: undefined, attachment: undefined, attachmentUri: undefined });
}
}

/**
* Save the state before unmounting the component.
*/
public componentWillUnmount(): void {
if (FeedbackWidget._didSubmitForm) {
this._clearFormState();
FeedbackWidget._didSubmitForm = false;
} else {
this._saveFormState();
}
}

Expand Down Expand Up @@ -214,7 +226,7 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
style={styles.input}
placeholder={text.namePlaceholder}
value={name}
onChangeText={(value) => this.setState({ name: value }, this._saveFormState)}
onChangeText={(value) => this.setState({ name: value })}
/>
</>
)}
Expand All @@ -230,7 +242,7 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
placeholder={text.emailPlaceholder}
keyboardType={'email-address' as KeyboardTypeOptions}
value={email}
onChangeText={(value) => this.setState({ email: value }, this._saveFormState)}
onChangeText={(value) => this.setState({ email: value })}
/>
</>
)}
Expand All @@ -243,7 +255,7 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
style={[styles.input, styles.textArea]}
placeholder={text.messagePlaceholder}
value={description}
onChangeText={(value) => this.setState({ description: value }, this._saveFormState)}
onChangeText={(value) => this.setState({ description: value })}
multiline
/>
{(config.enableScreenshot || imagePickerConfiguration.imagePicker) && (
Expand Down Expand Up @@ -279,12 +291,11 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
}

private _saveFormState = (): void => {
FeedbackForm._savedState = { ...this.state };
FeedbackWidget._savedState = { ...this.state };
};

private _clearFormState = (): void => {
FeedbackForm._savedState = {
isVisible: false,
FeedbackWidget._savedState = {
name: '',
email: '',
description: '',
Expand Down
25 changes: 21 additions & 4 deletions packages/core/test/feedback/FeedbackWidget.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,30 +355,47 @@ describe('FeedbackWidget', () => {
expect(mockOnFormClose).toHaveBeenCalled();
});

it('onUnmount the input is saved and restored when the form reopens', async () => {
const { getByPlaceholderText, unmount } = render(<FeedbackWidget {...defaultProps} />);

fireEvent.changeText(getByPlaceholderText(defaultProps.namePlaceholder), 'John Doe');
fireEvent.changeText(getByPlaceholderText(defaultProps.emailPlaceholder), '[email protected]');
fireEvent.changeText(getByPlaceholderText(defaultProps.messagePlaceholder), 'This is a feedback message.');

unmount();
const { queryByPlaceholderText } = render(<FeedbackWidget {...defaultProps} />);

expect(queryByPlaceholderText(defaultProps.namePlaceholder).props.value).toBe('John Doe');
expect(queryByPlaceholderText(defaultProps.emailPlaceholder).props.value).toBe('[email protected]');
expect(queryByPlaceholderText(defaultProps.messagePlaceholder).props.value).toBe('This is a feedback message.');
});

it('onCancel the input is saved and restored when the form reopens', async () => {
const { getByPlaceholderText, getByText } = render(<FeedbackForm {...defaultProps} />);
const { getByPlaceholderText, getByText, unmount } = render(<FeedbackWidget {...defaultProps} />);

fireEvent.changeText(getByPlaceholderText(defaultProps.namePlaceholder), 'John Doe');
fireEvent.changeText(getByPlaceholderText(defaultProps.emailPlaceholder), '[email protected]');
fireEvent.changeText(getByPlaceholderText(defaultProps.messagePlaceholder), 'This is a feedback message.');

fireEvent.press(getByText(defaultProps.cancelButtonLabel));
const { queryByPlaceholderText } = render(<FeedbackForm {...defaultProps} />);
unmount();
const { queryByPlaceholderText } = render(<FeedbackWidget {...defaultProps} />);

expect(queryByPlaceholderText(defaultProps.namePlaceholder).props.value).toBe('John Doe');
expect(queryByPlaceholderText(defaultProps.emailPlaceholder).props.value).toBe('[email protected]');
expect(queryByPlaceholderText(defaultProps.messagePlaceholder).props.value).toBe('This is a feedback message.');
});

it('onSubmit the saved input is cleared and not restored when the form reopens', async () => {
const { getByPlaceholderText, getByText } = render(<FeedbackForm {...defaultProps} />);
const { getByPlaceholderText, getByText, unmount } = render(<FeedbackWidget {...defaultProps} />);

fireEvent.changeText(getByPlaceholderText(defaultProps.namePlaceholder), 'John Doe');
fireEvent.changeText(getByPlaceholderText(defaultProps.emailPlaceholder), '[email protected]');
fireEvent.changeText(getByPlaceholderText(defaultProps.messagePlaceholder), 'This is a feedback message.');

fireEvent.press(getByText(defaultProps.submitButtonLabel));
const { queryByPlaceholderText } = render(<FeedbackForm {...defaultProps} />);
unmount();
const { queryByPlaceholderText } = render(<FeedbackWidget {...defaultProps} />);

expect(queryByPlaceholderText(defaultProps.namePlaceholder).props.value).toBe('Test User');
expect(queryByPlaceholderText(defaultProps.emailPlaceholder).props.value).toBe('[email protected]');
Expand Down
Loading