topScreensChart.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {t} from 'sentry/locale';
  2. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  3. import useTruncatedReleaseNames from 'sentry/views/insights/mobile/common/queries/useTruncatedRelease';
  4. import {TOP_SCREENS} from 'sentry/views/insights/mobile/constants';
  5. import {ScreensBarChart} from 'sentry/views/insights/mobile/screenload/components/charts/screenBarChart';
  6. function getChartTitle(yAxis: string, countTopScreens: number) {
  7. const TITLES = {
  8. ['avg(mobile.slow_frames)']: [
  9. t('Top Screen Slow Frames'),
  10. t('Top %s Screen Slow Frames', countTopScreens),
  11. ],
  12. ['avg(mobile.frozen_frames)']: [
  13. t('Top Screen Frozen Frames'),
  14. t('Top %s Screen Frozen Frames', countTopScreens),
  15. ],
  16. ['avg(mobile.frames_delay)']: [
  17. t('Top Screen Frames Delay'),
  18. t('Top %s Screen Frames Delay', countTopScreens),
  19. ],
  20. };
  21. const [singularTopScreenTitle, pluralTopScreenTitle] = TITLES[yAxis];
  22. return countTopScreens > 1 ? pluralTopScreenTitle : singularTopScreenTitle;
  23. }
  24. export function TopScreensChart({
  25. yAxis,
  26. topTransactions,
  27. transformedReleaseEvents,
  28. chartHeight,
  29. isLoading,
  30. }) {
  31. const {primaryRelease, secondaryRelease} = useReleaseSelection();
  32. const {truncatedPrimaryRelease, truncatedSecondaryRelease} = useTruncatedReleaseNames();
  33. const countTopScreens = Math.min(TOP_SCREENS, topTransactions.length);
  34. return (
  35. <ScreensBarChart
  36. chartOptions={[
  37. {
  38. title: getChartTitle(yAxis, countTopScreens),
  39. yAxis,
  40. xAxisLabel: topTransactions,
  41. series: Object.values(transformedReleaseEvents[yAxis]),
  42. subtitle: primaryRelease
  43. ? t(
  44. '%s v. %s',
  45. truncatedPrimaryRelease,
  46. secondaryRelease ? truncatedSecondaryRelease : ''
  47. )
  48. : '',
  49. },
  50. ]}
  51. chartHeight={chartHeight}
  52. isLoading={isLoading}
  53. chartKey={`${yAxis}-screen-chart`}
  54. />
  55. );
  56. }