domainCell.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {Link} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import * as qs from 'query-string';
  4. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  5. import {space} from 'sentry/styles/space';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import useProjects from 'sentry/utils/useProjects';
  9. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  10. import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
  11. interface Props {
  12. domain?: string;
  13. projectId?: string;
  14. }
  15. export function DomainCell({projectId, domain}: Props) {
  16. const location = useLocation();
  17. const organization = useOrganization();
  18. const {projects} = useProjects();
  19. // NOTE: This is for safety only, the product should not fetch or render rows with missing domains or project IDs
  20. if (!domain) {
  21. return NULL_DESCRIPTION;
  22. }
  23. const project = projects.find(p => projectId === p.id);
  24. const queryString = {
  25. ...location.query,
  26. domain,
  27. };
  28. return (
  29. <DomainDescription>
  30. {project && <ProjectAvatar project={project} />}
  31. <OverflowEllipsisTextContainer>
  32. <Link
  33. to={normalizeUrl(
  34. `/organizations/${organization.slug}/performance/http/domains/?${qs.stringify(queryString)}`
  35. )}
  36. >
  37. {domain}
  38. </Link>
  39. </OverflowEllipsisTextContainer>
  40. </DomainDescription>
  41. );
  42. }
  43. const DomainDescription = styled('div')`
  44. display: flex;
  45. flex-wrap: nowrap;
  46. gap: ${space(1)};
  47. align-items: center;
  48. `;
  49. const NULL_DESCRIPTION = <span>&lt;null&gt;</span>;