Skip to content

wip: screenshots in feedback #9562

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

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 4 additions & 5 deletions packages/feedback/src/sendFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import type { BrowserClient, Replay } from '@sentry/browser';
import { getCurrentHub } from '@sentry/core';
import { getLocationHref } from '@sentry/utils';

import type { SendFeedbackOptions } from './types';
import type { FeedbackFormData, Screenshot, SendFeedbackOptions } from './types';
import { sendFeedbackRequest } from './util/sendFeedbackRequest';

interface SendFeedbackParams {
message: string;
name?: string;
email?: string;
interface SendFeedbackParams extends FeedbackFormData {
url?: string;
}

Expand All @@ -18,6 +15,7 @@ interface SendFeedbackParams {
export function sendFeedback(
{ name, email, message, url = getLocationHref() }: SendFeedbackParams,
{ includeReplay = true }: SendFeedbackOptions = {},
screenshots: Screenshot[] = [],
): ReturnType<typeof sendFeedbackRequest> {
const client = getCurrentHub().getClient<BrowserClient>();
const replay = includeReplay && client ? (client.getIntegrationById('Replay') as Replay | undefined) : undefined;
Expand All @@ -38,5 +36,6 @@ export function sendFeedback(
url,
replay_id: replayId,
},
screenshots,
});
}
23 changes: 23 additions & 0 deletions packages/feedback/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ export interface SendFeedbackData {
replay_id?: string;
name?: string;
};
screenshots: Screenshot[];
}

export interface SendFeedbackOptions {
/**
* Should include replay with the feedback?
*/
includeReplay?: boolean;

screenshots?: Screenshot[];
}

/**
Expand All @@ -31,6 +34,8 @@ export interface FeedbackFormData {
name?: string;
}

export interface FeedbackFormDataWithOptionalScreenshots extends FeedbackFormData, OptionalScreenshotData {}

/**
* General feedback configuration
*/
Expand Down Expand Up @@ -337,3 +342,21 @@ export interface FeedbackWidget {
closeDialog: () => void;
removeDialog: () => void;
}

export interface Rect {
height: number;
width: number;
x: number;
y: number;
}

export interface OptionalScreenshotData {
screenshot?: Blob | null;
screenshotCutout?: Blob | null;
}

export interface Screenshot {
filename: string;
data: Uint8Array;
contentType: string;
}
5 changes: 3 additions & 2 deletions packages/feedback/src/util/handleFeedbackSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { TransportMakeRequestResponse } from '@sentry/types';
import { logger } from '@sentry/utils';

import { sendFeedback } from '../sendFeedback';
import type { FeedbackFormData, SendFeedbackOptions } from '../types';
import type { FeedbackFormData, Screenshot, SendFeedbackOptions } from '../types';
import type { DialogComponent } from '../widget/Dialog';

/**
Expand All @@ -13,6 +13,7 @@ export async function handleFeedbackSubmit(
dialog: DialogComponent | null,
feedback: FeedbackFormData,
options?: SendFeedbackOptions,
screenshots?: Screenshot[],
): Promise<TransportMakeRequestResponse | void> {
if (!dialog) {
// Not sure when this would happen
Expand All @@ -29,7 +30,7 @@ export async function handleFeedbackSubmit(
dialog.hideError();

try {
const resp = await sendFeedback(feedback, options);
const resp = await sendFeedback(feedback, options, screenshots);

// Success!
return resp;
Expand Down
Loading