mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
add timezone to revenue chartData. Fix min/max date for 7day value
This commit is contained in:
parent
bf99068bd7
commit
89d3cd4f5a
4 changed files with 21 additions and 15 deletions
|
|
@ -18,20 +18,20 @@ import { useCallback, useMemo, useState } from 'react';
|
|||
|
||||
export interface RevenueProps {
|
||||
websiteId: string;
|
||||
minDate: Date;
|
||||
maxDate: Date;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
unit: string;
|
||||
}
|
||||
|
||||
export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
|
||||
export function Revenue({ websiteId, startDate, endDate, unit }: RevenueProps) {
|
||||
const [currency, setCurrency] = useState('USD');
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { locale, dateLocale } = useLocale();
|
||||
const { countryNames } = useCountryNames(locale);
|
||||
const { data, error, isLoading } = useResultQuery<any>('revenue', {
|
||||
websiteId,
|
||||
minDate,
|
||||
maxDate,
|
||||
startDate,
|
||||
endDate,
|
||||
currency,
|
||||
});
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
|
|||
const color = colord(CHART_COLORS[index % CHART_COLORS.length]);
|
||||
return {
|
||||
label: key,
|
||||
data: generateTimeSeries(map[key], minDate, maxDate, unit, dateLocale),
|
||||
data: generateTimeSeries(map[key], startDate, endDate, unit, dateLocale),
|
||||
lineTension: 0,
|
||||
backgroundColor: color.alpha(0.6).toRgbString(),
|
||||
borderColor: color.alpha(0.7).toRgbString(),
|
||||
|
|
@ -71,7 +71,7 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
|
|||
};
|
||||
}),
|
||||
};
|
||||
}, [data, minDate, maxDate, unit]);
|
||||
}, [data, startDate, endDate, unit]);
|
||||
|
||||
const metrics = useMemo(() => {
|
||||
if (!data) return [];
|
||||
|
|
@ -122,8 +122,8 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
|
|||
<Panel>
|
||||
<BarChart
|
||||
chartData={chartData}
|
||||
minDate={minDate}
|
||||
maxDate={maxDate}
|
||||
minDate={startDate}
|
||||
maxDate={endDate}
|
||||
unit={unit}
|
||||
stacked={true}
|
||||
currency={currency}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export function RevenuePage({ websiteId }: { websiteId: string }) {
|
|||
return (
|
||||
<Column gap>
|
||||
<WebsiteControls websiteId={websiteId} />
|
||||
<Revenue websiteId={websiteId} minDate={startDate} maxDate={endDate} unit={unit} />
|
||||
<Revenue websiteId={websiteId} startDate={startDate} endDate={endDate} unit={unit} />
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,12 @@ export function parseDateRange(value: string, locale = 'en-US'): DateRange {
|
|||
|
||||
const now = new Date();
|
||||
const dateLocale = getDateLocale(locale);
|
||||
const { num = 1, unit } = parseDateValue(value);
|
||||
const { unit } = parseDateValue(value);
|
||||
let { num = 1 } = parseDateValue(value);
|
||||
|
||||
if (value === '7day') {
|
||||
num--;
|
||||
}
|
||||
|
||||
switch (unit) {
|
||||
case 'hour':
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export interface RevenuParameters {
|
|||
startDate: Date;
|
||||
endDate: Date;
|
||||
unit: string;
|
||||
timezone: string;
|
||||
currency: string;
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ async function relationalQuery(
|
|||
parameters: RevenuParameters,
|
||||
filters: QueryFilters,
|
||||
): Promise<RevenueResult> {
|
||||
const { startDate, endDate, currency, unit = 'day' } = parameters;
|
||||
const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
|
||||
const { getDateSQL, rawQuery, parseFilters } = prisma;
|
||||
const { queryParams, filterQuery, cohortQuery, joinSessionQuery } = parseFilters({
|
||||
...filters,
|
||||
|
|
@ -44,7 +45,7 @@ async function relationalQuery(
|
|||
`
|
||||
select
|
||||
revenue.event_name x,
|
||||
${getDateSQL('revenue.created_at', unit)} t,
|
||||
${getDateSQL('revenue.created_at', unit, timezone)} t,
|
||||
sum(revenue.revenue) y
|
||||
from revenue
|
||||
join website_event
|
||||
|
|
@ -123,7 +124,7 @@ async function clickhouseQuery(
|
|||
parameters: RevenuParameters,
|
||||
filters: QueryFilters,
|
||||
): Promise<RevenueResult> {
|
||||
const { startDate, endDate, unit = 'day', currency } = parameters;
|
||||
const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
|
||||
const { getDateSQL, rawQuery, parseFilters } = clickhouse;
|
||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
|
|
@ -143,7 +144,7 @@ async function clickhouseQuery(
|
|||
`
|
||||
select
|
||||
website_revenue.event_name x,
|
||||
${getDateSQL('website_revenue.created_at', unit)} t,
|
||||
${getDateSQL('website_revenue.created_at', unit, timezone)} t,
|
||||
sum(website_revenue.revenue) y
|
||||
from website_revenue
|
||||
join website_event
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue