renderGroupingInfo.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {t} from 'sentry/locale';
  2. import {EventGroupComponent, EventGroupInfo, EventGroupVariant} from 'sentry/types';
  3. function renderGroupingInfo(groupingInfo: EventGroupInfo): string[] {
  4. return Object.values(groupingInfo).map(renderGroupVariant).flat();
  5. }
  6. function renderGroupVariant(variant: EventGroupVariant): string[] {
  7. const title = [t('Type: %s', variant.type)];
  8. if (variant.hash) {
  9. title.push(t('Hash: %s', variant.hash));
  10. }
  11. if (variant.description) {
  12. title.push(t('Description: %s', variant.description));
  13. }
  14. const rv = [title.join('\n')];
  15. if ('component' in variant && variant.component) {
  16. rv.push(renderComponent(variant.component).join('\n'));
  17. }
  18. return rv;
  19. }
  20. function renderComponent(component: EventGroupComponent): string[] {
  21. if (!component.contributes) {
  22. return [];
  23. }
  24. const {name, id, hint} = component;
  25. const name_or_id = name || id;
  26. const title = name_or_id && hint ? `${name_or_id} (${hint})` : name_or_id;
  27. const rv = title ? [title] : [];
  28. if (component.values) {
  29. for (const value of component.values) {
  30. if (typeof value === 'string') {
  31. rv.push(` ${value}`);
  32. continue;
  33. }
  34. for (const line of renderComponent(value)) {
  35. rv.push(` ${line}`);
  36. }
  37. }
  38. }
  39. return rv;
  40. }
  41. export default renderGroupingInfo;