1
- import React , { Fragment , useRef , useState } from 'react' ;
1
+ import React , { Fragment , useRef } from 'react' ;
2
2
import styled from '@emotion/styled' ;
3
3
import { AnimatePresence , type AnimationProps , motion } from 'framer-motion' ;
4
4
5
- import { addErrorMessage , addSuccessMessage } from 'sentry/actionCreators/indicator' ;
6
5
import ClippedBox from 'sentry/components/clippedBox' ;
7
6
import { CopyToClipboardButton } from 'sentry/components/copyToClipboardButton' ;
8
7
import { Alert } from 'sentry/components/core/alert' ;
@@ -12,22 +11,13 @@ import {AutofixHighlightWrapper} from 'sentry/components/events/autofix/autofixH
12
11
import {
13
12
type AutofixRootCauseData ,
14
13
type AutofixRootCauseSelection ,
15
- AutofixStatus ,
16
- AutofixStepType ,
17
14
type CommentThread ,
18
15
} from 'sentry/components/events/autofix/types' ;
19
- import {
20
- type AutofixResponse ,
21
- makeAutofixQueryKey ,
22
- } from 'sentry/components/events/autofix/useAutofix' ;
23
- import { IconChat , IconCheckmark , IconClose , IconFocus , IconInput } from 'sentry/icons' ;
16
+ import { IconChat , IconFocus } from 'sentry/icons' ;
24
17
import { t } from 'sentry/locale' ;
25
18
import { space } from 'sentry/styles/space' ;
26
19
import { singleLineRenderer } from 'sentry/utils/marked/marked' ;
27
- import { setApiQueryData , useMutation , useQueryClient } from 'sentry/utils/queryClient' ;
28
20
import testableTransition from 'sentry/utils/testableTransition' ;
29
- import useApi from 'sentry/utils/useApi' ;
30
- import useOrganization from 'sentry/utils/useOrganization' ;
31
21
32
22
import AutofixHighlightPopup from './autofixHighlightPopup' ;
33
23
import { AutofixTimeline } from './autofixTimeline' ;
@@ -65,89 +55,6 @@ const cardAnimationProps: AnimationProps = {
65
55
} ) ,
66
56
} ;
67
57
68
- function useSelectCause ( { groupId, runId} : { groupId : string ; runId : string } ) {
69
- const api = useApi ( ) ;
70
- const queryClient = useQueryClient ( ) ;
71
- const orgSlug = useOrganization ( ) . slug ;
72
-
73
- return useMutation ( {
74
- mutationFn : (
75
- params :
76
- | {
77
- causeId : string ;
78
- instruction ?: string ;
79
- }
80
- | {
81
- customRootCause : string ;
82
- }
83
- ) => {
84
- return api . requestPromise (
85
- `/organizations/${ orgSlug } /issues/${ groupId } /autofix/update/` ,
86
- {
87
- method : 'POST' ,
88
- data :
89
- 'customRootCause' in params
90
- ? {
91
- run_id : runId ,
92
- payload : {
93
- type : 'select_root_cause' ,
94
- custom_root_cause : params . customRootCause ,
95
- } ,
96
- }
97
- : {
98
- run_id : runId ,
99
- payload : {
100
- type : 'select_root_cause' ,
101
- cause_id : params . causeId ,
102
- instruction : params . instruction ,
103
- } ,
104
- } ,
105
- }
106
- ) ;
107
- } ,
108
- onSuccess : ( _ , params ) => {
109
- setApiQueryData < AutofixResponse > (
110
- queryClient ,
111
- makeAutofixQueryKey ( orgSlug , groupId ) ,
112
- data => {
113
- if ( ! data ?. autofix ) {
114
- return data ;
115
- }
116
-
117
- return {
118
- ...data ,
119
- autofix : {
120
- ...data . autofix ,
121
- status : AutofixStatus . PROCESSING ,
122
- steps : data . autofix . steps ?. map ( step => {
123
- if ( step . type !== AutofixStepType . ROOT_CAUSE_ANALYSIS ) {
124
- return step ;
125
- }
126
-
127
- return {
128
- ...step ,
129
- selection :
130
- 'customRootCause' in params
131
- ? {
132
- custom_root_cause : params . customRootCause ,
133
- }
134
- : {
135
- cause_id : params . causeId ,
136
- } ,
137
- } ;
138
- } ) ,
139
- } ,
140
- } ;
141
- }
142
- ) ;
143
- addSuccessMessage ( 'On it.' ) ;
144
- } ,
145
- onError : ( ) => {
146
- addErrorMessage ( t ( 'Something went wrong when selecting the root cause.' ) ) ;
147
- } ,
148
- } ) ;
149
- }
150
-
151
58
export function replaceHeadersWithBold ( markdown : string ) {
152
59
const headerRegex = / ^ ( # { 1 , 6 } ) \s + ( .* ) $ / gm;
153
60
const boldMarkdown = markdown . replace ( headerRegex , ( _match , _hashes , content ) => {
@@ -257,15 +164,10 @@ export function formatRootCauseText(
257
164
function CopyRootCauseButton ( {
258
165
cause,
259
166
customRootCause,
260
- isEditing,
261
167
} : {
262
168
cause ?: AutofixRootCauseData ;
263
169
customRootCause ?: string ;
264
- isEditing ?: boolean ;
265
170
} ) {
266
- if ( isEditing ) {
267
- return null ;
268
- }
269
171
const text = formatRootCauseText ( cause , customRootCause ) ;
270
172
return (
271
173
< CopyToClipboardButton
@@ -286,9 +188,6 @@ function AutofixRootCauseDisplay({
286
188
previousInsightCount,
287
189
agentCommentThread,
288
190
} : AutofixRootCauseProps ) {
289
- const { mutate : handleContinue , isPending} = useSelectCause ( { groupId, runId} ) ;
290
- const [ isEditing , setIsEditing ] = useState ( false ) ;
291
- const [ customRootCause , setCustomRootCause ] = useState ( '' ) ;
292
191
const cause = causes [ 0 ] ;
293
192
const iconFocusRef = useRef < HTMLDivElement > ( null ) ;
294
193
const descriptionRef = useRef < HTMLDivElement | null > ( null ) ;
@@ -324,10 +223,7 @@ function AutofixRootCauseDisplay({
324
223
</ IconWrapper >
325
224
{ t ( 'Custom Root Cause' ) }
326
225
</ HeaderText >
327
- < CopyRootCauseButton
328
- customRootCause = { rootCauseSelection . custom_root_cause }
329
- isEditing = { isEditing }
330
- />
226
+ < CopyRootCauseButton customRootCause = { rootCauseSelection . custom_root_cause } />
331
227
</ HeaderWrapper >
332
228
< CauseDescription > { rootCauseSelection . custom_root_cause } </ CauseDescription >
333
229
</ CustomRootCausePadding >
@@ -354,39 +250,7 @@ function AutofixRootCauseDisplay({
354
250
</ ChatButton >
355
251
</ HeaderText >
356
252
< ButtonBar >
357
- < CopyRootCauseButton cause = { cause } isEditing = { isEditing } />
358
- < EditButton
359
- size = "sm"
360
- borderless
361
- data-test-id = "autofix-root-cause-edit-button"
362
- title = { isEditing ? t ( 'Cancel' ) : t ( 'Propose your own root cause' ) }
363
- onClick = { ( ) => {
364
- if ( isEditing ) {
365
- setIsEditing ( false ) ;
366
- setCustomRootCause ( '' ) ;
367
- } else {
368
- setIsEditing ( true ) ;
369
- }
370
- } }
371
- >
372
- { isEditing ? < IconClose size = "sm" /> : < IconInput size = "sm" /> }
373
- </ EditButton >
374
- { isEditing && (
375
- < Button
376
- size = "sm"
377
- priority = "primary"
378
- title = { t ( 'Rethink with your new root cause' ) }
379
- data-test-id = "autofix-root-cause-save-edit-button"
380
- onClick = { ( ) => {
381
- if ( customRootCause . trim ( ) ) {
382
- handleContinue ( { customRootCause : customRootCause . trim ( ) } ) ;
383
- }
384
- } }
385
- busy = { isPending }
386
- >
387
- < IconCheckmark size = "sm" />
388
- </ Button >
389
- ) }
253
+ < CopyRootCauseButton cause = { cause } />
390
254
</ ButtonBar >
391
255
</ HeaderWrapper >
392
256
< AnimatePresence >
@@ -408,30 +272,16 @@ function AutofixRootCauseDisplay({
408
272
) }
409
273
</ AnimatePresence >
410
274
< Content >
411
- { isEditing ? (
412
- < TextArea
413
- value = { customRootCause }
414
- onChange = { e => {
415
- setCustomRootCause ( e . target . value ) ;
416
- e . target . style . height = 'auto' ;
417
- e . target . style . height = `${ e . target . scrollHeight } px` ;
418
- } }
419
- rows = { 5 }
420
- autoFocus
421
- placeholder = { t ( 'Propose your own root cause...' ) }
275
+ < Fragment >
276
+ < RootCauseDescription
277
+ cause = { cause }
278
+ groupId = { groupId }
279
+ runId = { runId }
280
+ previousDefaultStepIndex = { previousDefaultStepIndex }
281
+ previousInsightCount = { previousInsightCount }
282
+ ref = { descriptionRef }
422
283
/>
423
- ) : (
424
- < Fragment >
425
- < RootCauseDescription
426
- cause = { cause }
427
- groupId = { groupId }
428
- runId = { runId }
429
- previousDefaultStepIndex = { previousDefaultStepIndex }
430
- previousInsightCount = { previousInsightCount }
431
- ref = { descriptionRef }
432
- />
433
- </ Fragment >
434
- ) }
284
+ </ Fragment >
435
285
</ Content >
436
286
</ ClippedBox >
437
287
</ CausesContainer >
@@ -522,24 +372,6 @@ const AnimationWrapper = styled(motion.div)`
522
372
transform-origin: top center;
523
373
` ;
524
374
525
- const TextArea = styled ( 'textarea' ) `
526
- width: 100%;
527
- min-height: 150px;
528
- border: none;
529
- border-radius: ${ p => p . theme . borderRadius } ;
530
- font-size: ${ p => p . theme . fontSizeMedium } ;
531
- line-height: 1.4;
532
- resize: none;
533
- overflow: hidden;
534
- &:focus {
535
- outline: none;
536
- }
537
- ` ;
538
-
539
- const EditButton = styled ( Button ) `
540
- color: ${ p => p . theme . subText } ;
541
- ` ;
542
-
543
375
const ChatButton = styled ( Button ) `
544
376
color: ${ p => p . theme . subText } ;
545
377
margin-left: -${ space ( 0.5 ) } ;
0 commit comments