Skip to content

Commit 747ea8f

Browse files
gggritsoclaude
andcommitted
feat(explore): Add 1 day interval option for durations >= 14 days
The interval rebalancing in #112562 removed the 1d bucket option. Add it back as an extra option appended to the dropdown for durations of 14 days or more, without changing the ladder-derived defaults. Refs DAIN-1511 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ff568d2 commit 747ea8f

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

static/app/utils/useChartInterval.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('useChartInterval', () => {
2727
{value: '1h', label: '1 hour'},
2828
{value: '3h', label: '3 hours'},
2929
{value: '6h', label: '6 hours'},
30+
{value: '1d', label: '1 day'},
3031
]);
3132
expect(chartInterval).toBe('1h'); // default
3233

static/app/utils/useChartInterval.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,32 @@ function useChartIntervalImpl({
6565
intervalOptions: Array<{label: string; value: string}>,
6666
] {
6767
const {datetime} = pagefilters.selection;
68-
const intervalOptions = useMemo(
69-
() => getIntervalOptionsForPageFilter(datetime),
70-
[datetime]
71-
);
7268

73-
const interval = useMemo(() => {
74-
const decodedInterval = decodeScalar(location.query.interval);
69+
const {intervalOptions, defaultInterval} = useMemo(() => {
70+
const diffInMinutes = getDiffInMinutes(datetime);
71+
const options = getIntervalOptionsForPageFilter(datetime);
7572

76-
// Default to the second largest option or largest option
77-
const fallbackInterval =
73+
// Compute the default from the ladder-derived options, before appending extras
74+
const fallback =
7875
unspecifiedStrategy === ChartIntervalUnspecifiedStrategy.USE_SMALLEST
79-
? intervalOptions[0]!.value
80-
: (intervalOptions[intervalOptions.length - 2]?.value ??
81-
intervalOptions[intervalOptions.length - 1]!.value);
76+
? options[0]!.value
77+
: (options[options.length - 2]?.value ?? options[options.length - 1]!.value);
78+
79+
if (diffInMinutes >= MINIMUM_DURATION_FOR_ONE_DAY_INTERVAL) {
80+
options.push(ONE_DAY_OPTION);
81+
}
82+
83+
return {intervalOptions: options, defaultInterval: fallback};
84+
}, [datetime, unspecifiedStrategy]);
85+
86+
const interval = useMemo(() => {
87+
const decodedInterval = decodeScalar(location.query.interval);
8288

8389
return decodedInterval &&
8490
intervalOptions.some(option => option.value === decodedInterval)
8591
? decodedInterval
86-
: fallbackInterval;
87-
}, [location.query.interval, unspecifiedStrategy, intervalOptions]);
92+
: defaultInterval;
93+
}, [location.query.interval, intervalOptions, defaultInterval]);
8894

8995
const setInterval = useCallback(
9096
(newInterval: string) => {
@@ -139,6 +145,9 @@ const MAXIMUM_INTERVAL = new GranularityLadder([
139145
[0, '1m'],
140146
]);
141147

148+
const ONE_DAY_OPTION = {value: '1d', label: t('1 day')};
149+
const MINIMUM_DURATION_FOR_ONE_DAY_INTERVAL = TWO_WEEKS;
150+
142151
export function getIntervalOptionsForPageFilter(datetime: PageFilters['datetime']) {
143152
const diffInMinutes = getDiffInMinutes(datetime);
144153

0 commit comments

Comments
 (0)