@parca/profile 0.16.61 → 0.16.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@ interface ProfileMetricsGraphProps {
31
31
  addLabelMatcher: (key: string, value: string) => void;
32
32
  }
33
33
 
34
- export interface IQueryRangeResult {
34
+ export interface IQueryRangeState {
35
35
  response: QueryRangeResponse | null;
36
36
  isLoading: boolean;
37
37
  error: RpcError | null;
@@ -42,36 +42,39 @@ export const useQueryRange = (
42
42
  queryExpression: string,
43
43
  start: number,
44
44
  end: number
45
- ): IQueryRangeResult => {
46
- const [isLoading, setIsLoading] = useState<boolean>(false);
47
- const [error, setError] = useState<any>(null);
48
- const [response, setResponse] = useState<QueryRangeResponse | null>(null);
45
+ ): IQueryRangeState => {
46
+ const [state, setState] = useState<IQueryRangeState>({
47
+ response: null,
48
+ isLoading: true,
49
+ error: null,
50
+ });
49
51
  const metadata = useGrpcMetadata();
50
52
 
51
53
  useEffect(() => {
52
54
  void (async () => {
53
- setIsLoading(true);
55
+ setState({
56
+ response: null,
57
+ isLoading: true,
58
+ error: null,
59
+ });
54
60
 
55
- try {
56
- const {response} = await client.queryRange(
57
- {
58
- query: queryExpression,
59
- start: Timestamp.fromDate(new Date(start)),
60
- end: Timestamp.fromDate(new Date(end)),
61
- limit: 0,
62
- },
63
- {meta: metadata}
64
- );
65
- setResponse(response);
66
- } catch (e) {
67
- setError(e);
68
- } finally {
69
- setIsLoading(false);
70
- }
61
+ const call = client.queryRange(
62
+ {
63
+ query: queryExpression,
64
+ start: Timestamp.fromDate(new Date(start)),
65
+ end: Timestamp.fromDate(new Date(end)),
66
+ limit: 0,
67
+ },
68
+ {meta: metadata}
69
+ );
70
+
71
+ call.response
72
+ .then(response => setState({response, isLoading: false, error: null}))
73
+ .catch(error => setState({response: null, isLoading: false, error}));
71
74
  })();
72
75
  }, [client, queryExpression, start, end, metadata]);
73
76
 
74
- return {isLoading, error, response};
77
+ return state;
75
78
  };
76
79
 
77
80
  const ProfileMetricsGraph = ({