samplingFromOtherProject.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import styled from '@emotion/styled';
  2. import Alert from 'sentry/components/alert';
  3. import Button from 'sentry/components/button';
  4. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  5. import {t, tn} from 'sentry/locale';
  6. import space from 'sentry/styles/space';
  7. import {Organization, Project} from 'sentry/types';
  8. import useProjects from 'sentry/utils/useProjects';
  9. import {useDistribution} from './utils/useDistribution';
  10. import {SERVER_SIDE_SAMPLING_DOC_LINK} from './utils';
  11. type Props = {
  12. orgSlug: Organization['slug'];
  13. projectSlug: Project['slug'];
  14. };
  15. export function SamplingFromOtherProject({orgSlug, projectSlug}: Props) {
  16. const {distribution, loading} = useDistribution();
  17. const {projects} = useProjects({
  18. slugs: distribution?.parentProjectBreakdown?.map(({project}) => project) ?? [],
  19. orgId: orgSlug,
  20. });
  21. const otherProjects = projects.filter(project => project.slug !== projectSlug);
  22. if (loading || otherProjects.length === 0) {
  23. return null;
  24. }
  25. return (
  26. <Alert
  27. type="info"
  28. showIcon
  29. trailingItems={
  30. <Button
  31. href={`${SERVER_SIDE_SAMPLING_DOC_LINK}#traces--propagation-of-sampling-decisions`}
  32. priority="link"
  33. borderless
  34. external
  35. >
  36. {t('Learn More')}
  37. </Button>
  38. }
  39. >
  40. {tn(
  41. 'The following project made sampling decisions for this project. You might want to set up rules there.',
  42. 'The following projects made sampling decisions for this project. You might want to set up rules there.',
  43. otherProjects.length
  44. )}
  45. <Projects>
  46. {otherProjects.map(project => (
  47. <ProjectBadge
  48. key={project.slug}
  49. project={project}
  50. avatarSize={16}
  51. to={`/settings/${orgSlug}/projects/${project.slug}/dynamic-sampling/`}
  52. />
  53. ))}
  54. </Projects>
  55. </Alert>
  56. );
  57. }
  58. const Projects = styled('div')`
  59. display: flex;
  60. flex-wrap: wrap;
  61. gap: ${space(1.5)};
  62. justify-content: flex-start;
  63. align-items: center;
  64. margin-top: ${space(1)};
  65. `;