-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(feedback): Revamp of user feedback screenshot editing #15424
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 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c6a13d8
wip: need to fix border & resizing
c298lee b52d5a7
Merge branch 'develop' into cl/annotations-v2
c298lee 2c0fd8c
buggy resizing & screenshotting
c298lee 50ca3ea
back to prev drawBuffer plus move scaling out
c298lee 0ba53a6
shrinking works
c298lee 8908648
working resize & delete
c298lee dc273c3
no bugs hopefully
c298lee 3282a1d
custom rectangle outline colour
c298lee 43be14b
PR comments
c298lee 6b88c44
one more callback
c298lee a301ce1
Merge branch 'develop' into cl/annotations-v2
c298lee a8c4840
rm old screenshot stuff
c298lee 6a18b5a
clean up css & hide is just black rectangle
c298lee 7c52b22
fix lint
c298lee 766e036
Merge branch 'develop' into cl/annotations-v2
c298lee aa80b58
fix linewidth
c298lee 1c198fb
rm annotations flag
c298lee 9f206eb
PR comments
c298lee 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { VNode, h as hType } from 'preact'; | ||
|
|
||
| interface FactoryParams { | ||
| h: typeof hType; | ||
| } | ||
|
|
||
| export default function IconCloseFactory({ | ||
| h, // eslint-disable-line @typescript-eslint/no-unused-vars | ||
| }: FactoryParams) { | ||
| return function IconClose(): VNode { | ||
| return ( | ||
| <svg data-test-id="icon-close" viewBox="0 0 16 16" fill="#2B2233" height="25px" width="25px"> | ||
| <circle r="7" cx="8" cy="8" fill="white" /> | ||
| <path | ||
| strokeWidth="1.5" | ||
| d="M8,16a8,8,0,1,1,8-8A8,8,0,0,1,8,16ZM8,1.53A6.47,6.47,0,1,0,14.47,8,6.47,6.47,0,0,0,8,1.53Z" | ||
| ></path> | ||
| <path | ||
| strokeWidth="1.5" | ||
| d="M5.34,11.41a.71.71,0,0,1-.53-.22.74.74,0,0,1,0-1.06l5.32-5.32a.75.75,0,0,1,1.06,1.06L5.87,11.19A.74.74,0,0,1,5.34,11.41Z" | ||
| ></path> | ||
| <path | ||
| strokeWidth="1.5" | ||
| d="M10.66,11.41a.74.74,0,0,1-.53-.22L4.81,5.87A.75.75,0,0,1,5.87,4.81l5.32,5.32a.74.74,0,0,1,0,1.06A.71.71,0,0,1,10.66,11.41Z" | ||
| ></path> | ||
| </svg> | ||
| ); | ||
| }; | ||
| } |
363 changes: 363 additions & 0 deletions
363
packages/feedback/src/screenshot/components/ScreenshotEditorv2.tsx
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,363 @@ | ||||||||||||||||||||||||
| /* eslint-disable max-lines */ | ||||||||||||||||||||||||
| import type { ComponentType, VNode, h as hType } from 'preact'; | ||||||||||||||||||||||||
| import { h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-vars | ||||||||||||||||||||||||
| import type * as Hooks from 'preact/hooks'; | ||||||||||||||||||||||||
| import { useTakeScreenshotFactory } from './useTakeScreenshot'; | ||||||||||||||||||||||||
| import type { FeedbackInternalOptions, FeedbackModalIntegration } from '@sentry/core'; | ||||||||||||||||||||||||
| import { DOCUMENT, WINDOW } from '../../constants'; | ||||||||||||||||||||||||
| import { createScreenshotInputStyles } from './ScreenshotInput.css'; | ||||||||||||||||||||||||
| import ToolbarFactoryv2 from './Toolbarv2'; | ||||||||||||||||||||||||
| import IconCloseFactory from './IconClose'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| interface FactoryParams { | ||||||||||||||||||||||||
| h: typeof hType; | ||||||||||||||||||||||||
| hooks: typeof Hooks; | ||||||||||||||||||||||||
| imageBuffer: HTMLCanvasElement; | ||||||||||||||||||||||||
| dialog: ReturnType<FeedbackModalIntegration['createDialog']>; | ||||||||||||||||||||||||
| options: FeedbackInternalOptions; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| interface Props { | ||||||||||||||||||||||||
| onError: (error: Error) => void; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| interface Box { | ||||||||||||||||||||||||
| action: 'highlight' | 'hide' | ''; | ||||||||||||||||||||||||
| startX: number; | ||||||||||||||||||||||||
| startY: number; | ||||||||||||||||||||||||
| endX: number; | ||||||||||||||||||||||||
| endY: number; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| interface Rect { | ||||||||||||||||||||||||
| action: 'highlight' | 'hide' | ''; | ||||||||||||||||||||||||
| x: number; | ||||||||||||||||||||||||
| y: number; | ||||||||||||||||||||||||
| height: number; | ||||||||||||||||||||||||
| width: number; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const DPI = WINDOW.devicePixelRatio; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const constructRect = (box: Box): Rect => ({ | ||||||||||||||||||||||||
| action: box.action, | ||||||||||||||||||||||||
| x: Math.min(box.startX, box.endX), | ||||||||||||||||||||||||
| y: Math.min(box.startY, box.endY), | ||||||||||||||||||||||||
| width: Math.abs(box.startX - box.endX), | ||||||||||||||||||||||||
| height: Math.abs(box.startY - box.endY), | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const getContainedSize = (measurementDiv: HTMLDivElement, imageSource: HTMLCanvasElement): Rect => { | ||||||||||||||||||||||||
| const imgClientHeight = measurementDiv.clientHeight; | ||||||||||||||||||||||||
| const imgClientWidth = measurementDiv.clientWidth; | ||||||||||||||||||||||||
| const ratio = imageSource.width / imageSource.height; | ||||||||||||||||||||||||
| let width = imgClientHeight * ratio; | ||||||||||||||||||||||||
| let height = imgClientHeight; | ||||||||||||||||||||||||
| if (width > imgClientWidth) { | ||||||||||||||||||||||||
| width = imgClientWidth; | ||||||||||||||||||||||||
| height = imgClientWidth / ratio; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| const x = (imgClientWidth - width) / 2; | ||||||||||||||||||||||||
| const y = (imgClientHeight - height) / 2; | ||||||||||||||||||||||||
| return { action: '', x: x, y: y, width: width, height: height }; | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function drawRect(rect: Rect, ctx: CanvasRenderingContext2D, scale: number = 1, lineWidth: number = 4): void { | ||||||||||||||||||||||||
| const scaledX = rect.x * scale; | ||||||||||||||||||||||||
| const scaledY = rect.y * scale; | ||||||||||||||||||||||||
| const scaledWidth = rect.width * scale; | ||||||||||||||||||||||||
| const scaledHeight = rect.height * scale; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // creates a shadow around | ||||||||||||||||||||||||
| ctx.shadowColor = 'rgba(0, 0, 0, 0.7)'; | ||||||||||||||||||||||||
| ctx.shadowBlur = 50; // Amount of blur for the shadow | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| switch (rect.action) { | ||||||||||||||||||||||||
| case 'highlight': | ||||||||||||||||||||||||
| // draws a rectangle first so that the shadow is visible before clearing | ||||||||||||||||||||||||
| ctx.fillStyle = 'rgb(0, 0, 0)'; | ||||||||||||||||||||||||
| ctx.fillRect(scaledX, scaledY, scaledWidth, scaledHeight); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ctx.clearRect(scaledX, scaledY, scaledWidth, scaledHeight); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| case 'hide': | ||||||||||||||||||||||||
| ctx.fillStyle = 'rgb(0, 0, 0)'; | ||||||||||||||||||||||||
| ctx.fillRect(scaledX, scaledY, scaledWidth, scaledHeight); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Disable shadow after the action is drawn | ||||||||||||||||||||||||
| ctx.shadowColor = 'transparent'; | ||||||||||||||||||||||||
| ctx.shadowBlur = 0; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let strokeColor; | ||||||||||||||||||||||||
| const sentryFeedback = DOCUMENT.getElementById('sentry-feedback'); | ||||||||||||||||||||||||
| if (sentryFeedback) { | ||||||||||||||||||||||||
| strokeColor = | ||||||||||||||||||||||||
| getComputedStyle(sentryFeedback).getPropertyValue('--button-primary-background') || | ||||||||||||||||||||||||
| getComputedStyle(sentryFeedback).getPropertyValue('--accent-background'); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| if (sentryFeedback) { | |
| strokeColor = | |
| getComputedStyle(sentryFeedback).getPropertyValue('--button-primary-background') || | |
| getComputedStyle(sentryFeedback).getPropertyValue('--accent-background'); | |
| } | |
| if (sentryFeedback) { | |
| const computedStyle = getComputedStyle(sentryFeedback); | |
| strokeColor = | |
| computedStyle.getPropertyValue('--button-primary-background') || | |
| computedStyle.getPropertyValue('--accent-background'); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, not sure if this is the best way to do this, but it works
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c298lee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Oops, something went wrong.
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.