newTraceDetailsValueRenderer.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import styled from '@emotion/styled';
  2. import {space} from 'sentry/styles/space';
  3. function ObjectView({obj}: {obj: object}) {
  4. if (Array.isArray(obj)) {
  5. return (
  6. <ListContainer>
  7. {obj.map((x, i) => (
  8. <li key={'array-' + i}>
  9. <GeneralSpanDetailsValue value={x} />
  10. </li>
  11. ))}
  12. </ListContainer>
  13. );
  14. }
  15. return (
  16. <ObjectContainer>
  17. {Object.keys(obj).map(key => (
  18. <div key={key}>
  19. {key}: <GeneralSpanDetailsValue value={obj[key]} />
  20. </div>
  21. ))}
  22. </ObjectContainer>
  23. );
  24. }
  25. export function GeneralSpanDetailsValue({value}: {value: any}) {
  26. if (typeof value === 'string') {
  27. return <span>{value}</span>;
  28. }
  29. if (typeof value === 'object') {
  30. if (value === null) {
  31. return <span>null</span>;
  32. }
  33. return <ObjectView obj={value} />;
  34. }
  35. return <span>{JSON.stringify(value, null, 4)}</span>;
  36. }
  37. const ListContainer = styled('ul')`
  38. display: flex;
  39. flex-direction: column;
  40. gap: ${space(1)};
  41. padding: 0;
  42. margin-left: ${space(1)};
  43. list-style-type: '-';
  44. flex-grow: 1;
  45. flex-basis: full;
  46. `;
  47. const ObjectContainer = styled('div')`
  48. display: flex;
  49. flex-direction: column;
  50. gap: ${space(1)};
  51. margin-left: ${space(1)};
  52. flex-grow: 1;
  53. flex-basis: full;
  54. `;