debugIdBundleDetails.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {Fragment, useMemo, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import {DateTime} from 'sentry/components/dateTime';
  5. import KeyValueList from 'sentry/components/events/interfaces/keyValueList';
  6. import Link from 'sentry/components/links/link';
  7. import {t} from 'sentry/locale';
  8. import type {KeyValueListData} from 'sentry/types/group';
  9. import type {DebugIdBundle, DebugIdBundleArtifact} from 'sentry/types/sourceMaps';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. const formatDist = (dist: string | string[] | null) => {
  12. if (Array.isArray(dist)) {
  13. return dist.join(', ');
  14. }
  15. if (dist === null) {
  16. return 'none';
  17. }
  18. return dist;
  19. };
  20. export function DebugIdBundleDetails({
  21. debugIdBundle,
  22. }: {
  23. debugIdBundle: DebugIdBundle | DebugIdBundleArtifact;
  24. }) {
  25. const [showAll, setShowAll] = useState(false);
  26. const organization = useOrganization();
  27. const detailsData = useMemo<KeyValueListData>(() => {
  28. const associations = debugIdBundle.associations;
  29. const visibleAssociations = showAll ? associations : associations.slice(0, 3);
  30. return [
  31. {
  32. key: 'count',
  33. subject: t('Artifacts'),
  34. value: debugIdBundle.fileCount,
  35. },
  36. {
  37. key: 'releases',
  38. subject: t('Associated Releases'),
  39. actionButton: associations.length > 3 && (
  40. <Button size="xs" onClick={() => setShowAll(value => !value)}>
  41. {showAll ? t('Show Less') : t('Show All')}
  42. </Button>
  43. ),
  44. value:
  45. associations.length > 0 ? (
  46. <ReleasesWrapper className="val-string-multiline">
  47. {visibleAssociations.map(association => (
  48. <Fragment key={association.release}>
  49. <Link
  50. to={`/organizations/${organization.slug}/releases/${association.release}/`}
  51. >
  52. {association.release}
  53. </Link>
  54. {` (Dist: ${formatDist(association.dist)})`}
  55. <br />
  56. </Fragment>
  57. ))}
  58. </ReleasesWrapper>
  59. ) : (
  60. t('No releases associated with this bundle')
  61. ),
  62. },
  63. {
  64. key: 'date',
  65. subject: t('Date Uploaded'),
  66. value: (
  67. <pre>
  68. <DateTime timeZone year date={debugIdBundle.date} />
  69. </pre>
  70. ),
  71. },
  72. ];
  73. }, [debugIdBundle, organization.slug, showAll]);
  74. return <StyledKeyValueList data={detailsData} shouldSort={false} />;
  75. }
  76. const ReleasesWrapper = styled('pre')`
  77. max-height: 200px;
  78. overflow-y: auto !important;
  79. `;
  80. const StyledKeyValueList = styled(KeyValueList)`
  81. && {
  82. margin-bottom: 0;
  83. }
  84. `;