Skip to content

Commit

Permalink
[GEN-2175]: optimize metrics fetching based on available sources and …
Browse files Browse the repository at this point in the history
…destinations (#2160)

This pull request includes changes to the `useMetrics` hook in the
`frontend/webapp/hooks/overview/useMetrics.ts` file to improve its
functionality by ensuring that metrics are only fetched when there are
sources or destinations available.

Improvements to `useMetrics` hook:

*
[`frontend/webapp/hooks/overview/useMetrics.ts`](diffhunk://#diff-a1494f6951b923bb9bdd816930133866b8e6ab2f8e2d61d2c9730e4ee02469beL2-R12):
Modified the `useMetrics` hook to use the `useSourceCRUD` and
`useDestinationCRUD` hooks for fetching sources and destinations, and
updated the `skip` condition in the `useQuery` call to prevent fetching
metrics when there are no sources or destinations.
  • Loading branch information
BenElferink authored Jan 8, 2025
1 parent a90e163 commit 48089e4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frontend/webapp/hooks/overview/useMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useQuery } from '@apollo/client';
import { GET_METRICS } from '@/graphql/mutations/metrics';
import { useSourceCRUD } from '../sources';
import { useDestinationCRUD } from '../destinations';
import type { OverviewMetricsResponse } from '@/types';
import { GET_METRICS } from '@/graphql/mutations/metrics';

export const useMetrics = () => {
// TODO: don't fetch until we have sources and/or destinations
const { sources } = useSourceCRUD();
const { destinations } = useDestinationCRUD();

const { data } = useQuery<OverviewMetricsResponse>(GET_METRICS, {
skip: false,
skip: !sources.length && !destinations.length,
pollInterval: 3000,
});

Expand Down

0 comments on commit 48089e4

Please sign in to comment.