Skip to content

Commit

Permalink
Fix bug when loading Metrics graph
Browse files Browse the repository at this point in the history
Fixes a bug where the ProfileSelector component is trying to set the query expression before it has been successfully fetched from the URL. Adding an early return to the useEffect, and adding `queryExpression` to the dependency array fixes this.
  • Loading branch information
yomete committed Nov 28, 2023
1 parent ec1aabe commit c5aebd9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ui/packages/shared/profile/src/ProfileSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ const ProfileSelector = ({
const [timeRangeSelection, setTimeRangeSelection] = useState(
DateTimeRange.fromRangeKey(querySelection.timeSelection)
);

const [queryExpressionString, setQueryExpressionString] = useState(querySelection.expression);

useEffect(() => {
if (querySelection.expression === undefined) {
return;
}

setIsDataLoading(true);
const handleNewTimeRange = async (): Promise<void> => {
await setQueryExpression();
await setIsDataLoading(false);
};

void handleNewTimeRange();
setQueryExpression();
setIsDataLoading(false);

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [timeRangeSelection]);
}, [timeRangeSelection, querySelection.expression]);

useEffect(() => {
if (enforcedProfileName !== '') {
Expand Down

0 comments on commit c5aebd9

Please sign in to comment.