Skip to content

Commit

Permalink
fix min date chart bug when using all time
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscao633 committed Nov 27, 2024
1 parent bf89dfd commit c851f3b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app/(main)/websites/[websiteId]/WebsiteChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function WebsiteChart({
compareMode?: boolean;
}) {
const { dateRange, dateCompare } = useDateRange(websiteId);
const { startDate, endDate, unit } = dateRange;
const { startDate, endDate, unit, value } = dateRange;
const { data, isLoading } = useWebsitePageviews(websiteId, compareMode ? dateCompare : undefined);
const { pageviews, sessions, compare } = (data || {}) as any;

Expand Down Expand Up @@ -49,6 +49,7 @@ export function WebsiteChart({
maxDate={endDate.toISOString()}
unit={unit}
isLoading={isLoading}
isAllTime={value === 'all'}
/>
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/charts/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface BarChartProps extends ChartProps {
YAxisType?: string;
minDate?: number | string;
maxDate?: number | string;
isAllTime?: boolean;
}

export function BarChart(props: BarChartProps) {
Expand All @@ -29,6 +30,7 @@ export function BarChart(props: BarChartProps) {
minDate,
maxDate,
currency,
isAllTime,
} = props;

const options: any = useMemo(() => {
Expand All @@ -37,7 +39,7 @@ export function BarChart(props: BarChartProps) {
x: {
type: XAxisType,
stacked: true,
min: minDate && new Date(minDate).getSeconds() === 0 ? minDate : '',
min: isAllTime ? '' : minDate,
max: maxDate,
time: {
unit,
Expand Down
9 changes: 5 additions & 4 deletions src/components/metrics/EventsChart.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useMemo } from 'react';
import { colord } from 'colord';
import BarChart from 'components/charts/BarChart';
import { useLocale, useDateRange, useWebsiteEventsSeries } from 'components/hooks';
import { CHART_COLORS } from 'lib/constants';
import { useDateRange, useLocale, useWebsiteEventsSeries } from 'components/hooks';
import { renderDateLabels } from 'lib/charts';
import { CHART_COLORS } from 'lib/constants';
import { useMemo } from 'react';

export interface EventsChartProps {
websiteId: string;
Expand All @@ -12,7 +12,7 @@ export interface EventsChartProps {

export function EventsChart({ websiteId, className }: EventsChartProps) {
const {
dateRange: { startDate, endDate, unit },
dateRange: { startDate, endDate, unit, value },
} = useDateRange(websiteId);
const { locale } = useLocale();
const { data, isLoading } = useWebsiteEventsSeries(websiteId);
Expand Down Expand Up @@ -55,6 +55,7 @@ export function EventsChart({ websiteId, className }: EventsChartProps) {
stacked={true}
renderXLabel={renderDateLabels(unit, locale)}
isLoading={isLoading}
isAllTime={value === 'all'}
/>
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/components/metrics/PageviewsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ export interface PagepageviewsChartProps extends BarChartProps {
};
unit: string;
isLoading?: boolean;
isAllTime?: boolean;
}

export function PagepageviewsChart({ data, unit, isLoading, ...props }: PagepageviewsChartProps) {
export function PagepageviewsChart({
data,
unit,
isLoading,
isAllTime,
...props
}: PagepageviewsChartProps) {
const { formatMessage, labels } = useMessages();
const { colors } = useTheme();
const { locale } = useLocale();
Expand Down Expand Up @@ -74,6 +81,7 @@ export function PagepageviewsChart({ data, unit, isLoading, ...props }: Pagepage
data={chartData}
unit={unit}
isLoading={isLoading}
isAllTime={isAllTime}
renderXLabel={renderDateLabels(unit, locale)}
/>
);
Expand Down

0 comments on commit c851f3b

Please sign in to comment.