1
1
import type { ReactEventHandler } from 'react' ;
2
- import { Fragment , useState } from 'react' ;
2
+ import { useState } from 'react' ;
3
3
import { css } from '@emotion/react' ;
4
4
import styled from '@emotion/styled' ;
5
5
@@ -8,8 +8,9 @@ import {openConfirmModal} from 'sentry/components/confirm';
8
8
import { Button } from 'sentry/components/core/button' ;
9
9
import { ButtonBar } from 'sentry/components/core/button/buttonBar' ;
10
10
import { DropdownMenu } from 'sentry/components/dropdownMenu' ;
11
+ import ImageViewer from 'sentry/components/events/attachmentViewers/imageViewer' ;
11
12
import {
12
- getInlineAttachmentRenderer ,
13
+ getImageAttachmentRenderer ,
13
14
imageMimeTypes ,
14
15
webmMimeType ,
15
16
} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes' ;
@@ -70,115 +71,105 @@ function Screenshot({
70
71
onDelete ( screenshotAttachmentId ) ;
71
72
}
72
73
73
- function renderContent ( screenshotAttachment : EventAttachment ) {
74
- const AttachmentComponent = getInlineAttachmentRenderer ( screenshotAttachment ) ! ;
75
-
76
- const downloadUrl = `/api/0/projects/${ organization . slug } /${ projectSlug } /events/${ eventId } /attachments/${ screenshot . id } /` ;
77
-
78
- return (
79
- < Fragment >
80
- { totalScreenshots > 1 && (
81
- < StyledPanelHeader lightText >
74
+ const AttachmentComponent = getImageAttachmentRenderer ( screenshot ) ?? ImageViewer ;
75
+ const downloadUrl = `/api/0/projects/${ organization . slug } /${ projectSlug } /events/${ eventId } /attachments/${ screenshot . id } /` ;
76
+
77
+ return (
78
+ < StyledPanel >
79
+ { totalScreenshots > 1 && (
80
+ < StyledPanelHeader lightText >
81
+ < Button
82
+ disabled = { screenshotInFocus === 0 }
83
+ aria-label = { t ( 'Previous Screenshot' ) }
84
+ onClick = { onPrevious }
85
+ icon = { < IconChevron direction = "left" /> }
86
+ size = "xs"
87
+ />
88
+ { tct ( '[currentScreenshot] of [totalScreenshots]' , {
89
+ currentScreenshot : screenshotInFocus + 1 ,
90
+ totalScreenshots,
91
+ } ) }
92
+ < Button
93
+ disabled = { screenshotInFocus + 1 === totalScreenshots }
94
+ aria-label = { t ( 'Next Screenshot' ) }
95
+ onClick = { onNext }
96
+ icon = { < IconChevron direction = "right" /> }
97
+ size = "xs"
98
+ />
99
+ </ StyledPanelHeader >
100
+ ) }
101
+ < StyledPanelBody hasHeader = { totalScreenshots > 1 } >
102
+ { loadingImage && (
103
+ < StyledLoadingIndicator >
104
+ < LoadingIndicator mini />
105
+ </ StyledLoadingIndicator >
106
+ ) }
107
+ < AttachmentComponentWrapper
108
+ onClick = { ( ) => openVisualizationModal ( screenshot , `${ downloadUrl } ?download=1` ) }
109
+ >
110
+ < AttachmentComponent
111
+ orgSlug = { organization . slug }
112
+ projectSlug = { projectSlug }
113
+ eventId = { eventId }
114
+ attachment = { screenshot }
115
+ onLoad = { ( ) => setLoadingImage ( false ) }
116
+ onError = { ( ) => setLoadingImage ( false ) }
117
+ controls = { false }
118
+ onCanPlay = { ( ) => setLoadingImage ( false ) }
119
+ />
120
+ </ AttachmentComponentWrapper >
121
+ </ StyledPanelBody >
122
+ { ! onlyRenderScreenshot && (
123
+ < StyledPanelFooter >
124
+ < ButtonBar gap = { 1 } >
82
125
< Button
83
- disabled = { screenshotInFocus === 0 }
84
- aria-label = { t ( 'Previous Screenshot' ) }
85
- onClick = { onPrevious }
86
- icon = { < IconChevron direction = "left" /> }
87
126
size = "xs"
88
- />
89
- { tct ( '[currentScreenshot] of [totalScreenshots]' , {
90
- currentScreenshot : screenshotInFocus + 1 ,
91
- totalScreenshots,
92
- } ) }
93
- < Button
94
- disabled = { screenshotInFocus + 1 === totalScreenshots }
95
- aria-label = { t ( 'Next Screenshot' ) }
96
- onClick = { onNext }
97
- icon = { < IconChevron direction = "right" /> }
127
+ onClick = { ( ) =>
128
+ openVisualizationModal ( screenshot , `${ downloadUrl } ?download=1` )
129
+ }
130
+ >
131
+ { t ( 'View screenshot' ) }
132
+ </ Button >
133
+ < DropdownMenu
134
+ position = "bottom"
135
+ offset = { 4 }
136
+ triggerProps = { {
137
+ showChevron : false ,
138
+ icon : < IconEllipsis /> ,
139
+ 'aria-label' : t ( 'More screenshot actions' ) ,
140
+ } }
98
141
size = "xs"
99
- />
100
- </ StyledPanelHeader >
101
- ) }
102
- < StyledPanelBody hasHeader = { totalScreenshots > 1 } >
103
- { loadingImage && (
104
- < StyledLoadingIndicator >
105
- < LoadingIndicator mini />
106
- </ StyledLoadingIndicator >
107
- ) }
108
- < AttachmentComponentWrapper
109
- onClick = { ( ) =>
110
- openVisualizationModal ( screenshot , `${ downloadUrl } ?download=1` )
111
- }
112
- >
113
- < AttachmentComponent
114
- orgSlug = { organization . slug }
115
- projectSlug = { projectSlug }
116
- eventId = { eventId }
117
- attachment = { screenshot }
118
- onLoad = { ( ) => setLoadingImage ( false ) }
119
- onError = { ( ) => setLoadingImage ( false ) }
120
- controls = { false }
121
- onCanPlay = { ( ) => setLoadingImage ( false ) }
122
- />
123
- </ AttachmentComponentWrapper >
124
- </ StyledPanelBody >
125
- { ! onlyRenderScreenshot && (
126
- < StyledPanelFooter >
127
- < ButtonBar gap = { 1 } >
128
- < Button
129
- size = "xs"
130
- onClick = { ( ) =>
131
- openVisualizationModal (
132
- screenshotAttachment ,
133
- `${ downloadUrl } ?download=1`
134
- )
135
- }
136
- >
137
- { t ( 'View screenshot' ) }
138
- </ Button >
139
- < DropdownMenu
140
- position = "bottom"
141
- offset = { 4 }
142
- triggerProps = { {
143
- showChevron : false ,
144
- icon : < IconEllipsis /> ,
145
- 'aria-label' : t ( 'More screenshot actions' ) ,
146
- } }
147
- size = "xs"
148
- items = { [
149
- {
150
- key : 'download' ,
151
- label : t ( 'Download' ) ,
152
- onAction : ( ) => {
153
- window . location . assign ( `${ downloadUrl } ?download=1` ) ;
154
- trackAnalytics (
155
- 'issue_details.issue_tab.screenshot_dropdown_download' ,
156
- { organization}
157
- ) ;
158
- } ,
159
- } ,
160
- {
161
- key : 'delete' ,
162
- label : t ( 'Delete' ) ,
163
- onAction : ( ) =>
164
- openConfirmModal ( {
165
- header : t ( 'Delete this image?' ) ,
166
- message : t (
167
- 'This image was captured around the time that the event occurred. Are you sure you want to delete this image?'
168
- ) ,
169
- onConfirm : ( ) => handleDelete ( screenshotAttachment . id ) ,
170
- } ) ,
142
+ items = { [
143
+ {
144
+ key : 'download' ,
145
+ label : t ( 'Download' ) ,
146
+ onAction : ( ) => {
147
+ window . location . assign ( `${ downloadUrl } ?download=1` ) ;
148
+ trackAnalytics (
149
+ 'issue_details.issue_tab.screenshot_dropdown_download' ,
150
+ { organization}
151
+ ) ;
171
152
} ,
172
- ] }
173
- />
174
- </ ButtonBar >
175
- </ StyledPanelFooter >
176
- ) }
177
- </ Fragment >
178
- ) ;
179
- }
180
-
181
- return < StyledPanel > { renderContent ( screenshot ) } </ StyledPanel > ;
153
+ } ,
154
+ {
155
+ key : 'delete' ,
156
+ label : t ( 'Delete' ) ,
157
+ onAction : ( ) =>
158
+ openConfirmModal ( {
159
+ header : t ( 'Delete this image?' ) ,
160
+ message : t (
161
+ 'This image was captured around the time that the event occurred. Are you sure you want to delete this image?'
162
+ ) ,
163
+ onConfirm : ( ) => handleDelete ( screenshot . id ) ,
164
+ } ) ,
165
+ } ,
166
+ ] }
167
+ />
168
+ </ ButtonBar >
169
+ </ StyledPanelFooter >
170
+ ) }
171
+ </ StyledPanel >
172
+ ) ;
182
173
}
183
174
184
175
export default Screenshot ;
0 commit comments