deployBadge.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import Link from 'sentry/components/links/link';
  2. import Tag from 'sentry/components/tag';
  3. import {IconOpen} from 'sentry/icons';
  4. import {t} from 'sentry/locale';
  5. import {Deploy} from 'sentry/types';
  6. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  7. type Props = {
  8. deploy: Deploy;
  9. className?: string;
  10. orgSlug?: string;
  11. projectId?: number;
  12. version?: string;
  13. };
  14. const DeployBadge = ({deploy, orgSlug, projectId, version, className}: Props) => {
  15. const shouldLinkToIssues = !!orgSlug && !!version;
  16. const badge = (
  17. <Tag
  18. className={className}
  19. type="highlight"
  20. icon={shouldLinkToIssues && <IconOpen data-test-id="deploy-open-icon" />}
  21. textMaxWidth={80}
  22. tooltipText={shouldLinkToIssues ? t('Open In Issues') : undefined}
  23. >
  24. {deploy.environment}
  25. </Tag>
  26. );
  27. if (!shouldLinkToIssues) {
  28. return badge;
  29. }
  30. return (
  31. <Link
  32. to={{
  33. pathname: `/organizations/${orgSlug}/issues/`,
  34. query: {
  35. project: projectId ?? null,
  36. environment: deploy.environment,
  37. query: new MutableSearch([`release:${version!}`]).formatString(),
  38. },
  39. }}
  40. >
  41. {badge}
  42. </Link>
  43. );
  44. };
  45. export default DeployBadge;