groupPriority.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/group';
  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. project: [group.project.id],
  42. },
  43. {
  44. success: () => {
  45. clearIndicators();
  46. onChange?.(priority);
  47. },
  48. error: () => {
  49. clearIndicators();
  50. addErrorMessage(t('Unable to update issue priority'));
  51. },
  52. }
  53. );
  54. };
  55. // We can assume that when there is not `priorityLockedAt`, there were no
  56. // user edits to the priority.
  57. const lastEditedBy = !group.priorityLockedAt ? 'system' : undefined;
  58. return (
  59. <GroupPriorityDropdown
  60. groupId={group.id}
  61. onChange={onChangePriority}
  62. value={group.priority ?? PriorityLevel.MEDIUM}
  63. lastEditedBy={lastEditedBy}
  64. />
  65. );
  66. }
  67. export default GroupPriority;