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!

Merge branch 'main' into comments

Maksim Mrug2b2a33ffcc7c
diff --cc src/pages/Project/View/ViewProject.tsx
index 1295aab5e,1d22477ee..7808be055
--- a/src/pages/Project/View/ViewProject.tsx
+++ b/src/pages/Project/View/ViewProject.tsx
@@@ -121,9 -127,8 +127,9 @@@ interface IViewProject
const ViewProject = ({
projects, isLoading: _isLoading, showError, cache, cachePerf, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,
setLiveStatsForProject, authenticated, timezone, user, sharedProjects, extensions, generateAlert, setProjectCachePerf,
- projectTab, setProjectTab, setProjects, setProjectForcastCache, customEventsPrefs, setCustomEventsPrefs, liveStats,
+ projectTab, setProjectTab, setProjects, setProjectForcastCache, customEventsPrefs, setCustomEventsPrefs, liveStats, password,
}: IViewProject) => {
+ // t is used for translation
const { t, i18n: { language } }: {
t: (key: string, options?: {
[key: string]: string | number | null,
@@@ -160,14 -153,9 +166,17 @@@
const { id }: {
id: string
} = useParams()
+ // history is a history from react-router-dom
const history = useHistory()
+
+ // find project by id from url from state in redux projects and sharedProjects. projects and sharedProjects loading from api in Saga on page load
const project: IProjectForShared = useMemo(() => _find([...projects, ..._map(sharedProjects, (item) => ({ ...item.project, role: item.role }))], p => p.id === id) || {} as IProjectForShared, [projects, id, sharedProjects])
++
+ const projectPassword: string = useMemo(() => password[id] || getItem(PROJECTS_PROTECTED)?.[id] || '', [id, password])
++
+ /* isSharedProject is a boolean check if project is shared. If isSharedProject is true,
+ we used role and other colummn from sharedProjects.
+ And it is used for remove settings button when user have role viewer or logic with Alert tabs */
const isSharedProject = useMemo(() => {
const foundProject = _find([..._map(sharedProjects, (item) => item.project)], p => p.id === id)
return !_isEmpty(foundProject)
@@@ -515,9 -437,9 +524,10 @@@
}
}, 0), [activeTab])
+ // onErrorLoading is a function for redirect to dashboard when project do not exist
const onErrorLoading = () => {
showError(t('project.noExist'))
+ removeItem(PROJECTS_PROTECTED)
history.push(routes.dashboard)
}
@@@ -545,15 -465,11 +555,15 @@@
return _includes(_keys(customEventsChartData), metric)
})
+ // check if we need to load new date or we have data in redux/localstorage
if (!isAllActiveChartMetricsCustomEvents) {
+ // check if activePeriod is custom
if (period === 'custom' && dateRange) {
+ // activePeriod is custom
- data = await getProjectDataCustomEvents(id, timeBucket, '', filters, from, to, timezone, activeChartMetricsCustomEvents)
+ data = await getProjectDataCustomEvents(id, timeBucket, '', filters, from, to, timezone, activeChartMetricsCustomEvents, projectPassword)
} else {
+ // activePeriod is not custom
- data = await getProjectDataCustomEvents(id, timeBucket, period, filters, '', '', timezone, activeChartMetricsCustomEvents)
+ data = await getProjectDataCustomEvents(id, timeBucket, period, filters, '', '', timezone, activeChartMetricsCustomEvents, projectPassword)
}
}
@@@ -1460,14 -1349,18 +1470,19 @@@
return () => clearInterval(interval)
}, [project.id, setLiveStatsForProject]) // eslint-disable-line react-hooks/exhaustive-deps
+ // loadProject if project is empty so more often it is need for public projects
useEffect(() => {
if (!isLoading && _isEmpty(project)) {
- getProject(id)
+ getProject(id, false, projectPassword)
.then(projectRes => {
if (!_isEmpty(projectRes)) {
- if (projectRes.isPublic && !projectRes.isOwner) {
- getOverallStats([id])
+ if (projectRes.isPasswordProtected && !projectRes.isOwner && _isEmpty(projectPassword)) {
+ history.push(_replace(routes.project_protected_password, ':id', id))
+ return
+ }
+
+ if ((projectRes.isPublic || projectRes?.isPasswordProtected) && !projectRes.isOwner) {
+ getOverallStats([id], projectPassword)
.then(res => {
setPublicProject({
...projectRes,