eventTitleTreeLabel.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import space from 'sentry/styles/space';
  4. import {TreeLabelPart} from 'sentry/types';
  5. import {getTreeLabelPartDetails} from 'sentry/utils/events';
  6. type Props = {
  7. treeLabel: TreeLabelPart[];
  8. };
  9. function EventTitleTreeLabel({treeLabel}: Props) {
  10. const firstFourParts = treeLabel.slice(0, 4);
  11. const remainingParts = treeLabel.slice(firstFourParts.length);
  12. return (
  13. <Wrapper>
  14. <FirstFourParts>
  15. {firstFourParts.map((part, index) => {
  16. const label = getTreeLabelPartDetails(part);
  17. if (index !== firstFourParts.length - 1) {
  18. return (
  19. <Fragment key={index}>
  20. <PriorityLabel>{label}</PriorityLabel>
  21. <Divider>{'|'}</Divider>
  22. </Fragment>
  23. );
  24. }
  25. return <PriorityLabel key={index}>{label}</PriorityLabel>;
  26. })}
  27. </FirstFourParts>
  28. {!!remainingParts.length && (
  29. <RemainingLabels>
  30. {remainingParts.map((part, index) => {
  31. const label = getTreeLabelPartDetails(part);
  32. return (
  33. <Fragment key={index}>
  34. <Divider>{'|'}</Divider>
  35. <Label>{label}</Label>
  36. </Fragment>
  37. );
  38. })}
  39. </RemainingLabels>
  40. )}
  41. </Wrapper>
  42. );
  43. }
  44. export default EventTitleTreeLabel;
  45. const Wrapper = styled('div')`
  46. display: inline-grid;
  47. grid-template-columns: auto 1fr;
  48. align-items: center;
  49. `;
  50. const FirstFourParts = styled('div')`
  51. display: inline-grid;
  52. grid-auto-flow: column;
  53. align-items: center;
  54. `;
  55. const Label = styled('div')`
  56. display: inline-block;
  57. `;
  58. const PriorityLabel = styled(Label)`
  59. ${p => p.theme.overflowEllipsis}
  60. display: inline-block;
  61. `;
  62. const RemainingLabels = styled('div')`
  63. ${p => p.theme.overflowEllipsis}
  64. display: inline-block;
  65. min-width: 50px;
  66. `;
  67. export const Divider = styled('div')`
  68. color: ${p => p.theme.gray200};
  69. display: inline-block;
  70. padding: 0 ${space(1)};
  71. `;