Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix bug if setTimebucket and Period

kruzhambusf43654100a8f
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index 4bfb97135..f6b9c7548 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -632,6 +632,14 @@ const ViewProject = ({
return
}
+ console.log(activePeriod)
+ // return error if periodToForecast is less than 1 or greater than period
+ if (periodToForecast < 1 || periodToForecast > activePeriod.daysCount) {
+ setDataLoading(false)
+ showError('Period to forecast should be greater than 0 and less than period')
+ return
+ }
+
try {
const result = await getChartPrediction(chartData, periodToForecast, timeBucket)
const transformed = transformAIChartData(result)
@@ -1078,6 +1086,7 @@ const ViewProject = ({
timeBucket: tb,
dateRange: newPeriod.period === 'custom' ? dateRange : null,
})
+ setForecasedChartData({})
}
const updateTimebucket = (newTimebucket) => {
@@ -1099,6 +1108,7 @@ const ViewProject = ({
timeBucket: newTimebucket,
dateRange,
})
+ setForecasedChartData({})
}
const openSettingsHandler = () => {
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index 180567c6c..abb158d7b 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -18,41 +18,49 @@ export const tbPeriodPairs = (t, tbs, dates) => [{
period: 'today',
tbs: ['hour'],
access: 'free',
+ daysCount: 1,
}, {
label: t('project.yesterday'),
period: 'yesterday',
tbs: ['hour'],
access: 'free',
+ daysCount: 1,
}, {
label: t('project.last24h'),
period: '1d',
tbs: ['hour'],
access: 'free',
+ daysCount: 1,
}, {
label: t('project.lastXDays', { amount: 7 }),
period: '7d',
tbs: ['hour', 'day'],
access: 'free',
+ daysCount: 7,
}, {
label: t('project.lastXWeeks', { amount: 4 }),
period: '4w',
tbs: ['day', 'week'],
access: 'free',
+ daysCount: 28,
}, {
label: t('project.lastXMonths', { amount: 3 }),
period: '3M',
tbs: ['week', 'month'],
access: 'free',
+ daysCount: 90,
}, {
label: t('project.lastXMonths', { amount: 12 }),
period: '12M',
tbs: ['week', 'month'],
access: 'paid',
+ daysCount: 365,
}, {
label: t('project.lastXMonths', { amount: 24 }),
period: '24M',
tbs: ['month'],
access: 'paid',
+ daysCount: 730,
}, {
label: getCustomLabel(dates, t),
dropdownLabel: t('project.custom'),
@@ -60,6 +68,7 @@ export const tbPeriodPairs = (t, tbs, dates) => [{
period: 'custom',
tbs: tbs || ['custom'],
access: 'free',
+ daysCount: dates ? Math.ceil((dates[1] - dates[0]) / (1000 * 60 * 60 * 24)) : 0,
}]
// the maximum amount of months user can go back when picking a date in flat picker (project view)