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 {
|
export interface RevenueProps {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
minDate: Date;
|
startDate: Date;
|
||||||
maxDate: Date;
|
endDate: Date;
|
||||||
unit: string;
|
unit: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
|
export function Revenue({ websiteId, startDate, endDate, unit }: RevenueProps) {
|
||||||
const [currency, setCurrency] = useState('USD');
|
const [currency, setCurrency] = useState('USD');
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { locale, dateLocale } = useLocale();
|
const { locale, dateLocale } = useLocale();
|
||||||
const { countryNames } = useCountryNames(locale);
|
const { countryNames } = useCountryNames(locale);
|
||||||
const { data, error, isLoading } = useResultQuery<any>('revenue', {
|
const { data, error, isLoading } = useResultQuery<any>('revenue', {
|
||||||
websiteId,
|
websiteId,
|
||||||
minDate,
|
startDate,
|
||||||
maxDate,
|
endDate,
|
||||||
currency,
|
currency,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
|
||||||
const color = colord(CHART_COLORS[index % CHART_COLORS.length]);
|
const color = colord(CHART_COLORS[index % CHART_COLORS.length]);
|
||||||
return {
|
return {
|
||||||
label: key,
|
label: key,
|
||||||
data: generateTimeSeries(map[key], minDate, maxDate, unit, dateLocale),
|
data: generateTimeSeries(map[key], startDate, endDate, unit, dateLocale),
|
||||||
lineTension: 0,
|
lineTension: 0,
|
||||||
backgroundColor: color.alpha(0.6).toRgbString(),
|
backgroundColor: color.alpha(0.6).toRgbString(),
|
||||||
borderColor: color.alpha(0.7).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(() => {
|
const metrics = useMemo(() => {
|
||||||
if (!data) return [];
|
if (!data) return [];
|
||||||
|
|
@ -122,8 +122,8 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
|
||||||
<Panel>
|
<Panel>
|
||||||
<BarChart
|
<BarChart
|
||||||
chartData={chartData}
|
chartData={chartData}
|
||||||
minDate={minDate}
|
minDate={startDate}
|
||||||
maxDate={maxDate}
|
maxDate={endDate}
|
||||||
unit={unit}
|
unit={unit}
|
||||||
stacked={true}
|
stacked={true}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export function RevenuePage({ websiteId }: { websiteId: string }) {
|
||||||
return (
|
return (
|
||||||
<Column gap>
|
<Column gap>
|
||||||
<WebsiteControls websiteId={websiteId} />
|
<WebsiteControls websiteId={websiteId} />
|
||||||
<Revenue websiteId={websiteId} minDate={startDate} maxDate={endDate} unit={unit} />
|
<Revenue websiteId={websiteId} startDate={startDate} endDate={endDate} unit={unit} />
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,12 @@ export function parseDateRange(value: string, locale = 'en-US'): DateRange {
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const dateLocale = getDateLocale(locale);
|
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) {
|
switch (unit) {
|
||||||
case 'hour':
|
case 'hour':
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export interface RevenuParameters {
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
endDate: Date;
|
endDate: Date;
|
||||||
unit: string;
|
unit: string;
|
||||||
|
timezone: string;
|
||||||
currency: string;
|
currency: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +31,7 @@ async function relationalQuery(
|
||||||
parameters: RevenuParameters,
|
parameters: RevenuParameters,
|
||||||
filters: QueryFilters,
|
filters: QueryFilters,
|
||||||
): Promise<RevenueResult> {
|
): Promise<RevenueResult> {
|
||||||
const { startDate, endDate, currency, unit = 'day' } = parameters;
|
const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
|
||||||
const { getDateSQL, rawQuery, parseFilters } = prisma;
|
const { getDateSQL, rawQuery, parseFilters } = prisma;
|
||||||
const { queryParams, filterQuery, cohortQuery, joinSessionQuery } = parseFilters({
|
const { queryParams, filterQuery, cohortQuery, joinSessionQuery } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
|
|
@ -44,7 +45,7 @@ async function relationalQuery(
|
||||||
`
|
`
|
||||||
select
|
select
|
||||||
revenue.event_name x,
|
revenue.event_name x,
|
||||||
${getDateSQL('revenue.created_at', unit)} t,
|
${getDateSQL('revenue.created_at', unit, timezone)} t,
|
||||||
sum(revenue.revenue) y
|
sum(revenue.revenue) y
|
||||||
from revenue
|
from revenue
|
||||||
join website_event
|
join website_event
|
||||||
|
|
@ -123,7 +124,7 @@ async function clickhouseQuery(
|
||||||
parameters: RevenuParameters,
|
parameters: RevenuParameters,
|
||||||
filters: QueryFilters,
|
filters: QueryFilters,
|
||||||
): Promise<RevenueResult> {
|
): Promise<RevenueResult> {
|
||||||
const { startDate, endDate, unit = 'day', currency } = parameters;
|
const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
|
||||||
const { getDateSQL, rawQuery, parseFilters } = clickhouse;
|
const { getDateSQL, rawQuery, parseFilters } = clickhouse;
|
||||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
|
|
@ -143,7 +144,7 @@ async function clickhouseQuery(
|
||||||
`
|
`
|
||||||
select
|
select
|
||||||
website_revenue.event_name x,
|
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
|
sum(website_revenue.revenue) y
|
||||||
from website_revenue
|
from website_revenue
|
||||||
join website_event
|
join website_event
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue