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!

maxRange

kruzhambusf248d07b9f5b
diff --git a/src/pages/Project/View/ViewProject.tsx b/src/pages/Project/View/ViewProject.tsx
index 2c15bb9ed..7e8d6f8f5 100644
--- a/src/pages/Project/View/ViewProject.tsx
+++ b/src/pages/Project/View/ViewProject.tsx
@@ -131,6 +131,7 @@ const ViewProject = ({
label: string
period: string
tbs: string[]
+ countDays?: number
dropdownLabel?: string
isCustomDate?: boolean
}[]>(tbPeriodPairs(t))
@@ -221,6 +222,15 @@ const ViewProject = ({
const activeDropdownLabelCompare = useMemo(() => _find(periodPairsCompare, p => p.period === activePeriodCompare)?.label, [periodPairsCompare, activePeriodCompare])
const [dateRangeCompare, setDateRangeCompare] = useState<null | Date[]>(null)
const [dataChartCompare, setDataChartCompare] = useState<any>({})
+ const maxRangeCompare = useMemo(() => {
+ if (!isActiveCompare) {
+ return 0
+ }
+
+ return _find(periodPairs, p => p.period === period)?.countDays || 0
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [isActiveCompare, period])
+ console.log(maxRangeCompare)
const tabs: {
id: string
@@ -1691,7 +1701,7 @@ const ViewProject = ({
}}
value={isActiveCompare ? dateRangeCompare || [] : dateRange || []}
maxDateMonths={MAX_MONTHS_IN_PAST}
- maxRange={10}
+ maxRange={isActiveCompare ? maxRangeCompare : 0}
/>
</div>
</div>
diff --git a/src/redux/constants/index.ts b/src/redux/constants/index.ts
index 962bd1c88..d97717100 100644
--- a/src/redux/constants/index.ts
+++ b/src/redux/constants/index.ts
@@ -26,6 +26,7 @@ export const tbPeriodPairs = (t: Function, tbs?: string[] | null, dates?: Date[]
label: string
period: string
tbs: string[]
+ countDays?: number
dropdownLabel?: string
isCustomDate?: boolean
}[] => [{
@@ -39,23 +40,28 @@ export const tbPeriodPairs = (t: Function, tbs?: string[] | null, dates?: Date[]
}, {
label: t('project.last24h'),
period: '1d',
+ countDays: 1,
tbs: ['hour'],
}, {
label: t('project.lastXDays', { amount: 7 }),
period: '7d',
tbs: ['hour', 'day'],
+ countDays: 7,
}, {
label: t('project.lastXWeeks', { amount: 4 }),
period: '4w',
tbs: ['day', 'week'],
+ countDays: 28,
}, {
label: t('project.lastXMonths', { amount: 3 }),
period: '3M',
tbs: ['week', 'month'],
+ countDays: 90,
}, {
label: t('project.lastXMonths', { amount: 12 }),
period: '12M',
tbs: ['week', 'month'],
+ countDays: 365,
}, {
label: t('project.lastXMonths', { amount: 24 }),
period: '24M',
diff --git a/src/ui/Flatpicker.tsx b/src/ui/Flatpicker.tsx
index f387ef027..f8b5ba315 100644
--- a/src/ui/Flatpicker.tsx
+++ b/src/ui/Flatpicker.tsx
@@ -47,8 +47,9 @@ class FlatPicker extends React.Component<FlatPickerProps, {
const minDate = new Date(dates[0])
maxDate.setDate(maxDate.getDate() + maxRange)
minDate.setDate(minDate.getDate() - maxRange)
+
this.setState({
- maxDate: maxDate.toISOString().split('T')[0],
+ maxDate: maxDate > new Date() ? 'today' : maxDate.toISOString().split('T')[0],
minDate: minDate.toISOString().split('T')[0],
})
}