Skip to content

Commit

Permalink
Using default date range when partial query params are found in the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
manojVivek committed May 17, 2022
1 parent 44b7805 commit bab7614
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ui/packages/shared/components/src/ProfileExplorer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {QueryServiceClient} from '@parca/client';
import {useAppSelector, useAppDispatch, setCompare, selectCompareMode} from '@parca/store';
import {Provider} from 'react-redux';
import {store} from '@parca/store';
import {DateTimeRange} from '../DateTimeRangePicker';

export type NavigateFunction = (path: string, queryParams: any) => void;

Expand All @@ -20,6 +21,15 @@ const getExpressionAsAString = (expression: string | []) => {
return x;
};

const sanitizeDateRange = (time_selection_a: any, from_a: any, to_a: any) => {
const range = DateTimeRange.fromRangeKey(time_selection_a);
if (from_a == null && to_a == null) {
from_a = range.getFromMs();
to_a = range.getToMs();
}
return {time_selection_a: range.getRangeKey(), from_a, to_a};
};

const ProfileExplorerApp = ({
queryClient,
queryParams,
Expand All @@ -28,7 +38,7 @@ const ProfileExplorerApp = ({
const dispatch = useAppDispatch();
const compareMode = useAppSelector(selectCompareMode);

const {
let {
from_a,
to_a,
merge_a,
Expand All @@ -47,6 +57,11 @@ const ProfileExplorerApp = ({
compare_b,
} = queryParams;

const sanitizedRange = sanitizeDateRange(time_selection_a, from_a, to_a);
time_selection_a = sanitizedRange.time_selection_a;
from_a = sanitizedRange.from_a;
to_a = sanitizedRange.to_a;

const expression_a = getExpressionAsAString(queryParams.expression_a);

const expression_b = getExpressionAsAString(queryParams.expression_b);
Expand Down

0 comments on commit bab7614

Please sign in to comment.