Skip to content

ref(feedback): Remove isAnonymous option from feedback #9602

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 2 commits into from
Nov 20, 2023
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
7 changes: 4 additions & 3 deletions packages/feedback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ The following options can be configured as options to the integration, in `new F
| --------- | ------- | ------- | ----------- |
| `showName` | `boolean` | `true` | Displays the name field on the feedback form, however will still capture the name (if available) from Sentry SDK context. |
| `showEmail` | `boolean` | `true` | Displays the email field on the feedback form, however will still capture the email (if available) from Sentry SDK context. |
| `isAnonymous` | `boolean` | `false` | Hides both name and email fields and does not use Sentry SDK's user context. |
| `isNameRequired` | `boolean` | `false` | Requires the name field on the feedback form to be filled in. |
| `isEmailRequired` | `boolean` | `false` | Requires the email field on the feedback form to be filled in. |
| `useSentryUser` | `Record<string, string>` | `{ email: 'email', name: 'username'}` | Map of the `email` and `name` fields to the corresponding Sentry SDK user fields that were called with `Sentry.setUser`. |

By default the Feedback integration will attempt to fill in the name/email fields if you have set a user context via [`Sentry.setUser`](https://docs.sentry.io/platforms/javascript/enriching-events/identify-user/). By default it expects the email and name fields to be `email` and `username`. Below is an example configuration with non-default user fields.
Expand Down Expand Up @@ -133,7 +134,7 @@ Colors can be customized via the Feedback constructor or by defining CSS variabl
| `submitForegroundHover` | `--submit-foreground-hover` | `#ffffff` | `#ffffff` | Foreground color for the submit button when hovering |
| `cancelBackground` | `--cancel-background` | `transparent` | `transparent` | Background color for the cancel button |
| `cancelBackgroundHover` | `--cancel-background-hover` | `var(--background-hover)` | `var(--background-hover)` | Background color when hovering over the cancel button |
| `cancelBorder` | `--cancel-border` | `var(--border)` | `var(--border)` | Border style for the cancel button |
| `cancelBorder` | `--cancel-border` | `var(--border)` | `var(--border)` | Border style for the cancel button |
| `cancelOutlineFocus` | `--cancel-outline-focus` | `var(--input-outline-focus)` | `var(--input-outline-focus)` | Outline color for the cancel button, in the focused state |
| `cancelForeground` | `--cancel-foreground` | `var(--foreground)` | `var(--foreground)` | Foreground color for the cancel button |
| `cancelForegroundHover` | `--cancel-foreground-hover` | `var(--foreground)` | `var(--foreground)` | Foreground color for the cancel button when hovering |
Expand Down Expand Up @@ -270,7 +271,7 @@ document.getElementById('my-feedback-form').addEventListener('submit', (event) =

Note: The following instructions are to be followed in the Sentry product.

If you have Sentry's default issue alert ("Alert me on every new issue") turned on for the project you are setting up User Feedback on, no action is required to have alerting on each user feedback report.
If you have Sentry's default issue alert ("Alert me on every new issue") turned on for the project you are setting up User Feedback on, no action is required to have alerting on each user feedback report.

If you don't have Sentry's default issue alert turned on, follow these steps:

Expand Down
2 changes: 0 additions & 2 deletions packages/feedback/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export class Feedback implements Integration {
email: 'email',
name: 'username',
},
isAnonymous = false,
isEmailRequired = false,
isNameRequired = false,

Expand Down Expand Up @@ -120,7 +119,6 @@ export class Feedback implements Integration {
id,
showBranding,
autoInject,
isAnonymous,
isEmailRequired,
isNameRequired,
showEmail,
Expand Down
5 changes: 0 additions & 5 deletions packages/feedback/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ export interface FeedbackGeneralConfiguration {
*/
autoInject: boolean;

/**
* If true, will not collect user data (email/name).
*/
isAnonymous: boolean;

/**
* Should the email field be required?
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/feedback/src/widget/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export function Dialog({
isNameRequired,
isEmailRequired,
colorScheme,
isAnonymous,
defaultName,
defaultEmail,
onClosed,
Expand Down Expand Up @@ -103,7 +102,6 @@ export function Dialog({
} = Form({
showEmail,
showName,
isAnonymous,
isEmailRequired,
isNameRequired,

Expand Down
12 changes: 4 additions & 8 deletions packages/feedback/src/widget/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface FormComponentProps
FeedbackInternalOptions,
| 'showName'
| 'showEmail'
| 'isAnonymous'
| 'isNameRequired'
| 'isEmailRequired'
| Exclude<keyof FeedbackTextConfiguration, 'buttonLabel' | 'formTitle' | 'successMessageText'>
Expand Down Expand Up @@ -59,7 +58,6 @@ export function Form({

showName,
showEmail,
isAnonymous,
isNameRequired,
isEmailRequired,

Expand Down Expand Up @@ -166,8 +164,7 @@ export function Form({
[
errorEl,

!isAnonymous &&
showName &&
showName &&
createElement(
'label',
{
Expand All @@ -184,10 +181,9 @@ export function Form({
nameEl,
],
),
!isAnonymous && !showName && nameEl,
!showName && nameEl,

!isAnonymous &&
showEmail &&
showEmail &&
createElement(
'label',
{
Expand All @@ -204,7 +200,7 @@ export function Form({
emailEl,
],
),
!isAnonymous && !showEmail && emailEl,
!showEmail && emailEl,

createElement(
'label',
Expand Down
5 changes: 2 additions & 3 deletions packages/feedback/src/widget/createWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function createWidget({
if (!feedback.message) {
emptyField.push(options.messageLabel);
}
if (emptyField.length != 0) {
if (emptyField.length > 0) {
dialog.showError(`Please enter in the following required fields: ${emptyField.join(', ')}`);
return;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ export function createWidget({
return;
}

const userKey = !options.isAnonymous && options.useSentryUser;
const userKey = options.useSentryUser;
const scope = getCurrentHub().getScope();
const user = scope && scope.getUser();

Expand All @@ -168,7 +168,6 @@ export function createWidget({
showBranding: options.showBranding,
showName: options.showName || options.isNameRequired,
showEmail: options.showEmail || options.isEmailRequired,
isAnonymous: options.isAnonymous,
isNameRequired: options.isNameRequired,
isEmailRequired: options.isEmailRequired,
formTitle: options.formTitle,
Expand Down
2 changes: 0 additions & 2 deletions packages/feedback/test/widget/Dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function renderDialog({
showName = true,
showEmail = true,
showBranding = false,
isAnonymous = false,
isNameRequired = false,
isEmailRequired = false,
formTitle = 'Feedback',
Expand All @@ -29,7 +28,6 @@ function renderDialog({
return Dialog({
formTitle,

isAnonymous,
showName,
showEmail,
isNameRequired,
Expand Down
31 changes: 0 additions & 31 deletions packages/feedback/test/widget/Form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type NonNullableFields<T> = {
function renderForm({
showName = true,
showEmail = true,
isAnonymous = false,
isNameRequired = false,
isEmailRequired = false,
defaultName = 'Foo Bar',
Expand All @@ -24,7 +23,6 @@ function renderForm({
...rest
}: Partial<FormComponentProps> = {}) {
return Form({
isAnonymous,
showName,
showEmail,
isNameRequired,
Expand Down Expand Up @@ -138,33 +136,4 @@ describe('Form', () => {
name: 'Foo Bar',
});
});

it('does not show name or email inputs for anonymous mode', () => {
const onSubmit = jest.fn();
const formComponent = renderForm({
isNameRequired: true,
isEmailRequired: true,
isAnonymous: true,
onSubmit,
});
const submitEvent = new Event('submit');

expect(formComponent.el).toBeInstanceOf(HTMLFormElement);
const nameInput = formComponent.el.querySelector('[name="name"][type="text"]') as HTMLInputElement;
const emailInput = formComponent.el.querySelector('[name="email"][type="text"]') as HTMLInputElement;
expect(nameInput).toBeNull();
expect(emailInput).toBeNull();
expect(formComponent.el.querySelector('[name="message"]')).not.toBeNull();

const message = formComponent.el.querySelector('[name="message"]') as HTMLTextAreaElement;
message.value = 'Foo (message)';
message.dispatchEvent(new KeyboardEvent('keyup'));

formComponent.el.dispatchEvent(submitEvent);
expect(onSubmit).toHaveBeenCalledWith({
email: '',
message: 'Foo (message)',
name: '',
});
});
});
1 change: 0 additions & 1 deletion packages/feedback/test/widget/createWidget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const DEFAULT_OPTIONS = {
email: 'email',
name: 'username',
},
isAnonymous: false,
isEmailRequired: false,
isNameRequired: false,

Expand Down