projectBadge.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import BadgeDisplayName from 'app/components/idBadge/badgeDisplayName';
  4. import BaseBadge from 'app/components/idBadge/baseBadge';
  5. import Link from 'app/components/links/link';
  6. import {Organization} from 'app/types';
  7. import withOrganization from 'app/utils/withOrganization';
  8. type BaseBadgeProps = React.ComponentProps<typeof BaseBadge>;
  9. type Project = NonNullable<BaseBadgeProps['project']>;
  10. type Props = Partial<Omit<BaseBadgeProps, 'project' | 'organization' | 'team'>> & {
  11. project: Project;
  12. organization?: Organization;
  13. /**
  14. * If true, will use default max-width, or specify one as a string
  15. */
  16. hideOverflow?: boolean | string;
  17. /**
  18. * If true, this component will not be a link to project details page
  19. */
  20. disableLink?: boolean;
  21. /**
  22. * Overides where the project badge links
  23. */
  24. to?: React.ComponentProps<typeof Link>['to'];
  25. };
  26. const ProjectBadge = ({
  27. project,
  28. organization,
  29. to,
  30. hideOverflow = true,
  31. disableLink = false,
  32. ...props
  33. }: Props) => {
  34. const {slug, id} = project;
  35. const badge = (
  36. <BaseBadge
  37. displayName={
  38. <BadgeDisplayName hideOverflow={hideOverflow}>{slug}</BadgeDisplayName>
  39. }
  40. project={project}
  41. {...props}
  42. />
  43. );
  44. if (!disableLink && organization?.slug) {
  45. const defaultTo = `/organizations/${organization.slug}/projects/${slug}/${
  46. id ? `?project=${id}` : ''
  47. }`;
  48. return <StyledLink to={to ?? defaultTo}>{badge}</StyledLink>;
  49. }
  50. return badge;
  51. };
  52. const StyledLink = styled(Link)`
  53. flex-shrink: 0;
  54. img:hover {
  55. cursor: pointer;
  56. }
  57. `;
  58. export default withOrganization(ProjectBadge);