fix(dashboard): ensure we only pass dates to formatdate
This commit is contained in:
@@ -72,7 +72,15 @@ export const useXAxisProps = (
|
|||||||
scale: 'utc',
|
scale: 'utc',
|
||||||
domain: ['dataMin', 'dataMax'] as AxisDomain,
|
domain: ['dataMin', 'dataMax'] as AxisDomain,
|
||||||
tickFormatter:
|
tickFormatter:
|
||||||
interval === 'auto' ? undefined : (m: string) => formatDate(new Date(m)),
|
interval === 'auto'
|
||||||
|
? undefined
|
||||||
|
: (m: string) => {
|
||||||
|
if (['dataMin', 'dataMax'].includes(m)) {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatDate(new Date(m));
|
||||||
|
},
|
||||||
type: 'number' as const,
|
type: 'number' as const,
|
||||||
tickLine: false,
|
tickLine: false,
|
||||||
minTickGap: 20,
|
minTickGap: 20,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { IInterval } from '@openpanel/validation';
|
import type { IInterval } from '@openpanel/validation';
|
||||||
|
|
||||||
export function formatDateInterval(interval: IInterval, date: Date): string {
|
export function formatDateInterval(interval: IInterval, date: Date): string {
|
||||||
|
try {
|
||||||
if (interval === 'hour' || interval === 'minute') {
|
if (interval === 'hour' || interval === 'minute') {
|
||||||
return new Intl.DateTimeFormat('en-GB', {
|
return new Intl.DateTimeFormat('en-GB', {
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
@@ -21,6 +22,9 @@ export function formatDateInterval(interval: IInterval, date: Date): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return date.toISOString();
|
return date.toISOString();
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useFormatDateInterval(interval: IInterval) {
|
export function useFormatDateInterval(interval: IInterval) {
|
||||||
|
|||||||
Reference in New Issue
Block a user