Skip to content
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

feat(feedback): add spam detection to project settings #66740

Merged
merged 5 commits into from
Mar 21, 2024
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
22 changes: 22 additions & 0 deletions static/app/data/forms/userFeedbackProcessing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type {JsonFormObject} from 'sentry/components/forms/types';

export const route = '/settings/:orgId/projects/:projectId/user-feedback-processing/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find an import for this one

Copy link
Member Author

@michellewzhang michellewzhang Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from a previous file, but in those i see this:
// Export route to make these forms searchable by label/help

so maybe it's necessary


const formGroups: JsonFormObject[] = [
{
title: 'Settings',
fields: [
{
name: 'sentry:feedback_ai_spam_detection',
type: 'boolean',

// additional data/props that is related to rendering of form field rather than data
label: 'Enable Spam Detection',
help: 'Toggles whether or not to enable auto spam detection in User Feedback.',
getData: data => ({options: data}),
},
],
},
];

export default formGroups;
7 changes: 7 additions & 0 deletions static/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,13 @@ function buildRoutes() {
name={t('Replays')}
component={make(() => import('sentry/views/settings/project/projectReplays'))}
/>
<Route
path="user-feedback-processing/"
name={t('User Feedback')}
component={make(
() => import('sentry/views/settings/project/projectUserFeedbackProcessing')
)}
/>

<Route path="source-maps/" name={t('Source Maps')}>
<IndexRoute
Expand Down
5 changes: 5 additions & 0 deletions static/app/views/settings/project/navigationConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ export default function getConfiguration({
title: t('Replays'),
show: () => !!organization?.features?.includes('session-replay-ui'),
},
{
path: `${pathPrefix}/user-feedback-processing/`,
title: t('User Feedback'),
show: () => !!organization?.features?.includes('user-feedback-ui'),
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {ProjectFixture} from 'sentry-fixture/project';

import {initializeOrg} from 'sentry-test/initializeOrg';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import ProjectUserFeedbackProcessing from 'sentry/views/settings/project/projectUserFeedbackProcessing';

describe('ProjectUserFeedbackProcessing', function () {
const {routerProps, organization, project, routerContext} = initializeOrg();
const url = `/projects/${organization.slug}/${project.slug}/`;

beforeEach(function () {
MockApiClient.clearMockResponses();
MockApiClient.addMockResponse({
url,
method: 'GET',
body: ProjectFixture(),
});
MockApiClient.addMockResponse({
url: `${url}keys/`,
method: 'GET',
body: [],
});
});

it('can toggle spam detection', async function () {
render(
<ProjectUserFeedbackProcessing
{...routerProps}
organization={organization}
project={project}
/>,
{
context: routerContext,
}
);

const mock = MockApiClient.addMockResponse({
url,
method: 'PUT',
});

await userEvent.click(screen.getByRole('checkbox', {name: 'Enable Spam Detection'}));

expect(mock).toHaveBeenCalledWith(
url,
expect.objectContaining({
method: 'PUT',
data: {
options: {'sentry:feedback_ai_spam_detection': true},
},
})
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type {RouteComponentProps} from 'react-router';

import Access from 'sentry/components/acl/access';
import {Button} from 'sentry/components/button';
import Form from 'sentry/components/forms/form';
import JsonForm from 'sentry/components/forms/jsonForm';
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
import formGroups from 'sentry/data/forms/userFeedbackProcessing';
import {t} from 'sentry/locale';
import type {Organization, Project} from 'sentry/types';
import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
import PermissionAlert from 'sentry/views/settings/project/permissionAlert';

type RouteParams = {
projectId: string;
};
type Props = RouteComponentProps<RouteParams, {}> & {
organization: Organization;
project: Project;
};

function ProjectUserFeedbackProcessingSettings({
project,
organization,
params: {projectId},
}: Props) {
return (
<SentryDocumentTitle title={t('User Feedback')} projectSlug={project.slug}>
<SettingsPageHeader
title={t('User Feedback')}
action={
<Button external href="https://docs.sentry.io/product/user-feedback/">
{t('Read the docs')}
</Button>
}
/>
<PermissionAlert project={project} />
<Form
saveOnBlur
apiMethod="PUT"
apiEndpoint={`/projects/${organization.slug}/${projectId}/`}
initialData={project.options}
>
<Access access={['project:write']} project={project}>
{({hasAccess}) => <JsonForm disabled={!hasAccess} forms={formGroups} />}
</Access>
</Form>
</SentryDocumentTitle>
);
}

export default ProjectUserFeedbackProcessingSettings;
Loading