-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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): Refactor the feedback screenshot rendering to show N screenshots side by side #68136
feat(feedback): Refactor the feedback screenshot rendering to show N screenshots side by side #68136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import {useCallback, useState} from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import {useDeleteEventAttachmentOptimistic} from 'sentry/actionCreators/events'; | ||
|
@@ -15,93 +14,79 @@ import {t} from 'sentry/locale'; | |
import {space} from 'sentry/styles/space'; | ||
import type {Organization} from 'sentry/types'; | ||
import type {Event} from 'sentry/types/event'; | ||
import type {EventAttachment} from 'sentry/types/group'; | ||
import {objectIsEmpty} from 'sentry/utils'; | ||
|
||
type Props = { | ||
event: Event; | ||
organization: Organization; | ||
projectSlug: string; | ||
}; | ||
|
||
export function ScreenshotSection({projectSlug, event, organization}: Props) { | ||
export function ScreenshotSection({event, organization, projectSlug}: Props) { | ||
const {screenshots} = useFeedbackScreenshot({projectSlug, event}); | ||
const hasContext = !objectIsEmpty(event.user ?? {}) || !objectIsEmpty(event.contexts); | ||
const {mutate: deleteAttachment} = useDeleteEventAttachmentOptimistic(); | ||
const [screenshotInFocus, setScreenshotInFocus] = useState<number>(0); | ||
|
||
const handleDeleteScreenshot = useCallback( | ||
(attachmentId: string) => { | ||
deleteAttachment({ | ||
orgSlug: organization.slug, | ||
projectSlug, | ||
eventId: event.id, | ||
attachmentId, | ||
}); | ||
}, | ||
[deleteAttachment, event.id, organization.slug, projectSlug] | ||
); | ||
|
||
const handleOpenVisualizationModal = useCallback( | ||
(eventAttachment: EventAttachment) => { | ||
openModal( | ||
modalProps => ( | ||
<OpenScreenshotModal | ||
{...modalProps} | ||
event={event} | ||
orgSlug={organization.slug} | ||
return screenshots.length ? ( | ||
<ScreenshotWrapper> | ||
{screenshots.map(screenshot => ( | ||
<li key={screenshot.id}> | ||
<FeedbackScreenshot | ||
organization={organization} | ||
projectSlug={projectSlug} | ||
eventAttachment={eventAttachment} | ||
attachments={screenshots} | ||
attachmentIndex={screenshotInFocus} | ||
screenshot={screenshot} | ||
onClick={() => { | ||
openModal( | ||
modalProps => ( | ||
<OpenScreenshotModal | ||
{...modalProps} | ||
event={event} | ||
orgSlug={organization.slug} | ||
projectSlug={projectSlug} | ||
eventAttachment={screenshot} | ||
attachments={screenshots} | ||
attachmentIndex={screenshots.indexOf(screenshot)} | ||
/> | ||
), | ||
{modalCss} | ||
); | ||
}} | ||
/> | ||
), | ||
{modalCss} | ||
); | ||
}, | ||
[event, organization.slug, projectSlug, screenshotInFocus, screenshots] | ||
); | ||
|
||
if (!hasContext && !screenshots.length) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need any of this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i took it out because i think we really only care that there are screenshots. Within the rest of the page we don't show context at all, we get the message from I'm a bit worried that we're assuming the attachments will be images though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we validate somehow that they are images? |
||
} | ||
|
||
const showScreenshot = !!screenshots.length; | ||
const screenshot = screenshots[screenshotInFocus]; | ||
|
||
return showScreenshot ? ( | ||
<ScreenshotWrapper> | ||
<FeedbackScreenshot | ||
organization={organization} | ||
eventId={event.id} | ||
projectSlug={projectSlug} | ||
screenshot={screenshot} | ||
onNext={() => setScreenshotInFocus(screenshotInFocus + 1)} | ||
onPrevious={() => setScreenshotInFocus(screenshotInFocus - 1)} | ||
screenshotInFocus={screenshotInFocus} | ||
totalScreenshots={screenshots.length} | ||
openVisualizationModal={handleOpenVisualizationModal} | ||
/> | ||
<Button | ||
icon={<IconDelete />} | ||
borderless | ||
size="xs" | ||
onClick={() => { | ||
openConfirmModal({ | ||
header: t('Delete screenshot?'), | ||
message: t('This action cannot be undone.'), | ||
confirmText: t('Delete screenshot'), | ||
onConfirm: () => handleDeleteScreenshot(screenshot.id), | ||
priority: 'danger', | ||
}); | ||
}} | ||
aria-label={t('Delete screenshot')} | ||
/> | ||
<Button | ||
icon={<IconDelete />} | ||
borderless | ||
size="xs" | ||
onClick={() => { | ||
openConfirmModal({ | ||
header: t('Delete screenshot?'), | ||
message: t('This action cannot be undone.'), | ||
confirmText: t('Delete screenshot'), | ||
onConfirm: () => | ||
deleteAttachment({ | ||
orgSlug: organization.slug, | ||
projectSlug, | ||
eventId: screenshot.event_id, | ||
attachmentId: screenshot.id, | ||
}), | ||
priority: 'danger', | ||
}); | ||
}} | ||
aria-label={t('Delete screenshot')} | ||
/> | ||
</li> | ||
))} | ||
</ScreenshotWrapper> | ||
) : null; | ||
} | ||
|
||
const ScreenshotWrapper = styled('div')` | ||
const ScreenshotWrapper = styled('ul')` | ||
display: flex; | ||
gap: ${space(1)}; | ||
flex-wrap: wrap; | ||
gap: ${space(1.5)}; | ||
margin: 0; | ||
padding: 0; | ||
list-style: none; | ||
|
||
& > li { | ||
display: flex; | ||
gap: ${space(1)}; | ||
} | ||
`; |
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.
deleting all the extra stuff !