contextSummaryGeneric.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import styled from '@emotion/styled';
  2. import AnnotatedText from 'sentry/components/events/meta/annotatedText';
  3. import {getMeta} from 'sentry/components/events/meta/metaProxy';
  4. import TextOverflow from 'sentry/components/textOverflow';
  5. import {t} from 'sentry/locale';
  6. import space from 'sentry/styles/space';
  7. import ContextSummaryNoSummary from './contextSummaryNoSummary';
  8. import generateClassName from './generateClassName';
  9. import Item from './item';
  10. type Props = {
  11. data: Data;
  12. unknownTitle: string;
  13. omitUnknownVersion?: boolean;
  14. };
  15. type Data = {
  16. name: string;
  17. version?: string;
  18. };
  19. const ContextSummaryGeneric = ({
  20. data,
  21. unknownTitle,
  22. omitUnknownVersion = false,
  23. }: Props) => {
  24. if (Object.keys(data).length === 0) {
  25. return <ContextSummaryNoSummary title={unknownTitle} />;
  26. }
  27. const renderValue = (key: keyof Data) => {
  28. const meta = getMeta(data, key);
  29. return <AnnotatedText value={data[key]} meta={meta} />;
  30. };
  31. const className = generateClassName(data.name, data.version);
  32. return (
  33. <Item className={className} icon={<span className="context-item-icon" />}>
  34. <h3>{renderValue('name')}</h3>
  35. {(data.version || !omitUnknownVersion) && (
  36. <TextOverflow isParagraph>
  37. <Subject>{t('Version:')}</Subject>
  38. {!data.version ? t('Unknown') : renderValue('version')}
  39. </TextOverflow>
  40. )}
  41. </Item>
  42. );
  43. };
  44. export default ContextSummaryGeneric;
  45. const Subject = styled('strong')`
  46. margin-right: ${space(0.5)};
  47. `;