Skip to content

Commit

Permalink
fix(graphCardContext): sw-690 duplicate api calls (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera authored Nov 30, 2022
1 parent 339f43f commit 2891b10
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/components/graphCard/graphCardContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,24 @@ const useGetMetrics = ({
const { settings = {} } = useAliasGraphCardContext();
const { metrics = [] } = settings;

const response = useAliasMetricsSelector();
const { pending, ...response } = useAliasMetricsSelector();

useShallowCompareEffect(() => {
const updatedMetrics = metrics.map(({ metric: metricId, isCapacity, query: metricQuery }) => ({
id: productId,
metric: metricId,
isCapacity,
query: metricQuery
}));
getGraphMetrics(updatedMetrics, query)(dispatch);
}, [dispatch, getGraphMetrics, metrics, productId, query]);
if (!pending) {
const updatedMetrics = metrics.map(({ metric: metricId, isCapacity, query: metricQuery }) => ({
id: productId,
metric: metricId,
isCapacity,
query: metricQuery
}));
getGraphMetrics(updatedMetrics, query)(dispatch);
}
}, [metrics, productId, query]);

return response;
return {
...response,
pending
};
};

const context = {
Expand Down

0 comments on commit 2891b10

Please sign in to comment.