issueTrackingSignals.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import useExternalIssueDataFeedback from 'sentry/components/feedback/list/useHasLinkedIssues';
  2. import type {
  3. IntegrationComponent,
  4. PluginActionComponent,
  5. PluginIssueComponent,
  6. SentryAppIssueComponent,
  7. } from 'sentry/components/group/externalIssuesList/types';
  8. import {Tooltip} from 'sentry/components/tooltip';
  9. import {IconLink} from 'sentry/icons';
  10. import {t} from 'sentry/locale';
  11. import type {Event} from 'sentry/types/event';
  12. import type {Group} from 'sentry/types/group';
  13. import {
  14. getIntegrationDisplayName,
  15. getIntegrationIcon,
  16. } from 'sentry/utils/integrationUtil';
  17. interface Props {
  18. group: Group;
  19. }
  20. function getPluginNames(pluginIssue: PluginIssueComponent | PluginActionComponent) {
  21. return {
  22. name: pluginIssue.props.plugin.name ?? '',
  23. icon: pluginIssue.props.plugin.slug ?? '',
  24. };
  25. }
  26. function getIntegrationNames(integrationIssue: IntegrationComponent) {
  27. const icon = integrationIssue.props.externalIssue
  28. ? integrationIssue.props.externalIssue.integrationKey
  29. : '';
  30. const name = integrationIssue.props.externalIssue
  31. ? getIntegrationDisplayName(integrationIssue.props.externalIssue.integrationKey)
  32. : '';
  33. return {
  34. name,
  35. icon,
  36. };
  37. }
  38. function getAppIntegrationNames(integrationIssue: SentryAppIssueComponent) {
  39. return {
  40. name: integrationIssue.props.sentryApp.name,
  41. icon: integrationIssue.key ?? '',
  42. };
  43. }
  44. export default function IssueTrackingSignals({group}: Props) {
  45. const {linkedIssues} = useExternalIssueDataFeedback({
  46. group,
  47. event: {} as Event,
  48. project: group.project,
  49. });
  50. if (!linkedIssues.length) {
  51. return null;
  52. }
  53. if (linkedIssues.length > 1) {
  54. return (
  55. <Tooltip
  56. title={t('Linked Tickets: %d', linkedIssues.length)}
  57. containerDisplayMode="flex"
  58. >
  59. <IconLink size="xs" />
  60. </Tooltip>
  61. );
  62. }
  63. const issue = linkedIssues[0];
  64. const {name, icon} = {
  65. 'plugin-issue': getPluginNames,
  66. 'plugin-actions': getPluginNames,
  67. 'integration-issue': getIntegrationNames,
  68. 'sentry-app-issue': getAppIntegrationNames,
  69. }[issue.type](issue) ?? {name: '', icon: undefined};
  70. return (
  71. <Tooltip title={t('Linked %s Issue', name)} containerDisplayMode="flex">
  72. {getIntegrationIcon(icon, 'xs')}
  73. </Tooltip>
  74. );
  75. }