fullSpanDescription.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {CodeSnippet} from 'sentry/components/codeSnippet';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import {space} from 'sentry/styles/space';
  6. import {useFullSpanFromTrace} from 'sentry/views/starfish/queries/useFullSpanFromTrace';
  7. import {SQLishFormatter} from 'sentry/views/starfish/utils/sqlish/SQLishFormatter';
  8. const formatter = new SQLishFormatter();
  9. export function FullSpanDescription({group, shortDescription, language}: Props) {
  10. const {
  11. data: fullSpan,
  12. isLoading,
  13. isFetching,
  14. } = useFullSpanFromTrace(group, Boolean(group));
  15. const description = fullSpan?.description ?? shortDescription;
  16. if (!description) {
  17. return null;
  18. }
  19. if (isLoading && isFetching) {
  20. return (
  21. <PaddedSpinner>
  22. <LoadingIndicator mini hideMessage relative />
  23. </PaddedSpinner>
  24. );
  25. }
  26. if (language === 'sql') {
  27. return (
  28. <CodeSnippet language={language}>
  29. {formatter.toString(description, {maxLineLength: LINE_LENGTH})}
  30. </CodeSnippet>
  31. );
  32. }
  33. if (language) {
  34. return <CodeSnippet language={language}>{description}</CodeSnippet>;
  35. }
  36. return <Fragment>{description}</Fragment>;
  37. }
  38. interface Props {
  39. group?: string;
  40. language?: 'sql' | 'http';
  41. shortDescription?: string;
  42. }
  43. const LINE_LENGTH = 60;
  44. const PaddedSpinner = styled('div')`
  45. padding: ${space(0)} ${space(0.5)};
  46. `;