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: bugs, warning and errors

kruzhambus6ceffec3c654
diff --git a/src/App.js b/src/App.js
index 8048f0e5c..57f4aaa38 100644
--- a/src/App.js
+++ b/src/App.js
@@ -51,6 +51,7 @@ const About = lazy(() => import('pages/About'))
const ProjectAlertsSettings = lazy(() => import('pages/Project/Alerts/Settings'))
const CookiePolicy = lazy(() => import('pages/CookiePolicy'))
const CaptchaSettings = lazy(() => import('pages/Captcha/Settings'))
+const CaptchaView = lazy(() => import('pages/Captcha/View'))
const minimalFooterPages = [
'/projects', '/dashboard', '/settings', '/contact',
@@ -208,8 +209,9 @@ const App = () => {
<Route path={routes.alert_settings} component={ProjectAlertsSettings} exact />
<Route path={routes.create_alert} component={ProjectAlertsSettings} exact />
<Route path={routes.cookiePolicy} component={CookiePolicy} exact />
- <Route path={routes.captchaSettings} component={CaptchaSettings} exact />
+ <Route path={routes.captcha_settings} component={CaptchaSettings} exact />
<Route path={routes.new_captcha} component={CaptchaSettings} exact />
+ <Route path={routes.captcha} component={CaptchaView} exact />
<Route path='*' component={NotFound} />
</Switch>
</Suspense>
diff --git a/src/pages/Captcha/Settings/CaptchaSettings.jsx b/src/pages/Captcha/Settings/CaptchaSettings.jsx
index ef0494bb8..748397b5c 100644
--- a/src/pages/Captcha/Settings/CaptchaSettings.jsx
+++ b/src/pages/Captcha/Settings/CaptchaSettings.jsx
@@ -56,8 +56,8 @@ const CaptchaSettings = ({
const { t } = useTranslation('common')
const { pathname } = useLocation()
const { id } = useParams()
- const project = useMemo(() => _find(projects, p => p.id === id) || {}, [projects, id])
- const isSettings = !_isEmpty(id) && (_replace(routes.project_settings, ':id', id) === pathname)
+ const project = useMemo(() => _find([...projects, ...analyticsProjects], p => p.id === id) || {}, [projects, analyticsProjects, id])
+ const isSettings = !_isEmpty(id) && (_replace(routes.captcha_settings, ':id', id) === pathname)
const history = useHistory()
const [form, setForm] = useState({
name: '',
@@ -259,21 +259,23 @@ const CaptchaSettings = ({
{t('profileSettings.general')}
</h3>
<div className='mt-6'>
- <nav className='-mb-px flex space-x-8'>
- {_map(tabForCreateCaptcha, (tabCaptcha) => (
- <button
- key={tabCaptcha.name}
- type='button'
- onClick={() => setTab(tabCaptcha.name)}
- className={cx('whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-md', {
- 'border-indigo-500 text-indigo-600 dark:text-indigo-500': tab === tabCaptcha.name,
- 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300 dark:hover:border-gray-300': tab !== tabCaptcha.name,
- })}
- >
- {t(tabCaptcha.label)}
- </button>
- ))}
- </nav>
+ {!isSettings && (
+ <nav className='-mb-px flex space-x-8'>
+ {_map(tabForCreateCaptcha, (tabCaptcha) => (
+ <button
+ key={tabCaptcha.name}
+ type='button'
+ onClick={() => setTab(tabCaptcha.name)}
+ className={cx('whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-md', {
+ 'border-indigo-500 text-indigo-600 dark:text-indigo-500': tab === tabCaptcha.name,
+ 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300 dark:hover:border-gray-300': tab !== tabCaptcha.name,
+ })}
+ >
+ {t(tabCaptcha.label)}
+ </button>
+ ))}
+ </nav>
+ )}
</div>
{tab === tabForNew && (
<>
diff --git a/src/pages/Captcha/View/ViewCaptcha.container.jsx b/src/pages/Captcha/View/ViewCaptcha.container.jsx
index aa9b785bf..a811cf889 100644
--- a/src/pages/Captcha/View/ViewCaptcha.container.jsx
+++ b/src/pages/Captcha/View/ViewCaptcha.container.jsx
@@ -1,24 +1,20 @@
import { connect } from 'react-redux'
import { errorsActions } from 'redux/actions/errors'
import UIActions from 'redux/actions/ui'
-import { tabForSharedProject } from 'redux/constants'
import { alertsActions } from 'redux/actions/alerts'
import ViewProject from './ViewCaptcha'
const mapStateToProps = (state) => ({
projects: state.ui.projects.projects,
- sharedProjects: state.ui.projects.sharedProjects,
isLoading: state.ui.projects.isLoading,
cache: state.ui.cache.analytics,
- cachePerf: state.ui.cache.analyticsPerf,
projectViewPrefs: state.ui.cache.projectViewPrefs,
authenticated: state.auth.authenticated,
timezone: state.auth.user.timezone,
isPaidTierUsed: state.auth.isPaidTierUsed,
extensions: state.ui.misc.extensions,
user: state.auth.user,
- projectTab: state.ui.projects.projectTab,
})
const mapDispatchToProps = (dispatch) => ({
@@ -31,8 +27,8 @@ const mapDispatchToProps = (dispatch) => ({
setPublicProject: (project) => {
dispatch(UIActions.setPublicProject(project))
},
- setProjects: (project, shared) => {
- dispatch(UIActions.setProjects(project, shared))
+ setProjects: (project) => {
+ dispatch(UIActions.setProjects(project))
},
setLiveStatsForProject: (id, count) => {
dispatch(UIActions.setLiveStatsForProject(id, count))
@@ -40,8 +36,8 @@ const mapDispatchToProps = (dispatch) => ({
generateAlert: (message, type) => {
dispatch(alertsActions.generateAlerts(message, type))
},
- setProjectTab: (tabs) => {
- dispatch(UIActions.setProjectTab(tabs))
+ setProjectViewPrefs: (pid, period, timeBucket, rangeDate) => {
+ dispatch(UIActions.setProjectViewPrefs(pid, period, timeBucket, rangeDate))
},
})
diff --git a/src/pages/Captcha/View/ViewCaptcha.helpers.jsx b/src/pages/Captcha/View/ViewCaptcha.helpers.jsx
index 7b7c6f962..2e13da849 100644
--- a/src/pages/Captcha/View/ViewCaptcha.helpers.jsx
+++ b/src/pages/Captcha/View/ViewCaptcha.helpers.jsx
@@ -6,7 +6,7 @@ import {
import * as d3 from 'd3'
import dayjs from 'dayjs'
import {
- area, areaSpline, spline, bar,
+ area, spline, bar,
} from 'billboard.js'
import _forEach from 'lodash/forEach'
import _map from 'lodash/map'
@@ -18,7 +18,6 @@ import _size from 'lodash/size'
import _round from 'lodash/round'
import _fill from 'lodash/fill'
import _reduce from 'lodash/reduce'
-import _last from 'lodash/last'
import JSZip from 'jszip'
import {
@@ -199,17 +198,6 @@ const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions, timeFo
const modifiedChart = { ...chart }
let regions
- if (!_isEmpty(forecasedChartData)) {
- lines.push({
- value: _last(chart?.x),
- text: 'Forecast',
- })
- modifiedChart.x = [...modifiedChart.x, ...forecasedChartData.x]
- modifiedChart.uniques = [...modifiedChart.uniques, ...forecasedChartData.uniques]
- modifiedChart.visits = [...modifiedChart.visits, ...forecasedChartData.visits]
- modifiedChart.sdur = [...modifiedChart.sdur, ...forecasedChartData.sdur]
- }
-
if (applyRegions) {
let regionStart
diff --git a/src/pages/Captcha/View/ViewCaptcha.jsx b/src/pages/Captcha/View/ViewCaptcha.jsx
index 38587e8fe..a92b7041d 100644
--- a/src/pages/Captcha/View/ViewCaptcha.jsx
+++ b/src/pages/Captcha/View/ViewCaptcha.jsx
@@ -1,6 +1,6 @@
/* eslint-disable react/forbid-prop-types, react/no-unstable-nested-components, react/display-name */
import React, {
- useState, useEffect, useMemo, memo, useRef, Fragment, useCallback,
+ useState, useEffect, useMemo, memo, useRef, Fragment,
} from 'react'
import useSize from 'hooks/useSize'
import { useHistory, useParams, Link } from 'react-router-dom'
@@ -8,7 +8,7 @@ import domToImage from 'dom-to-image'
import { saveAs } from 'file-saver'
import bb from 'billboard.js'
import {
- ArrowDownTrayIcon, Cog8ToothIcon, ArrowPathIcon, CurrencyDollarIcon, ChartBarIcon, BoltIcon, BellIcon, PresentationChartBarIcon, PresentationChartLineIcon,
+ ArrowDownTrayIcon, Cog8ToothIcon, ArrowPathIcon, CurrencyDollarIcon, PresentationChartBarIcon, PresentationChartLineIcon,
} from '@heroicons/react/24/outline'
import cx from 'clsx'
import dayjs from 'dayjs'
@@ -19,7 +19,6 @@ import _includes from 'lodash/includes'
import _last from 'lodash/last'
import _isEmpty from 'lodash/isEmpty'
import _replace from 'lodash/replace'
-import _values from 'lodash/values'
import _find from 'lodash/find'
import _filter from 'lodash/filter'
import _startsWith from 'lodash/startsWith'
@@ -35,13 +34,12 @@ import Title from 'components/Title'
import EventsRunningOutBanner from 'components/EventsRunningOutBanner'
import {
tbPeriodPairs, getProjectCacheKey, LIVE_VISITORS_UPDATE_INTERVAL, DEFAULT_TIMEZONE, CDN_URL, isDevelopment,
- timeBucketToDays, getProjectCacheCustomKey, roleViewer, MAX_MONTHS_IN_PAST, MAX_MONTHS_IN_PAST_FREE, PROJECT_TABS, TimeFormat, chartTypes,
+ timeBucketToDays, getProjectCacheCustomKey, roleViewer, MAX_MONTHS_IN_PAST, MAX_MONTHS_IN_PAST_FREE, TimeFormat, chartTypes,
} from 'redux/constants'
import Button from 'ui/Button'
import Loader from 'ui/Loader'
import Dropdown from 'ui/Dropdown'
import Checkbox from 'ui/Checkbox'
-import Select from 'ui/Select'
import FlatPicker from 'ui/Flatpicker'
import PaidFeature from 'modals/PaidFeature'
import routes from 'routes'
@@ -61,12 +59,9 @@ import NoEvents from './components/NoEvents'
import Filters from './components/Filters'
import './styles.css'
-const PROJECT_TABS_VALUES = _values(PROJECT_TABS)
-
const ViewProject = ({
projects, isLoading: _isLoading, showError, cache, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,
- setLiveStatsForProject, authenticated, timezone, user, sharedProjects, isPaidTierUsed, extensions, generateAlert,
- projectTab, setProjectTab, setProjects,
+ setLiveStatsForProject, authenticated, timezone, user, isPaidTierUsed, extensions, generateAlert, setProjects,
}) => {
const { t, i18n: { language } } = useTranslation('common')
const [periodPairs, setPeriodPairs] = useState(tbPeriodPairs(t))
@@ -76,11 +71,7 @@ const ViewProject = ({
const dashboardRef = useRef(null)
const { id } = useParams()
const history = useHistory()
- const project = useMemo(() => _find([...projects, ..._map(sharedProjects, (item) => item.project)], p => p.id === id) || {}, [projects, id, sharedProjects])
- const isSharedProject = useMemo(() => {
- const foundProject = _find([..._map(sharedProjects, (item) => item.project)], p => p.id === id)
- return !_isEmpty(foundProject)
- }, [id, sharedProjects])
+ const project = useMemo(() => _find(projects, p => p.id === id) || {}, [projects, id])
const [areFiltersParsed, setAreFiltersParsed] = useState(false)
const [areTimeBucketParsed, setAreTimeBucketParsed] = useState(false)
const [arePeriodParsed, setArePeriodParsed] = useState(false)
@@ -750,7 +741,7 @@ const ViewProject = ({
}
const openSettingsHandler = () => {
- history.push(_replace(routes.project_settings, ':id', id))
+ history.push(_replace(routes.captcha_settings, ':id', id))
}
const exportAsImageHandler = async () => {
@@ -772,7 +763,7 @@ const ViewProject = ({
const url = new URL(window.location)
const { searchParams } = url
const intialPeriod = searchParams.get('period')
- if (!_includes(validPeriods, intialPeriod) || (!isSharedProject && id !== SWETRIX_PID && !isPaidTierUsed && _includes(paidPeriods, intialPeriod))) {
+ if (!_includes(validPeriods, intialPeriod) || (id !== SWETRIX_PID && !isPaidTierUsed && _includes(paidPeriods, intialPeriod))) {
return
}
@@ -909,7 +900,7 @@ const ViewProject = ({
// disable limitation for shared projects as project hosts already have a paid plan
// disable limitation for Swetrix public project (for demonstration purposes)
- if (!isSharedProject && id !== SWETRIX_PID && !isPaidTierUsed && pair.access === 'paid') {
+ if (id !== SWETRIX_PID && !isPaidTierUsed && pair.access === 'paid') {
return (
<span className='flex items-center'>
<CurrencyDollarIcon className='w-4 h-4 mr-1' />
@@ -922,7 +913,7 @@ const ViewProject = ({
}}
keyExtractor={(pair) => pair.label}
onSelect={(pair) => {
- if (!isSharedProject && id !== SWETRIX_PID && !isPaidTierUsed && pair.access === 'paid') {
+ if (id !== SWETRIX_PID && !isPaidTierUsed && pair.access === 'paid') {
setIsPaidFeatureOpened(true)
return
}
@@ -942,7 +933,7 @@ const ViewProject = ({
ref={refCalendar}
onChange={(date) => setDateRange(date)}
value={dateRange}
- maxDateMonths={(isPaidTierUsed || id === SWETRIX_PID || isSharedProject) ? MAX_MONTHS_IN_PAST : MAX_MONTHS_IN_PAST_FREE}
+ maxDateMonths={(isPaidTierUsed || id === SWETRIX_PID) ? MAX_MONTHS_IN_PAST : MAX_MONTHS_IN_PAST_FREE}
/>
</div>
</div>
@@ -1207,7 +1198,6 @@ const ViewProject = ({
ViewProject.propTypes = {
projects: PropTypes.arrayOf(PropTypes.object).isRequired,
- sharedProjects: PropTypes.arrayOf(PropTypes.object).isRequired,
cache: PropTypes.objectOf(PropTypes.object).isRequired,
projectViewPrefs: PropTypes.objectOf(PropTypes.object).isRequired,
showError: PropTypes.func.isRequired,
diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsx
index e9ff82fd9..dacfddfba 100644
--- a/src/pages/Dashboard/Dashboard.jsx
+++ b/src/pages/Dashboard/Dashboard.jsx
@@ -1,6 +1,6 @@
/* eslint-disable react/forbid-prop-types */
import React, {
- memo, useState, useMemo, useEffect,
+ memo, useState, useEffect,
} from 'react'
import { Link, useHistory } from 'react-router-dom'
import cx from 'clsx'
@@ -13,7 +13,6 @@ import _map from 'lodash/map'
import _isUndefined from 'lodash/isUndefined'
import _filter from 'lodash/filter'
import _find from 'lodash/find'
-import _ceil from 'lodash/ceil'
import { useTranslation } from 'react-i18next'
import { EyeIcon, CalendarIcon, FolderPlusIcon } from '@heroicons/react/24/outline'
import { ArrowSmallUpIcon, ArrowSmallDownIcon, XCircleIcon } from '@heroicons/react/24/solid'
@@ -347,7 +346,7 @@ const Dashboard = ({
name, id, created, active, overall, live, public: isPublic, confirmed, shared = false,
}) => (
<div key={confirmed ? `${id}-confirmed` : id}>
- <Link to={_replace(routes.project, ':id', id)}>
+ <Link to={_replace(routes.captcha, ':id', id)}>
<ProjectCart
t={t}
language={language}
diff --git a/src/routes.js b/src/routes.js
index 10cbaaa66..7e13d6f62 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -14,6 +14,7 @@ const routes = Object.freeze({
project_settings: '/projects/settings/:id',
captcha_settings: '/captchas/settings/:id',
project: '/projects/:id',
+ captcha: '/captchas/:id',
features: '/features',
billing: '/billing',
privacy: '/privacy',