useTopEvents.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import {useMemo} from 'react';
  2. import {
  3. useExploreGroupBys,
  4. useExploreMode,
  5. useExploreVisualizes,
  6. } from 'sentry/views/explore/contexts/pageParamsContext';
  7. import {Mode} from 'sentry/views/explore/contexts/pageParamsContext/mode';
  8. export const TOP_EVENTS_LIMIT: number = 5;
  9. export function useTopEvents(): number | undefined {
  10. const visualizes = useExploreVisualizes();
  11. const groupBys = useExploreGroupBys();
  12. const mode = useExploreMode();
  13. const hasChartWithMultipleYaxes = useMemo(() => {
  14. return visualizes.some(visualize => visualize.yAxes.length > 1);
  15. }, [visualizes]);
  16. const topEvents: number | undefined = useMemo(() => {
  17. if (mode === Mode.SAMPLES) {
  18. return undefined;
  19. }
  20. // We only support top events for when there are no multiple y-axes chart
  21. // and there is at least one group by.
  22. return hasChartWithMultipleYaxes || (groupBys.length === 1 && groupBys[0] === '')
  23. ? undefined
  24. : TOP_EVENTS_LIMIT;
  25. }, [hasChartWithMultipleYaxes, groupBys, mode]);
  26. return topEvents;
  27. }