groupPriority.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {bulkUpdate} from 'sentry/actionCreators/group';
  2. import {
  3. addErrorMessage,
  4. addLoadingMessage,
  5. clearIndicators,
  6. } from 'sentry/actionCreators/indicator';
  7. import {GroupPriorityDropdown} from 'sentry/components/badge/groupPriority';
  8. import {t} from 'sentry/locale';
  9. import IssueListCacheStore from 'sentry/stores/IssueListCacheStore';
  10. import {type Group, PriorityLevel} from 'sentry/types';
  11. import {trackAnalytics} from 'sentry/utils/analytics';
  12. import {getAnalyticsDataForGroup} from 'sentry/utils/events';
  13. import useApi from 'sentry/utils/useApi';
  14. import useOrganization from 'sentry/utils/useOrganization';
  15. type GroupDetailsPriorityProps = {
  16. group: Group;
  17. onChange?: (priority: PriorityLevel) => void;
  18. };
  19. function GroupPriority({group, onChange}: GroupDetailsPriorityProps) {
  20. const api = useApi({persistInFlight: true});
  21. const organization = useOrganization();
  22. const onChangePriority = (priority: PriorityLevel) => {
  23. if (priority === group.priority) {
  24. return;
  25. }
  26. trackAnalytics('issue_details.set_priority', {
  27. organization,
  28. ...getAnalyticsDataForGroup(group),
  29. from_priority: group.priority,
  30. to_priority: priority,
  31. });
  32. addLoadingMessage(t('Saving changes\u2026'));
  33. IssueListCacheStore.reset();
  34. bulkUpdate(
  35. api,
  36. {
  37. orgId: organization.slug,
  38. itemIds: [group.id],
  39. data: {priority},
  40. failSilently: true,
  41. },
  42. {
  43. success: () => {
  44. clearIndicators();
  45. onChange?.(priority);
  46. },
  47. error: () => {
  48. clearIndicators();
  49. addErrorMessage(t('Unable to update issue priority'));
  50. },
  51. }
  52. );
  53. };
  54. // We can assume that when there is not `priorityLockedAt`, there were no
  55. // user edits to the priority.
  56. const lastEditedBy = !group.priorityLockedAt ? 'system' : undefined;
  57. return (
  58. <GroupPriorityDropdown
  59. groupId={group.id}
  60. onChange={onChangePriority}
  61. value={group.priority ?? PriorityLevel.MEDIUM}
  62. lastEditedBy={lastEditedBy}
  63. />
  64. );
  65. }
  66. export default GroupPriority;