rrwebJsonViewer.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import JsonViewer from 'sentry/components/events/attachmentViewers/jsonViewer';
  4. import {ViewerProps} from 'sentry/components/events/attachmentViewers/utils';
  5. import PanelAlert from 'sentry/components/panels/panelAlert';
  6. import {tct} from 'sentry/locale';
  7. type State = {
  8. showRawJson: boolean;
  9. };
  10. export default class RRWebJsonViewer extends Component<ViewerProps, State> {
  11. state: State = {
  12. showRawJson: false,
  13. };
  14. render() {
  15. const {showRawJson} = this.state;
  16. return (
  17. <Fragment>
  18. <StyledPanelAlert border={showRawJson} type="info">
  19. {tct(
  20. 'This is an attachment containing a session replay. [replayLink:View the replay] or [jsonLink:view the raw JSON].',
  21. {
  22. replayLink: <a href="#context-replay" />,
  23. jsonLink: (
  24. <a
  25. onClick={() =>
  26. this.setState(state => ({
  27. showRawJson: !state.showRawJson,
  28. }))
  29. }
  30. />
  31. ),
  32. }
  33. )}
  34. </StyledPanelAlert>
  35. {showRawJson && <JsonViewer {...this.props} />}
  36. </Fragment>
  37. );
  38. }
  39. }
  40. const StyledPanelAlert = styled(PanelAlert)<{border: boolean}>`
  41. margin: 0;
  42. border-bottom: ${p => (p.border ? `1px solid ${p.theme.border}` : null)};
  43. `;