forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/lib/constants.ts
- Loading branch information
Showing
23 changed files
with
500 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import BarChart, { BarChartProps } from 'components/charts/BarChart'; | ||
import { useLocale, useMessages } from 'components/hooks'; | ||
import MetricCard from 'components/metrics/MetricCard'; | ||
import MetricsBar from 'components/metrics/MetricsBar'; | ||
import { renderDateLabels } from 'lib/charts'; | ||
import { formatLongNumber } from 'lib/format'; | ||
import { useContext, useMemo } from 'react'; | ||
import { ReportContext } from '../[reportId]/Report'; | ||
|
||
export interface PageviewsChartProps extends BarChartProps { | ||
isLoading?: boolean; | ||
} | ||
|
||
export function RevenueChart({ isLoading, ...props }: PageviewsChartProps) { | ||
const { formatMessage, labels } = useMessages(); | ||
const { locale } = useLocale(); | ||
const { report } = useContext(ReportContext); | ||
const { data, parameters } = report || {}; | ||
|
||
const chartData = useMemo(() => { | ||
if (!data) { | ||
return {}; | ||
} | ||
|
||
return { | ||
datasets: [ | ||
{ | ||
label: formatMessage(labels.average), | ||
data: data?.chart.map(a => ({ x: a.time, y: a.avg })), | ||
borderWidth: 2, | ||
backgroundColor: '#8601B0', | ||
borderColor: '#8601B0', | ||
order: 1, | ||
}, | ||
{ | ||
label: formatMessage(labels.total), | ||
data: data?.chart.map(a => ({ x: a.time, y: a.sum })), | ||
borderWidth: 2, | ||
backgroundColor: '#f15bb5', | ||
borderColor: '#f15bb5', | ||
order: 2, | ||
}, | ||
], | ||
}; | ||
}, [data, locale]); | ||
|
||
const metricData = useMemo(() => { | ||
if (!data) { | ||
return []; | ||
} | ||
|
||
const { sum, avg, count, uniqueCount } = data.total; | ||
|
||
return [ | ||
{ | ||
value: sum, | ||
label: formatMessage(labels.total), | ||
formatValue: formatLongNumber, | ||
}, | ||
{ | ||
value: avg, | ||
label: formatMessage(labels.average), | ||
formatValue: formatLongNumber, | ||
}, | ||
{ | ||
value: count, | ||
label: formatMessage(labels.transactions), | ||
formatValue: formatLongNumber, | ||
}, | ||
{ | ||
value: uniqueCount, | ||
label: formatMessage(labels.uniqueCustomers), | ||
formatValue: formatLongNumber, | ||
}, | ||
] as any; | ||
}, [data, locale]); | ||
|
||
return ( | ||
<> | ||
<MetricsBar isFetched={data}> | ||
{metricData?.map(({ label, value, formatValue }) => { | ||
return <MetricCard key={label} value={value} label={label} formatValue={formatValue} />; | ||
})} | ||
</MetricsBar> | ||
{data && ( | ||
<BarChart | ||
{...props} | ||
data={chartData} | ||
unit={parameters?.dateRange.unit} | ||
isLoading={isLoading} | ||
renderXLabel={renderDateLabels(parameters?.dateRange.unit, locale)} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default RevenueChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useMessages } from 'components/hooks'; | ||
import { useContext } from 'react'; | ||
import { Form, FormButtons, FormInput, FormRow, SubmitButton, TextField } from 'react-basics'; | ||
import BaseParameters from '../[reportId]/BaseParameters'; | ||
import { ReportContext } from '../[reportId]/Report'; | ||
|
||
export function RevenueParameters() { | ||
const { report, runReport, isRunning } = useContext(ReportContext); | ||
const { formatMessage, labels } = useMessages(); | ||
|
||
const { id, parameters } = report || {}; | ||
const { websiteId, dateRange } = parameters || {}; | ||
const queryDisabled = !websiteId || !dateRange; | ||
|
||
const handleSubmit = (data: any, e: any) => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
|
||
if (!queryDisabled) { | ||
runReport(data); | ||
} | ||
}; | ||
|
||
return ( | ||
<Form values={parameters} onSubmit={handleSubmit} preventSubmit={true}> | ||
<BaseParameters showDateSelect={true} allowWebsiteSelect={!id} /> | ||
<FormRow label={formatMessage(labels.event)}> | ||
<FormInput name="eventName" rules={{ required: formatMessage(labels.required) }}> | ||
<TextField autoComplete="off" /> | ||
</FormInput> | ||
</FormRow> | ||
<FormRow label={formatMessage(labels.revenueProperty)}> | ||
<FormInput name="revenueProperty" rules={{ required: formatMessage(labels.required) }}> | ||
<TextField autoComplete="off" /> | ||
</FormInput> | ||
</FormRow> | ||
<FormRow label={formatMessage(labels.userProperty)}> | ||
<FormInput name="userProperty"> | ||
<TextField autoComplete="off" /> | ||
</FormInput> | ||
</FormRow> | ||
<FormButtons> | ||
<SubmitButton variant="primary" disabled={queryDisabled} isLoading={isRunning}> | ||
{formatMessage(labels.runQuery)} | ||
</SubmitButton> | ||
</FormButtons> | ||
</Form> | ||
); | ||
} | ||
|
||
export default RevenueParameters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.filters { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
border: 1px solid var(--base400); | ||
border-radius: var(--border-radius); | ||
line-height: 32px; | ||
padding: 10px; | ||
overflow: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import RevenueChart from './RevenueChart'; | ||
import RevenueParameters from './RevenueParameters'; | ||
import Report from '../[reportId]/Report'; | ||
import ReportHeader from '../[reportId]/ReportHeader'; | ||
import ReportMenu from '../[reportId]/ReportMenu'; | ||
import ReportBody from '../[reportId]/ReportBody'; | ||
import Target from 'assets/target.svg'; | ||
import { REPORT_TYPES } from 'lib/constants'; | ||
|
||
const defaultParameters = { | ||
type: REPORT_TYPES.revenue, | ||
parameters: { Revenue: [] }, | ||
}; | ||
|
||
export default function RevenueReport({ reportId }: { reportId?: string }) { | ||
return ( | ||
<Report reportId={reportId} defaultParameters={defaultParameters}> | ||
<ReportHeader icon={<Target />} /> | ||
<ReportMenu> | ||
<RevenueParameters /> | ||
</ReportMenu> | ||
<ReportBody> | ||
<RevenueChart /> | ||
</ReportBody> | ||
</Report> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use client'; | ||
import RevenueReport from './RevenueReport'; | ||
|
||
export default function RevenueReportPage() { | ||
return <RevenueReport />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import RevenueReportPage from './RevenueReportPage'; | ||
import { Metadata } from 'next'; | ||
|
||
export default function () { | ||
return <RevenueReportPage />; | ||
} | ||
|
||
export const metadata: Metadata = { | ||
title: 'Revenue Report', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.