Skip to content

Commit 8bd3dc6

Browse files
authored
chore(autofix): remove propose your own root cause (#92455)
1 parent a91fd70 commit 8bd3dc6

File tree

2 files changed

+14
-257
lines changed

2 files changed

+14
-257
lines changed

static/app/components/events/autofix/autofixRootCause.spec.tsx

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrar
55
import {AutofixRootCause} from 'sentry/components/events/autofix/autofixRootCause';
66

77
describe('AutofixRootCause', function () {
8-
let mockApi: jest.Mock<any, any, any>;
9-
108
beforeEach(function () {
11-
mockApi = MockApiClient.addMockResponse({
9+
MockApiClient.addMockResponse({
1210
url: '/organizations/org-slug/issues/1/autofix/update/',
1311
method: 'POST',
1412
body: {success: true},
@@ -86,51 +84,6 @@ describe('AutofixRootCause', function () {
8684
);
8785
});
8886

89-
it('can edit and submit custom root cause', async function () {
90-
render(<AutofixRootCause {...defaultProps} />);
91-
92-
// Wait for initial render
93-
await waitFor(
94-
() => {
95-
expect(screen.getByText('Root Cause')).toBeInTheDocument();
96-
},
97-
{timeout: 2000}
98-
);
99-
100-
// Click edit button
101-
await userEvent.click(screen.getByTestId('autofix-root-cause-edit-button'));
102-
103-
// Verify textarea appears
104-
const textarea = screen.getByPlaceholderText('Propose your own root cause...');
105-
expect(textarea).toBeInTheDocument();
106-
107-
// Enter custom root cause
108-
await userEvent.type(textarea, 'This is a custom root cause');
109-
110-
// Click Save button
111-
await userEvent.click(screen.getByTestId('autofix-root-cause-save-edit-button'));
112-
113-
// Wait for API call to complete
114-
await waitFor(
115-
() => {
116-
expect(mockApi).toHaveBeenCalledWith(
117-
'/organizations/org-slug/issues/1/autofix/update/',
118-
expect.objectContaining({
119-
method: 'POST',
120-
data: {
121-
run_id: '101',
122-
payload: {
123-
type: 'select_root_cause',
124-
custom_root_cause: 'This is a custom root cause',
125-
},
126-
},
127-
})
128-
);
129-
},
130-
{timeout: 2000}
131-
);
132-
});
133-
13487
it('shows selected root cause when rootCauseSelection is provided', async function () {
13588
const selectedCause = AutofixRootCauseData();
13689
render(
@@ -161,32 +114,4 @@ describe('AutofixRootCause', function () {
161114
{timeout: 2000}
162115
);
163116
});
164-
165-
it('shows custom root cause when rootCauseSelection has custom_root_cause', async function () {
166-
render(
167-
<AutofixRootCause
168-
{...{
169-
...defaultProps,
170-
rootCauseSelection: {
171-
custom_root_cause: 'This is a custom root cause',
172-
},
173-
}}
174-
/>
175-
);
176-
177-
// Wait for custom root cause to render
178-
await waitFor(
179-
() => {
180-
expect(screen.getByText('Custom Root Cause')).toBeInTheDocument();
181-
},
182-
{timeout: 2000}
183-
);
184-
185-
await waitFor(
186-
() => {
187-
expect(screen.getByText('This is a custom root cause')).toBeInTheDocument();
188-
},
189-
{timeout: 2000}
190-
);
191-
});
192117
});

static/app/components/events/autofix/autofixRootCause.tsx

Lines changed: 13 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, {Fragment, useRef, useState} from 'react';
1+
import React, {Fragment, useRef} from 'react';
22
import styled from '@emotion/styled';
33
import {AnimatePresence, type AnimationProps, motion} from 'framer-motion';
44

5-
import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
65
import ClippedBox from 'sentry/components/clippedBox';
76
import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
87
import {Alert} from 'sentry/components/core/alert';
@@ -12,22 +11,13 @@ import {AutofixHighlightWrapper} from 'sentry/components/events/autofix/autofixH
1211
import {
1312
type AutofixRootCauseData,
1413
type AutofixRootCauseSelection,
15-
AutofixStatus,
16-
AutofixStepType,
1714
type CommentThread,
1815
} 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';
2417
import {t} from 'sentry/locale';
2518
import {space} from 'sentry/styles/space';
2619
import {singleLineRenderer} from 'sentry/utils/marked/marked';
27-
import {setApiQueryData, useMutation, useQueryClient} from 'sentry/utils/queryClient';
2820
import testableTransition from 'sentry/utils/testableTransition';
29-
import useApi from 'sentry/utils/useApi';
30-
import useOrganization from 'sentry/utils/useOrganization';
3121

3222
import AutofixHighlightPopup from './autofixHighlightPopup';
3323
import {AutofixTimeline} from './autofixTimeline';
@@ -65,89 +55,6 @@ const cardAnimationProps: AnimationProps = {
6555
}),
6656
};
6757

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-
15158
export function replaceHeadersWithBold(markdown: string) {
15259
const headerRegex = /^(#{1,6})\s+(.*)$/gm;
15360
const boldMarkdown = markdown.replace(headerRegex, (_match, _hashes, content) => {
@@ -257,15 +164,10 @@ export function formatRootCauseText(
257164
function CopyRootCauseButton({
258165
cause,
259166
customRootCause,
260-
isEditing,
261167
}: {
262168
cause?: AutofixRootCauseData;
263169
customRootCause?: string;
264-
isEditing?: boolean;
265170
}) {
266-
if (isEditing) {
267-
return null;
268-
}
269171
const text = formatRootCauseText(cause, customRootCause);
270172
return (
271173
<CopyToClipboardButton
@@ -286,9 +188,6 @@ function AutofixRootCauseDisplay({
286188
previousInsightCount,
287189
agentCommentThread,
288190
}: AutofixRootCauseProps) {
289-
const {mutate: handleContinue, isPending} = useSelectCause({groupId, runId});
290-
const [isEditing, setIsEditing] = useState(false);
291-
const [customRootCause, setCustomRootCause] = useState('');
292191
const cause = causes[0];
293192
const iconFocusRef = useRef<HTMLDivElement>(null);
294193
const descriptionRef = useRef<HTMLDivElement | null>(null);
@@ -324,10 +223,7 @@ function AutofixRootCauseDisplay({
324223
</IconWrapper>
325224
{t('Custom Root Cause')}
326225
</HeaderText>
327-
<CopyRootCauseButton
328-
customRootCause={rootCauseSelection.custom_root_cause}
329-
isEditing={isEditing}
330-
/>
226+
<CopyRootCauseButton customRootCause={rootCauseSelection.custom_root_cause} />
331227
</HeaderWrapper>
332228
<CauseDescription>{rootCauseSelection.custom_root_cause}</CauseDescription>
333229
</CustomRootCausePadding>
@@ -354,39 +250,7 @@ function AutofixRootCauseDisplay({
354250
</ChatButton>
355251
</HeaderText>
356252
<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} />
390254
</ButtonBar>
391255
</HeaderWrapper>
392256
<AnimatePresence>
@@ -408,30 +272,16 @@ function AutofixRootCauseDisplay({
408272
)}
409273
</AnimatePresence>
410274
<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}
422283
/>
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>
435285
</Content>
436286
</ClippedBox>
437287
</CausesContainer>
@@ -522,24 +372,6 @@ const AnimationWrapper = styled(motion.div)`
522372
transform-origin: top center;
523373
`;
524374

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-
543375
const ChatButton = styled(Button)`
544376
color: ${p => p.theme.subText};
545377
margin-left: -${space(0.5)};

0 commit comments

Comments
 (0)