utils.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import type {Organization} from 'sentry/types/organization';
  2. import type {TraceResult} from '../../hooks/useTraces';
  3. import type {SpanResult} from '../../hooks/useTraceSpans';
  4. import type {Field} from './data';
  5. export function normalizeTraces(traces: TraceResult[] | undefined) {
  6. if (!traces) {
  7. return traces;
  8. }
  9. return traces.sort(
  10. // Only sort name == null to the end, the rest leave in the original order.
  11. (t1, t2) => (t1.name ? '0' : '1').localeCompare(t2.name ? '0' : '1')
  12. );
  13. }
  14. export function getStylingSliceName(
  15. sliceName: string | null,
  16. sliceSecondaryName: string | null
  17. ) {
  18. if (sliceSecondaryName) {
  19. // Our color picking relies on the first 4 letters. Since we want to differentiate sdknames and project names we have to include part of the sdk name.
  20. return (sliceName ?? '').slice(0, 1) + sliceSecondaryName.slice(-4);
  21. }
  22. return sliceName;
  23. }
  24. export function areQueriesEmpty(queries: string[]): boolean {
  25. if (queries.length > 1) {
  26. return false;
  27. }
  28. if (queries.length === 0) {
  29. return true;
  30. }
  31. if (queries.length === 1) {
  32. return queries[0].length === 0;
  33. }
  34. return false;
  35. }
  36. export function getSecondaryNameFromSpan(span: SpanResult<Field>) {
  37. return span['sdk.name'];
  38. }
  39. export function generateTracesRoute({orgSlug}: {orgSlug: Organization['slug']}): string {
  40. return `/organizations/${orgSlug}/traces/`;
  41. }
  42. export function getShortenedSdkName(sdkName: string | null) {
  43. if (!sdkName) {
  44. return '';
  45. }
  46. const sdkNameParts = sdkName.split('.');
  47. if (sdkNameParts.length <= 1) {
  48. return sdkName;
  49. }
  50. return sdkNameParts[sdkNameParts.length - 1];
  51. }