resolveActions.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import ResolveActions from 'sentry/components/actions/resolve';
  2. import useProjects from 'sentry/utils/useProjects';
  3. import type {getConfirm, getLabel} from './utils';
  4. import {ConfirmAction} from './utils';
  5. type Props = {
  6. anySelected: boolean;
  7. confirm: ReturnType<typeof getConfirm>;
  8. label: ReturnType<typeof getLabel>;
  9. onShouldConfirm: (action: ConfirmAction) => boolean;
  10. onUpdate: (data?: any) => void;
  11. selectedProjectSlug: string | undefined;
  12. };
  13. function ResolveActionsContainer({
  14. anySelected,
  15. onShouldConfirm,
  16. onUpdate,
  17. selectedProjectSlug,
  18. confirm,
  19. label,
  20. }: Props) {
  21. const {initiallyLoaded, projects, fetchError} = useProjects({
  22. slugs: selectedProjectSlug ? [selectedProjectSlug] : [],
  23. });
  24. const project = selectedProjectSlug
  25. ? projects.find(p => p.slug === selectedProjectSlug)
  26. : null;
  27. const hasRelease =
  28. project && 'features' in project ? project.features.includes('releases') : false;
  29. const latestRelease =
  30. project && 'latestRelease' in project ? project.latestRelease : undefined;
  31. // resolve requires a single project to be active in an org context
  32. // projectId is null when 0 or >1 projects are selected.
  33. const resolveDisabled = Boolean(!anySelected || fetchError);
  34. const resolveDropdownDisabled = Boolean(
  35. !anySelected || !project?.slug || !initiallyLoaded || fetchError
  36. );
  37. return (
  38. <ResolveActions
  39. hasRelease={hasRelease}
  40. multipleProjectsSelected={!selectedProjectSlug}
  41. latestRelease={latestRelease}
  42. projectSlug={project?.slug}
  43. onUpdate={onUpdate}
  44. shouldConfirm={onShouldConfirm(ConfirmAction.RESOLVE)}
  45. confirmMessage={confirm({action: ConfirmAction.RESOLVE, canBeUndone: true})}
  46. confirmLabel={label('resolve')}
  47. disabled={resolveDisabled}
  48. disableDropdown={resolveDropdownDisabled}
  49. projectFetchError={Boolean(fetchError)}
  50. />
  51. );
  52. }
  53. export default ResolveActionsContainer;