fullSpanDescription.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 {SQLishFormatter} from 'sentry/utils/sqlish/SQLishFormatter';
  7. import {useFullSpanFromTrace} from 'sentry/views/insights/common/queries/useFullSpanFromTrace';
  8. const formatter = new SQLishFormatter();
  9. export function FullSpanDescription({group, shortDescription, language, filters}: Props) {
  10. const {
  11. data: fullSpan,
  12. isLoading,
  13. isFetching,
  14. } = useFullSpanFromTrace(group, undefined, Boolean(group), filters);
  15. const description = fullSpan?.description ?? shortDescription;
  16. if (isLoading && isFetching) {
  17. return (
  18. <PaddedSpinner>
  19. <LoadingIndicator mini hideMessage relative />
  20. </PaddedSpinner>
  21. );
  22. }
  23. if (!description) {
  24. return null;
  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. filters?: Record<string, string>;
  40. group?: string;
  41. language?: 'sql' | 'http';
  42. shortDescription?: string;
  43. }
  44. const LINE_LENGTH = 60;
  45. const PaddedSpinner = styled('div')`
  46. padding: ${space(0)} ${space(0.5)};
  47. `;