mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
Update report parameters.
This commit is contained in:
parent
e9b0d3f796
commit
43f5854f15
@ -8,6 +8,8 @@ export const ReportContext = createContext(null);
|
||||
export function Report({ reportId, defaultParameters, children, ...props }) {
|
||||
const report = useReport(reportId, defaultParameters);
|
||||
|
||||
//console.log(report);
|
||||
|
||||
return (
|
||||
<ReportContext.Provider value={{ ...report }}>
|
||||
<Page {...props} className={styles.container}>
|
||||
|
@ -20,15 +20,16 @@ export function ReportHeader({ icon }) {
|
||||
post(`/reports/${data.id}`, data),
|
||||
);
|
||||
|
||||
const { websiteId, name, dateRange } = report || {};
|
||||
const { name, parameters } = report || {};
|
||||
const { websiteId, dateRange } = parameters || {};
|
||||
const { value, startDate, endDate } = dateRange || {};
|
||||
|
||||
const handleSelect = websiteId => {
|
||||
updateReport({ websiteId });
|
||||
const handleWebsiteSelect = websiteId => {
|
||||
updateReport({ parameters: { websiteId } });
|
||||
};
|
||||
|
||||
const handleDateChange = value => {
|
||||
updateReport({ dateRange: { ...parseDateRange(value) } });
|
||||
updateReport({ parameters: { dateRange: { ...parseDateRange(value) } } });
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
@ -71,7 +72,7 @@ export function ReportHeader({ icon }) {
|
||||
onChange={handleDateChange}
|
||||
showAllTime
|
||||
/>
|
||||
<WebsiteSelect websiteId={websiteId} onSelect={handleSelect} />
|
||||
<WebsiteSelect websiteId={websiteId} onSelect={handleWebsiteSelect} />
|
||||
<LoadingButton
|
||||
variant="primary"
|
||||
loading={isCreating || isUpdating}
|
||||
|
@ -21,15 +21,11 @@ export function useReport(reportId, defaultParameters) {
|
||||
|
||||
const runReport = useCallback(
|
||||
async parameters => {
|
||||
const { websiteId, type, dateRange } = report;
|
||||
setIsRunning(true);
|
||||
|
||||
const data = await post(`/reports/${type}`, {
|
||||
websiteId: websiteId,
|
||||
...parameters,
|
||||
startAt: +dateRange?.startDate,
|
||||
endAt: +dateRange?.endDate,
|
||||
});
|
||||
const { type } = report;
|
||||
|
||||
const data = await post(`/reports/${type}`, parameters);
|
||||
|
||||
setReport(
|
||||
produce(state => {
|
||||
|
@ -40,6 +40,9 @@ export default async (
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { id: reportId } = req.query;
|
||||
const {
|
||||
user: { id: userId },
|
||||
} = req.auth;
|
||||
|
||||
const { websiteId, type, name, description, parameters } = req.body;
|
||||
|
||||
@ -52,6 +55,7 @@ export default async (
|
||||
const result = await updateReport(
|
||||
{
|
||||
websiteId,
|
||||
userId,
|
||||
type,
|
||||
name,
|
||||
description,
|
||||
|
@ -9,8 +9,10 @@ export interface FunnelRequestBody {
|
||||
websiteId: string;
|
||||
urls: string[];
|
||||
window: number;
|
||||
startAt: number;
|
||||
endAt: number;
|
||||
dateRange: {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface FunnelResponse {
|
||||
@ -28,18 +30,20 @@ export default async (
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { websiteId, urls, window, startAt, endAt } = req.body;
|
||||
const {
|
||||
websiteId,
|
||||
urls,
|
||||
window,
|
||||
dateRange: { startDate, endDate },
|
||||
} = req.body;
|
||||
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getPageviewFunnel(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
urls,
|
||||
windowMinutes: +window,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user