Skip to content

ref(ddm): datetime params #56567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions static/app/utils/metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import {useMemo} from 'react';
import moment from 'moment';

import {getInterval} from 'sentry/components/charts/utils';
import {parseStatsPeriod} from 'sentry/components/organizations/timeRangeSelector/utils';
import {ApiQueryKey, useApiQuery} from 'sentry/utils/queryClient';
import useOrganization from 'sentry/utils/useOrganization';

import {DateString} from '../types/core';
import {PageFilters} from '../types/core';

type MetricMeta = {
mri: string;
Expand Down Expand Up @@ -63,15 +62,8 @@ export function useMetricsTagValues(mri: string, tag: string) {
);
}

type DateTime = {
end: DateString | null;
period: string | null;
start: DateString | null;
utc: boolean | null;
};

export type MetricsDataProps = {
datetime: DateTime;
datetime: PageFilters['datetime'];
mri: string;
groupBy?: string[];
op?: string;
Expand Down Expand Up @@ -106,19 +98,12 @@ export function useMetricsData({
const useCase = getUseCaseFromMri(mri);
const field = op ? `${op}(${mri})` : mri;

const {start, end, period} = useMemo(
() => getUTCTimeRange(datetime.start, datetime.end, datetime.period),
[datetime.period, datetime.start, datetime.end]
);

const interval = getInterval({start, end}, 'metrics');

const query = getQueryString({projects, queryString});

const datetimeParams = period ? {statsPeriod: period} : {start, end};
const interval = getInterval(datetime, 'metrics');

const queryToSend = {
...datetimeParams,
...getDateTimeParams(datetime),
field,
useCase,
interval,
Expand Down Expand Up @@ -148,6 +133,12 @@ export function useMetricsData({
);
}

function getDateTimeParams({start, end, period}: PageFilters['datetime']) {
return period
? {statsPeriod: period}
: {start: moment(start).toISOString(), end: moment(end).toISOString()};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still have to convert these to ISO because they are formatted as locale strings

}

function getQueryString({
projects = [],
queryString = '',
Expand All @@ -156,22 +147,6 @@ function getQueryString({
return [projectQuery, queryString].join(' ');
}

const getUTCTimeRange = (
startDate: DateString,
endDate: DateString,
period: string | null
) => {
const {start, end} = period
? parseStatsPeriod(period)
: {start: startDate, end: endDate};

return {
period,
start: moment(start).utc().toISOString(),
end: moment(end).utc().toISOString(),
};
};

type UseCase = 'sessions' | 'transactions' | 'custom';

export function getUseCaseFromMri(mri?: string): UseCase {
Expand Down