|
@@ -15,15 +15,11 @@ import {t} from 'sentry/locale';
|
|
|
import type {PageFilters} from 'sentry/types/core';
|
|
|
import {parsePeriodToHours} from 'sentry/utils/dates';
|
|
|
import {useUpdateQuery} from 'sentry/utils/metrics';
|
|
|
-import {parseMRI} from 'sentry/utils/metrics/mri';
|
|
|
-import {isMetricsEquationWidget} from 'sentry/utils/metrics/types';
|
|
|
import {decodeScalar} from 'sentry/utils/queryString';
|
|
|
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
|
|
|
import usePageFilters from 'sentry/utils/usePageFilters';
|
|
|
-import {useMetricsContext} from 'sentry/views/metrics/context';
|
|
|
|
|
|
const ALL_INTERVAL_OPTIONS = [
|
|
|
- {value: '10s', label: t('10 seconds')},
|
|
|
{value: '1m', label: t('1 minute')},
|
|
|
{value: '5m', label: t('5 minutes')},
|
|
|
{value: '15m', label: t('15 minutes')},
|
|
@@ -55,19 +51,10 @@ const maximumInterval = new GranularityLadder([
|
|
|
[0, '1m'],
|
|
|
]);
|
|
|
|
|
|
-export function getIntervalOptionsForStatsPeriod(
|
|
|
- datetime: PageFilters['datetime'],
|
|
|
- isCustomMetricsOnly: boolean
|
|
|
-) {
|
|
|
+export function getIntervalOptionsForStatsPeriod(datetime: PageFilters['datetime']) {
|
|
|
const diffInMinutes = getDiffInMinutes(datetime);
|
|
|
- const diffInHours = diffInMinutes / 60;
|
|
|
-
|
|
|
- const minimumOption =
|
|
|
- // BE returns empty timeseries if we request less than 1 minute granularity
|
|
|
- // for other data sets than custom metrics
|
|
|
- isCustomMetricsOnly && diffInHours <= 1
|
|
|
- ? '10s'
|
|
|
- : minimumInterval.getInterval(diffInMinutes);
|
|
|
+
|
|
|
+ const minimumOption = minimumInterval.getInterval(diffInMinutes);
|
|
|
const minimumOptionInHours = parsePeriodToHours(minimumOption);
|
|
|
|
|
|
const maximumOption = maximumInterval.getInterval(diffInMinutes);
|
|
@@ -96,15 +83,6 @@ export function useMetricsIntervalParam() {
|
|
|
const {interval} = useLocationQuery({fields: {interval: decodeScalar}});
|
|
|
const updateQuery = useUpdateQuery();
|
|
|
|
|
|
- const {widgets} = useMetricsContext();
|
|
|
-
|
|
|
- const isCustomMetricsOnly = useMemo(() => {
|
|
|
- return widgets.every(
|
|
|
- widget =>
|
|
|
- isMetricsEquationWidget(widget) || parseMRI(widget.mri)?.useCase === 'custom'
|
|
|
- );
|
|
|
- }, [widgets]);
|
|
|
-
|
|
|
const handleIntervalChange = useCallback(
|
|
|
(newInterval: string) => {
|
|
|
updateQuery({interval: newInterval}, {replace: true});
|
|
@@ -115,7 +93,6 @@ export function useMetricsIntervalParam() {
|
|
|
const metricsIntervalOptions = useMetricsIntervalOptions({
|
|
|
interval,
|
|
|
datetime,
|
|
|
- isCustomMetricsOnly,
|
|
|
onIntervalChange: handleIntervalChange,
|
|
|
});
|
|
|
|
|
@@ -132,18 +109,16 @@ export interface MetricsIntervalParamProps {
|
|
|
datetime: PageFilters['datetime'];
|
|
|
interval: string;
|
|
|
onIntervalChange: (interval: string) => void;
|
|
|
- isCustomMetricsOnly?: boolean;
|
|
|
}
|
|
|
|
|
|
export function useMetricsIntervalOptions({
|
|
|
interval,
|
|
|
datetime,
|
|
|
onIntervalChange,
|
|
|
- isCustomMetricsOnly = false,
|
|
|
}: MetricsIntervalParamProps) {
|
|
|
const currentIntervalOptions = useMemo(
|
|
|
- () => getIntervalOptionsForStatsPeriod(datetime, isCustomMetricsOnly),
|
|
|
- [datetime, isCustomMetricsOnly]
|
|
|
+ () => getIntervalOptionsForStatsPeriod(datetime),
|
|
|
+ [datetime]
|
|
|
);
|
|
|
|
|
|
const setInterval = useCallback(
|