jsonViewer.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import styled from '@emotion/styled';
  2. import AsyncComponent from 'sentry/components/asyncComponent';
  3. import ContextData from 'sentry/components/contextData';
  4. import PreviewPanelItem from 'sentry/components/events/attachmentViewers/previewPanelItem';
  5. import {
  6. getAttachmentUrl,
  7. ViewerProps,
  8. } from 'sentry/components/events/attachmentViewers/utils';
  9. type Props = ViewerProps & AsyncComponent['props'];
  10. type State = AsyncComponent['state'];
  11. export default class JsonViewer extends AsyncComponent<Props, State> {
  12. getEndpoints(): [string, string][] {
  13. return [['attachmentJson', getAttachmentUrl(this.props)]];
  14. }
  15. renderBody() {
  16. const {attachmentJson} = this.state;
  17. if (!attachmentJson) {
  18. return null;
  19. }
  20. let json;
  21. try {
  22. json = JSON.parse(attachmentJson);
  23. } catch (e) {
  24. json = null;
  25. }
  26. return (
  27. <PreviewPanelItem>
  28. <StyledContextData
  29. data={json}
  30. maxDefaultDepth={4}
  31. preserveQuotes
  32. style={{width: '100%'}}
  33. jsonConsts
  34. />
  35. </PreviewPanelItem>
  36. );
  37. }
  38. }
  39. const StyledContextData = styled(ContextData)`
  40. margin-bottom: 0;
  41. `;