Skip to content
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(issue-details): Add universal copy hotkey #87325

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion static/app/components/events/autofix/autofixSolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export function formatSolutionText(

parts.push(
solution
.filter(event => event.is_active)
.map(event => {
const eventParts = [`### ${event.title}`];

Expand Down Expand Up @@ -430,7 +431,14 @@ function CopySolutionButton({
return null;
}
const text = formatSolutionText(solution, customSolution);
return <CopyToClipboardButton size="sm" text={text} borderless />;
return (
<CopyToClipboardButton
size="sm"
text={text}
borderless
title="Copy solution as Markdown"
/>
);
}

function AutofixSolutionDisplay({
Expand Down
129 changes: 129 additions & 0 deletions static/app/components/events/autofix/utils.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,130 @@
import {formatRootCauseText} from 'sentry/components/events/autofix/autofixRootCause';
import {formatSolutionText} from 'sentry/components/events/autofix/autofixSolution';
import {
type AutofixChangesStep,
type AutofixCodebaseChange,
type AutofixData,
AutofixStatus,
AutofixStepType,
} from 'sentry/components/events/autofix/types';

export const AUTOFIX_ROOT_CAUSE_STEP_ID = 'root_cause_analysis';

export function getRootCauseDescription(autofixData: AutofixData) {
const rootCause = autofixData.steps?.find(
step => step.type === AutofixStepType.ROOT_CAUSE_ANALYSIS
);
if (!rootCause) {
return null;
}
return rootCause.causes.at(0)?.description ?? null;
}

export function getRootCauseCopyText(autofixData: AutofixData) {
const rootCause = autofixData.steps?.find(
step => step.type === AutofixStepType.ROOT_CAUSE_ANALYSIS
);
if (!rootCause) {
return null;
}

const cause = rootCause.causes.at(0);

if (!cause) {
return null;
}

return formatRootCauseText(cause);
}

export function getSolutionDescription(autofixData: AutofixData) {
const solution = autofixData.steps?.find(
step => step.type === AutofixStepType.SOLUTION
);
if (!solution) {
return null;
}

return solution.description ?? null;
}

export function getSolutionCopyText(autofixData: AutofixData) {
const solution = autofixData.steps?.find(
step => step.type === AutofixStepType.SOLUTION
);
if (!solution) {
return null;
}

return formatSolutionText(solution.solution, solution.custom_solution);
}

export function getSolutionIsLoading(autofixData: AutofixData) {
const solutionProgressStep = autofixData.steps?.find(
step => step.key === 'solution_processing'
);
return solutionProgressStep?.status === AutofixStatus.PROCESSING;
}

export function getCodeChangesDescription(autofixData: AutofixData) {
if (!autofixData) {
return null;
}

const changesStep = autofixData.steps?.find(
step => step.type === AutofixStepType.CHANGES
) as AutofixChangesStep | undefined;

if (!changesStep) {
return null;
}

// If there are changes with PRs, show links to them
const changesWithPRs = changesStep.changes?.filter(
(change: AutofixCodebaseChange) => change.pull_request
);
if (changesWithPRs?.length) {
return changesWithPRs
.map(
(change: AutofixCodebaseChange) =>
`[View PR in ${change.repo_name}](${change.pull_request?.pr_url})`
)
.join('\n');
}

// If there are code changes but no PRs yet, show a summary
if (changesStep.changes?.length) {
// Group changes by repo
const changesByRepo: Record<string, number> = {};
changesStep.changes.forEach((change: AutofixCodebaseChange) => {
changesByRepo[change.repo_name] = (changesByRepo[change.repo_name] || 0) + 1;
});

const changesSummary = Object.entries(changesByRepo)
.map(([repo, count]) => `${count} ${count === 1 ? 'change' : 'changes'} in ${repo}`)
.join(', ');

return `Proposed ${changesSummary}.`;
}

return null;
}

export const getCodeChangesIsLoading = (autofixData: AutofixData) => {
if (!autofixData) {
return false;
}

// Check if there's a specific changes processing step, similar to solution_processing
const changesProgressStep = autofixData.steps?.find(step => step.key === 'plan');
if (changesProgressStep?.status === AutofixStatus.PROCESSING) {
return true;
}

// Also check if the changes step itself is in processing state
const changesStep = autofixData.steps?.find(
step => step.type === AutofixStepType.CHANGES
);

return changesStep?.status === AutofixStatus.PROCESSING;
};
25 changes: 24 additions & 1 deletion static/app/components/group/groupSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const POSSIBLE_CAUSE_CONFIDENCE_THRESHOLD = 0.468;
const POSSIBLE_CAUSE_NOVELTY_THRESHOLD = 0.419;
// These thresholds were used when embedding the cause and computing simliarities.

interface GroupSummaryData {
export interface GroupSummaryData {
groupId: string;
headline: string;
eventId?: string | null;
Expand Down Expand Up @@ -50,6 +50,29 @@ export const makeGroupSummaryQueryKey = (
},
];

/**
* Gets the data for group summary if it exists but doesn't fetch it.
*/
export function useGroupSummaryData(
group: Group,
event: Event | null | undefined,
forceEvent = false
) {
const organization = useOrganization();
const queryKey = makeGroupSummaryQueryKey(
organization.slug,
group.id,
forceEvent ? event?.id : undefined
);

const {data, isPending} = useApiQuery<GroupSummaryData>(queryKey, {
staleTime: Infinity,
enabled: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should stop it. Query can still run if refetch is used anywhere, but I think we're good?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally... it doesn't call it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to check my understanding - this is being used to get the group summary if it exists already, but won't create a new summary if one doesn't exist (so we don't need any checks around it)

Copy link
Member Author

@jennmueng jennmueng Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that is the intent and my understanding of how this hook works, other than just not rendering that hook, if we disable it via a check it'll be passing a false to enabled anyways, but this is always false

});

return {data, isPending};
}

export function useGroupSummary(
group: Group,
event: Event | null | undefined,
Expand Down
137 changes: 9 additions & 128 deletions static/app/components/group/groupSummaryWithAutofix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import styled from '@emotion/styled';
import {motion} from 'framer-motion';

import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
import {formatRootCauseText} from 'sentry/components/events/autofix/autofixRootCause';
import {formatSolutionText} from 'sentry/components/events/autofix/autofixSolution';
import {
type AutofixChangesStep,
type AutofixCodebaseChange,
type AutofixData,
AutofixStatus,
} from 'sentry/components/events/autofix/types';
import {AutofixStepType} from 'sentry/components/events/autofix/types';
import {useAutofixData} from 'sentry/components/events/autofix/useAutofix';
import {
getCodeChangesDescription,
getCodeChangesIsLoading,
getRootCauseCopyText,
getRootCauseDescription,
getSolutionCopyText,
getSolutionDescription,
getSolutionIsLoading,
} from 'sentry/components/events/autofix/utils';
import {GroupSummary} from 'sentry/components/group/groupSummary';
import Placeholder from 'sentry/components/placeholder';
import {IconCode, IconFix, IconFocus} from 'sentry/icons';
Expand Down Expand Up @@ -49,125 +49,6 @@ interface InsightCardObject {
onClick?: () => void;
}

const getRootCauseDescription = (autofixData: AutofixData) => {
const rootCause = autofixData.steps?.find(
step => step.type === AutofixStepType.ROOT_CAUSE_ANALYSIS
);
if (!rootCause) {
return null;
}
return rootCause.causes.at(0)?.description ?? null;
};

const getRootCauseCopyText = (autofixData: AutofixData) => {
const rootCause = autofixData.steps?.find(
step => step.type === AutofixStepType.ROOT_CAUSE_ANALYSIS
);
if (!rootCause) {
return null;
}

const cause = rootCause.causes.at(0);

if (!cause) {
return null;
}

return formatRootCauseText(cause);
};

const getSolutionDescription = (autofixData: AutofixData) => {
const solution = autofixData.steps?.find(
step => step.type === AutofixStepType.SOLUTION
);
if (!solution) {
return null;
}

return solution.description ?? null;
};

const getSolutionCopyText = (autofixData: AutofixData) => {
const solution = autofixData.steps?.find(
step => step.type === AutofixStepType.SOLUTION
);
if (!solution) {
return null;
}

return formatSolutionText(solution.solution, solution.custom_solution);
};

const getSolutionIsLoading = (autofixData: AutofixData) => {
const solutionProgressStep = autofixData.steps?.find(
step => step.key === 'solution_processing'
);
return solutionProgressStep?.status === AutofixStatus.PROCESSING;
};

const getCodeChangesDescription = (autofixData: AutofixData) => {
if (!autofixData) {
return null;
}

const changesStep = autofixData.steps?.find(
step => step.type === AutofixStepType.CHANGES
) as AutofixChangesStep | undefined;

if (!changesStep) {
return null;
}

// If there are changes with PRs, show links to them
const changesWithPRs = changesStep.changes?.filter(
(change: AutofixCodebaseChange) => change.pull_request
);
if (changesWithPRs?.length) {
return changesWithPRs
.map(
(change: AutofixCodebaseChange) =>
`[View PR in ${change.repo_name}](${change.pull_request?.pr_url})`
)
.join('\n');
}

// If there are code changes but no PRs yet, show a summary
if (changesStep.changes?.length) {
// Group changes by repo
const changesByRepo: Record<string, number> = {};
changesStep.changes.forEach((change: AutofixCodebaseChange) => {
changesByRepo[change.repo_name] = (changesByRepo[change.repo_name] || 0) + 1;
});

const changesSummary = Object.entries(changesByRepo)
.map(([repo, count]) => `${count} ${count === 1 ? 'change' : 'changes'} in ${repo}`)
.join(', ');

return `Proposed ${changesSummary}.`;
}

return null;
};

const getCodeChangesIsLoading = (autofixData: AutofixData) => {
if (!autofixData) {
return false;
}

// Check if there's a specific changes processing step, similar to solution_processing
const changesProgressStep = autofixData.steps?.find(step => step.key === 'plan');
if (changesProgressStep?.status === AutofixStatus.PROCESSING) {
return true;
}

// Also check if the changes step itself is in processing state
const changesStep = autofixData.steps?.find(
step => step.type === AutofixStepType.CHANGES
);

return changesStep?.status === AutofixStatus.PROCESSING;
};

export function GroupSummaryWithAutofix({
group,
event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import useOrganization from 'sentry/utils/useOrganization';
import {MetricIssuesSection} from 'sentry/views/issueDetails/metricIssues/metricIssuesSection';
import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
import {EventDetails} from 'sentry/views/issueDetails/streamline/eventDetails';
import {useCopyIssueDetails} from 'sentry/views/issueDetails/streamline/hooks/useCopyIssueDetails';
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection';
import {TraceDataSection} from 'sentry/views/issueDetails/traceDataSection';
import {useHasStreamlinedUI} from 'sentry/views/issueDetails/utils';
Expand Down Expand Up @@ -128,6 +129,8 @@ export function EventDetailsContent({
projectId: project.id,
});

useCopyIssueDetails(group, event);

// default to show on error or isPromptDismissed === undefined
const showFeedback = !isPromptDismissed || promptError || hasStreamlinedUI;

Expand Down
Loading
Loading