openAIFixSuggestionButton.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {useCallback} from 'react';
  2. import ActionButton from 'sentry/components/actions/button';
  3. import FeatureBadge from 'sentry/components/featureBadge';
  4. import {t} from 'sentry/locale';
  5. import {Group} from 'sentry/types';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. import useRouter from 'sentry/utils/useRouter';
  8. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  9. import {experimentalFeatureTooltipDesc} from 'sentry/views/issueDetails/openAIFixSuggestion/utils';
  10. type Props = {
  11. activeSuperUser: boolean;
  12. groupId: Group['id'];
  13. onClick: () => void;
  14. className?: string;
  15. disabled?: boolean;
  16. size?: 'xs' | 'sm';
  17. };
  18. export function OpenAIFixSuggestionButton({
  19. className,
  20. disabled,
  21. size,
  22. onClick,
  23. groupId,
  24. activeSuperUser,
  25. }: Props) {
  26. const organization = useOrganization();
  27. const router = useRouter();
  28. const groupLink = normalizeUrl(
  29. `/organizations/${organization.slug}/issues/${groupId}/`
  30. );
  31. const handleShowAISuggestion = useCallback(() => {
  32. onClick();
  33. router.push({
  34. pathname: groupLink,
  35. query: {...router.location.query, showSuggestedFix: true},
  36. });
  37. }, [router, groupLink, onClick]);
  38. if (!organization.features.includes('open-ai-suggestion')) {
  39. return null;
  40. }
  41. return (
  42. <ActionButton
  43. className={className}
  44. disabled={activeSuperUser || disabled}
  45. title={
  46. activeSuperUser ? (
  47. t("Superusers can't consent to policies")
  48. ) : (
  49. <div>
  50. {experimentalFeatureTooltipDesc}
  51. <FeatureBadge type="experimental" noTooltip />
  52. </div>
  53. )
  54. }
  55. size={size}
  56. onClick={handleShowAISuggestion}
  57. >
  58. {t('Suggested Fix')}
  59. </ActionButton>
  60. );
  61. }