improved date range selector with hotkeys
This commit is contained in:
@@ -2,6 +2,59 @@ import { isSameDay, isSameMonth } from 'date-fns';
|
||||
|
||||
export const NOT_SET_VALUE = '(not set)';
|
||||
|
||||
export const timeWindows = {
|
||||
'30min': {
|
||||
key: '30min',
|
||||
label: 'Last 30 min',
|
||||
shortcut: 'R',
|
||||
},
|
||||
lastHour: {
|
||||
key: 'lastHour',
|
||||
label: 'Last hour',
|
||||
shortcut: 'H',
|
||||
},
|
||||
today: {
|
||||
key: 'today',
|
||||
label: 'Today',
|
||||
shortcut: 'D',
|
||||
},
|
||||
'7d': {
|
||||
key: '7d',
|
||||
label: 'Last 7 days',
|
||||
shortcut: 'W',
|
||||
},
|
||||
'30d': {
|
||||
key: '30d',
|
||||
label: 'Last 30 days',
|
||||
shortcut: 'T',
|
||||
},
|
||||
monthToDate: {
|
||||
key: 'monthToDate',
|
||||
label: 'Month to Date',
|
||||
shortcut: 'M',
|
||||
},
|
||||
lastMonth: {
|
||||
key: 'lastMonth',
|
||||
label: 'Last Month',
|
||||
shortcut: 'P',
|
||||
},
|
||||
yearToDate: {
|
||||
key: 'yearToDate',
|
||||
label: 'Year to Date',
|
||||
shortcut: 'Y',
|
||||
},
|
||||
lastYear: {
|
||||
key: 'lastYear',
|
||||
label: 'Last year',
|
||||
shortcut: 'U',
|
||||
},
|
||||
custom: {
|
||||
key: 'custom',
|
||||
label: 'Custom range',
|
||||
shortcut: 'C',
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const ProjectTypeNames = {
|
||||
website: 'Website',
|
||||
app: 'App',
|
||||
@@ -64,7 +117,7 @@ export const alphabetIds = [
|
||||
'J',
|
||||
] as const;
|
||||
|
||||
export const timeRanges = {
|
||||
export const deprecated_timeRanges = {
|
||||
'30min': '30min',
|
||||
'1h': '1h',
|
||||
today: 'today',
|
||||
@@ -84,26 +137,29 @@ export const metrics = {
|
||||
max: 'max',
|
||||
} as const;
|
||||
|
||||
export function isMinuteIntervalEnabledByRange(range: keyof typeof timeRanges) {
|
||||
return range === '30min' || range === '1h';
|
||||
export function isMinuteIntervalEnabledByRange(
|
||||
range: keyof typeof timeWindows
|
||||
) {
|
||||
return range === '30min' || range === 'lastHour';
|
||||
}
|
||||
|
||||
export function isHourIntervalEnabledByRange(range: keyof typeof timeRanges) {
|
||||
return (
|
||||
isMinuteIntervalEnabledByRange(range) ||
|
||||
range === 'today' ||
|
||||
range === '24h'
|
||||
);
|
||||
export function isHourIntervalEnabledByRange(range: keyof typeof timeWindows) {
|
||||
return isMinuteIntervalEnabledByRange(range) || range === 'today';
|
||||
}
|
||||
|
||||
export function getDefaultIntervalByRange(
|
||||
range: keyof typeof timeRanges
|
||||
range: keyof typeof timeWindows
|
||||
): keyof typeof intervals {
|
||||
if (range === '30min' || range === '1h') {
|
||||
if (range === '30min' || range === 'lastHour') {
|
||||
return 'minute';
|
||||
} else if (range === 'today' || range === '24h') {
|
||||
} else if (range === 'today') {
|
||||
return 'hour';
|
||||
} else if (range === '7d' || range === '14d' || range === '1m') {
|
||||
} else if (
|
||||
range === '7d' ||
|
||||
range === '30d' ||
|
||||
range === 'lastMonth' ||
|
||||
range === 'monthToDate'
|
||||
) {
|
||||
return 'day';
|
||||
}
|
||||
return 'month';
|
||||
|
||||
Reference in New Issue
Block a user