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: alerts if is public projects

kruzhambus09ad2b128d4c
diff --git a/src/pages/Project/Alerts/Settings/ProjectAlertsSettings.jsx b/src/pages/Project/Alerts/Settings/ProjectAlertsSettings.jsx
index 5b99b78b2..aa33e9b6a 100644
--- a/src/pages/Project/Alerts/Settings/ProjectAlertsSettings.jsx
+++ b/src/pages/Project/Alerts/Settings/ProjectAlertsSettings.jsx
@@ -130,7 +130,6 @@ const ProjectAlertsSettings = ({
if (isSettings) {
updateAlert(id, data)
.then((res) => {
- console.log(res)
history.push(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
setProjectAlerts([..._filter(alerts, (a) => a.id !== id), res])
})
diff --git a/src/pages/Project/Alerts/View/ProjectAlertsView.jsx b/src/pages/Project/Alerts/View/ProjectAlertsView.jsx
index 335a85289..38e0ec3cd 100644
--- a/src/pages/Project/Alerts/View/ProjectAlertsView.jsx
+++ b/src/pages/Project/Alerts/View/ProjectAlertsView.jsx
@@ -6,6 +6,8 @@ import _isEmpty from 'lodash/isEmpty'
import _replace from 'lodash/replace'
import _values from 'lodash/values'
import _reduce from 'lodash/reduce'
+import _filter from 'lodash/filter'
+import _trucate from 'lodash/truncate'
import { useHistory } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import PropTypes from 'prop-types'
@@ -21,6 +23,12 @@ const ProjectAlerts = ({
const { t, i18n: { language } } = useTranslation()
const history = useHistory()
+ // find in alerts alert with pid === projectId
+ const projectAlerts = useMemo(() => {
+ if (loading) return []
+ return _filter(alerts, ({ pid }) => pid === projectId)
+ }, [projectId, alerts, loading])
+
const queryMetricTMapping = useMemo(() => {
const values = _values(QUERY_METRIC)
@@ -34,12 +42,10 @@ const ProjectAlerts = ({
return !_isEmpty(user) && user.telegramChatId && user.isTelegramChatIdConfirmed
}, [user])
- console.log(isIntegrationLinked)
-
return (
<div>
<div className='flex justify-between items-center'>
- {!loading && !_isEmpty(alerts) && (
+ {!loading && !_isEmpty(projectAlerts) && (
<>
<h2 className='text-2xl font-bold dark:text-white text-gray-800'>Alerts</h2>
<Button
@@ -62,7 +68,7 @@ const ProjectAlerts = ({
{t('common.loading')}
</div>
)}
- {(!loading && _isEmpty(alerts)) && (
+ {(!loading && _isEmpty(projectAlerts)) && (
<div className='p-5 mt-5 bg-gray-700 rounded-xl'>
<div className='flex items-center text-gray-50'>
<BellIcon className='w-8 h-8 mr-2' />
@@ -88,15 +94,17 @@ const ProjectAlerts = ({
</Button>
</div>
)}
- {(!loading && !_isEmpty(alerts)) && (
+ {(!loading && !_isEmpty(projectAlerts)) && (
<div className='flex flex-col'>
- {_map(alerts, ({
+ {_map(projectAlerts, ({
id, name, queryMetric, lastTriggered,
}) => (
<div key={id} className='flex flex-col bg-white dark:bg-gray-800 rounded-lg shadow-lg p-4 mb-4'>
<div className='flex justify-between items-center'>
<div className='flex flex-col'>
- <div className='text-lg font-bold dark:text-white text-gray-800'>{name}</div>
+ <div className='text-lg font-bold dark:text-white text-gray-800 hidden md:block'>{name}</div>
+ <div className='text-lg font-bold dark:text-white text-gray-800 hidden sm:block md:hidden'>{_trucate(name, { length: 20 })}</div>
+ <div className='text-lg font-bold dark:text-white text-gray-800 sm:hidden'>{_trucate(name, { length: 10 })}</div>
<div className='text-sm dark:text-gray-400 text-gray-600'>{queryMetricTMapping[queryMetric]}</div>
</div>
<div className='flex flex-col'>
diff --git a/src/pages/Project/View/ViewProject.container.jsx b/src/pages/Project/View/ViewProject.container.jsx
index 63e859a3d..4a5a8bde7 100644
--- a/src/pages/Project/View/ViewProject.container.jsx
+++ b/src/pages/Project/View/ViewProject.container.jsx
@@ -56,6 +56,9 @@ const mapDispatchToProps = (dispatch) => ({
setPublicProject: (project) => {
dispatch(UIActions.setPublicProject(project))
},
+ setProjects: (project, shared) => {
+ dispatch(UIActions.setProjects(project, shared))
+ },
setLiveStatsForProject: (id, count) => {
dispatch(UIActions.setLiveStatsForProject(id, count))
},
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index 73fa18d75..ebc74e1c1 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -63,7 +63,7 @@ import './styles.css'
const ViewProject = ({
projects, isLoading: _isLoading, showError, cache, cachePerf, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,
setLiveStatsForProject, authenticated, timezone, user, sharedProjects, isPaidTierUsed, extensions, generateAlert, setProjectCachePerf,
- projectTab, setProjectTab,
+ projectTab, setProjectTab, setProjects,
}) => {
const { t, i18n: { language } } = useTranslation('common')
const [periodPairs, setPeriodPairs] = useState(tbPeriodPairs(t))
@@ -954,19 +954,35 @@ const ViewProject = ({
if (!isLoading && _isEmpty(project)) {
getProject(id)
.then(projectRes => {
- if (!_isEmpty(projectRes) && projectRes?.public) {
- getOverallStats([id])
- .then(res => {
- setPublicProject({
- ...projectRes,
- overall: res[id],
- live: 'N/A',
+ if (!_isEmpty(projectRes)) {
+ if (projectRes.isPublic && !projectRes.isOwner) {
+ getOverallStats([id])
+ .then(res => {
+ setPublicProject({
+ ...projectRes,
+ overall: res[id],
+ live: 'N/A',
+ isPublicVisitors: true,
+ })
})
- })
- .catch(e => {
- console.error(e)
- onErrorLoading()
- })
+ .catch(e => {
+ console.error(e)
+ onErrorLoading()
+ })
+ } else {
+ getOverallStats([id])
+ .then(res => {
+ setProjects([...projects, {
+ ...projectRes,
+ overall: res[id],
+ live: 'N/A',
+ }])
+ })
+ .catch(e => {
+ console.error(e)
+ onErrorLoading()
+ })
+ }
setIsProjectPublic(true)
} else {
@@ -1353,7 +1369,7 @@ const ViewProject = ({
onSelect={item => item.onClick(panelsData, t)}
className={cx('ml-3', { hidden: isPanelsDataEmpty || analyticsLoading })}
/>
- {(!isProjectPublic && !(sharedRoles === roleViewer.role)) && (
+ {(!project?.isPublicVisitors && !(sharedRoles === roleViewer.role)) && (
<Button
onClick={openSettingsHandler}
className='relative flex justify-center items-center py-2 !pr-3 !pl-1 md:pr-4 md:pl-2 ml-3 text-sm dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600'
@@ -1366,7 +1382,7 @@ const ViewProject = ({
</div>
</>
)}
- {(activeTab === PROJECT_TABS.alerts && (isSharedProject || project.public)) && (
+ {(activeTab === PROJECT_TABS.alerts && (isSharedProject || project?.isPublicVisitors)) && (
<div className='p-5 mt-5 bg-gray-700 rounded-xl'>
<div className='flex items-center text-gray-50'>
<BellIcon className='w-8 h-8 mr-2' />
@@ -1382,7 +1398,7 @@ const ViewProject = ({
</Link>
</div>
)}
- {activeTab === PROJECT_TABS.alerts && !isSharedProject && !project.public && (
+ {(activeTab === PROJECT_TABS.alerts && !isSharedProject && !project?.isPublicVisitors) && (
<ProjectAlertsView projectId={id} />
)}
{(analyticsLoading && activeTab !== PROJECT_TABS.alerts) && (