newTraceDetailsValueRenderer.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. return <ObjectView obj={value} />;
  31. }
  32. return <span>{JSON.stringify(value, null, 4)}</span>;
  33. }
  34. const ListContainer = styled('ul')`
  35. display: flex;
  36. flex-direction: column;
  37. gap: ${space(1)};
  38. padding: 0;
  39. margin-left: ${space(1)};
  40. list-style-type: '-';
  41. flex-grow: 1;
  42. flex-basis: full;
  43. `;
  44. const ObjectContainer = styled('div')`
  45. display: flex;
  46. flex-direction: column;
  47. gap: ${space(1)};
  48. margin-left: ${space(1)};
  49. flex-grow: 1;
  50. flex-basis: full;
  51. `;