useTopEvents.tsx 981 B

12345678910111213141516171819202122232425262728293031
  1. import {useMemo} from 'react';
  2. import {useGroupBys} from './useGroupBys';
  3. import {useResultMode} from './useResultsMode';
  4. import {useVisualizes} from './useVisualizes';
  5. export const TOP_EVENTS_LIMIT: number = 5;
  6. export function useTopEvents(): number | undefined {
  7. const [visualizes] = useVisualizes();
  8. const {groupBys} = useGroupBys();
  9. const [resultMode] = useResultMode();
  10. const hasChartWithMultipleYaxes = useMemo(() => {
  11. return visualizes.some(visualize => visualize.yAxes.length > 1);
  12. }, [visualizes]);
  13. const topEvents: number | undefined = useMemo(() => {
  14. if (resultMode === 'samples') {
  15. return undefined;
  16. }
  17. // We only support top events for when there are no multiple y-axes chart
  18. // and there is at least one group by.
  19. return hasChartWithMultipleYaxes || (groupBys.length === 1 && groupBys[0] === '')
  20. ? undefined
  21. : TOP_EVENTS_LIMIT;
  22. }, [hasChartWithMultipleYaxes, groupBys, resultMode]);
  23. return topEvents;
  24. }