📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fixed a crash when an incorrect TB or PERIOD is stored in localstorage
Blue Mousef92eefb7cb06
diff --git a/app/pages/Project/View/ViewProject.helpers.tsx b/app/pages/Project/View/ViewProject.helpers.tsxindex 549663255..5200d39b3 100644--- a/app/pages/Project/View/ViewProject.helpers.tsx+++ b/app/pages/Project/View/ViewProject.helpers.tsx@@ -21,7 +21,12 @@ import _round from 'lodash/round'import _fill from 'lodash/fill'import _reduce from 'lodash/reduce'import _last from 'lodash/last'+import _toNumber from 'lodash/toNumber'+import _toString from 'lodash/toString'+import _includes from 'lodash/includes'import JSZip from 'jszip'+// @ts-ignore+import * as d3 from 'd3'import {TimeFormat, chartTypes, tbsFormatMapper, tbsFormatMapper24h, tbsFormatMapperTooltip, tbsFormatMapperTooltip24h,@@ -30,11 +35,6 @@ import {getTimeFromSeconds, getStringFromTime, sumArrays, nFormatter,} from 'utils/generic'import countries from 'utils/isoCountries'-import _toNumber from 'lodash/toNumber'-import _toString from 'lodash/toString'-import _includes from 'lodash/includes'-// @ts-ignore-import * as d3 from 'd3'const getAvg = (arr: any) => {const total = _reduce(arr, (acc, c) => acc + c, 0)@@ -909,6 +909,26 @@ const validTimeBacket = ['hour', 'day', 'week', 'month']const validPeriods = ['custom', 'today', 'yesterday', '1d', '7d', '4w', '3M', '12M', '24M']const validFilters = ['cc', 'rg', 'ct', 'pg', 'lc', 'ref', 'dv', 'br', 'os', 'so', 'me', 'ca', 'ev']+export const filterInvalidViewPrefs = (prefs: any): any => {+ const pids = _keys(prefs)+ const filtered = _reduce(pids, (prev: string[], curr: string) => {+ const { period, timeBucket } = prefs[curr]++ if (!_includes(validPeriods, period) || !_includes(validTimeBacket, timeBucket)) {+ return prev+ }++ return [...prev, curr]+ }, [])++ return _reduce(filtered, (prev: any, curr: string) => {+ return {+ ...prev,+ [curr]: prefs[curr],+ }+ })+}+const typeNameMapping = (t: (str: string) => string) => ({cc: t('project.mapping.cc'),rg: t('project.mapping.rg'),diff --git a/app/redux/constants/index.ts b/app/redux/constants/index.tsindex d8674df24..10378d6a3 100644--- a/app/redux/constants/index.ts+++ b/app/redux/constants/index.ts@@ -30,11 +30,6 @@ export const tbPeriodPairs = (t: Function, tbs?: string[] | null, dates?: Date[]countDays?: numberdropdownLabel?: stringisCustomDate?: boolean-// }[] => [{-// label: t('project.thishour'),-// period: 'thishour',-// tbs: ['hour'],-// }, {}[] => [{label: t('project.today'),period: 'today',@@ -88,7 +83,7 @@ export const tbPeriodPairs = (t: Function, tbs?: string[] | null, dates?: Date[]tbs: tbs || ['custom'],}]-export const filtersPeriodPairs = ['thishour', '1d', '7d', '4w', '3M', '12M', 'custom', 'compare']+export const filtersPeriodPairs = ['1d', '7d', '4w', '3M', '12M', 'custom', 'compare']export const tbPeriodPairsCompare = (t: Function, dates?: Date[]): {label: stringdiff --git a/app/redux/reducers/ui/cache.ts b/app/redux/reducers/ui/cache.tsindex 52c7aacf0..404163aad 100644--- a/app/redux/reducers/ui/cache.ts+++ b/app/redux/reducers/ui/cache.ts@@ -7,6 +7,7 @@ import {getUserFlowCacheKey, isBrowser,} from 'redux/constants'import { IUserFlow } from 'redux/models/IUserFlow'+import { filterInvalidViewPrefs } from 'pages/Project/View/ViewProject.helpers'export const getInitialViewPrefs = (LS_VIEW: string) => {if (!isBrowser) {@@ -15,7 +16,7 @@ export const getInitialViewPrefs = (LS_VIEW: string) => {const storedPrefs = getItem(LS_VIEW)try {- return storedPrefs+ return filterInvalidViewPrefs(storedPrefs)} catch (e) {removeItem(LS_VIEW)}