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 project alerts

Maksim Mrug1612337c5ac4
diff --git a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
index c2eb66516..497ae9745 100644
--- a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
+++ b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
@@ -1,9 +1,10 @@
/* eslint-disable react/forbid-prop-types */
import React, { useEffect, useMemo, useState } from 'react'
-import { useHistory, useParams, useLocation } from 'react-router-dom'
+import {
+ useNavigate, useParams, useLocation, Link,
+} from '@remix-run/react'
import { useTranslation, Trans } from 'react-i18next'
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'
-import { HashLink } from 'react-router-hash-link'
import PropTypes from 'prop-types'
import _isEmpty from 'lodash/isEmpty'
@@ -18,7 +19,6 @@ import _values from 'lodash/values'
import _findKey from 'lodash/findKey'
import _toNumber from 'lodash/toNumber'
import { clsx as cx } from 'clsx'
-import Title from 'components/Title'
import Input from 'ui/Input'
import Button from 'ui/Button'
import Checkbox from 'ui/Checkbox'
@@ -30,7 +30,7 @@ import {
createAlert, updateAlert, deleteAlert, ICreateAlert,
} from 'api'
import { withAuthentication, auth } from 'hoc/protected'
-import routes from 'routes'
+import routes from 'routesPath'
import Select from 'ui/Select'
import { IAlerts } from 'redux/models/IAlerts'
import { IUser } from 'redux/models/IUser'
@@ -48,7 +48,7 @@ const ProjectAlertsSettings = ({
total: number
generateAlerts: (message: string) => void
}): JSX.Element => {
- const history = useHistory()
+ const navigate = useNavigate()
const { id, pid }: {
id: string
pid: string
@@ -161,7 +161,7 @@ const ProjectAlertsSettings = ({
if (isSettings) {
updateAlert(id, data)
.then((res) => {
- history.push(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
+ navigate(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
setProjectAlerts([..._filter(alerts, (a) => a.id !== id), res])
generateAlerts(t('alertsSettings.alertUpdated'))
})
@@ -171,7 +171,7 @@ const ProjectAlertsSettings = ({
} else {
createAlert(data as ICreateAlert)
.then((res) => {
- history.push(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
+ navigate(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
setProjectAlerts([...alerts, res])
setProjectAlertsTotal(total + 1)
generateAlerts(t('alertsSettings.alertCreated'))
@@ -187,7 +187,7 @@ const ProjectAlertsSettings = ({
.then(() => {
setProjectAlerts(_filter(alerts, (a) => a.id !== id))
setProjectAlertsTotal(total - 1)
- history.push(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
+ navigate(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
generateAlerts(t('alertsSettings.alertDeleted'))
})
.catch((err) => {
@@ -196,7 +196,7 @@ const ProjectAlertsSettings = ({
}
const onCancel = () => {
- history.push(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
+ navigate(`/projects/${pid}?tab=${PROJECT_TABS.alerts}`)
}
useEffect(() => {
@@ -228,127 +228,116 @@ const ProjectAlertsSettings = ({
}) : t('alert.create')
return (
- <Title title={title}>
- <div
- className={cx('min-h-min-footer bg-gray-50 dark:bg-slate-900 flex flex-col py-6 px-4 sm:px-6 lg:px-8', {
- 'pb-40': isSettings,
- })}
- >
- <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
- <h2 className='mt-2 text-3xl font-bold text-gray-900 dark:text-gray-50'>
- {title}
- </h2>
- {!isIntegrationLinked && (
- <div className='flex items-center bg-blue-50 dark:text-gray-50 dark:bg-slate-800 rounded px-5 py-3 mt-2 whitespace-pre-wrap text-base'>
- <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
- <Trans
+ <div
+ className={cx('min-h-min-footer bg-gray-50 dark:bg-slate-900 flex flex-col py-6 px-4 sm:px-6 lg:px-8', {
+ 'pb-40': isSettings,
+ })}
+ >
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-bold text-gray-900 dark:text-gray-50'>
+ {title}
+ </h2>
+ {!isIntegrationLinked && (
+ <div className='flex items-center bg-blue-50 dark:text-gray-50 dark:bg-slate-800 rounded px-5 py-3 mt-2 whitespace-pre-wrap text-base'>
+ <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
+ <Trans
// @ts-ignore
- t={t}
- i18nKey='alert.noIntegration'
- components={{
- url: <HashLink to={INTEGRATIONS_LINK} className='hover:underline text-blue-600 dark:text-blue-500' />,
- }}
- />
- </div>
- )}
- <Input
- name='name'
- id='name'
- type='text'
- label={t('alert.name')}
- value={form.name || ''}
- placeholder={t('alert.name')}
- className='mt-4'
- onChange={handleInput}
- error={beenSubmitted ? errors.name : null}
+ t={t}
+ i18nKey='alert.noIntegration'
+ components={{
+ url: <Link to={INTEGRATIONS_LINK} className='hover:underline text-blue-600 dark:text-blue-500' />,
+ }}
/>
- <Checkbox
- checked={Boolean(form.active)}
- onChange={handleInput}
- name='active'
- id='active'
- className='mt-4'
- label={t('alert.enabled')}
- hint={t('alert.enabledHint')}
+ </div>
+ )}
+ <Input
+ name='name'
+ id='name'
+ type='text'
+ label={t('alert.name')}
+ value={form.name || ''}
+ placeholder={t('alert.name')}
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.name : null}
+ />
+ <Checkbox
+ checked={Boolean(form.active)}
+ onChange={handleInput}
+ name='active'
+ id='active'
+ className='mt-4'
+ label={t('alert.enabled')}
+ hint={t('alert.enabledHint')}
+ />
+ <div className='mt-4'>
+ <Select
+ id='queryMetric'
+ label={t('alert.metric')}
+ items={_values(queryMetricTMapping)}
+ title={form.queryMetric ? queryMetricTMapping[form.queryMetric] : ''}
+ onSelect={(item) => {
+ const key = _findKey(queryMetricTMapping, predicate => predicate === item)
+
+ setForm(prevForm => ({
+ ...prevForm,
+ queryMetric: key,
+ }))
+ }}
/>
- <div className='mt-4'>
- <Select
- id='queryMetric'
- label={t('alert.metric')}
- items={_values(queryMetricTMapping)}
- title={form.queryMetric ? queryMetricTMapping[form.queryMetric] : ''}
- onSelect={(item) => {
- const key = _findKey(queryMetricTMapping, predicate => predicate === item)
-
- setForm(prevForm => ({
- ...prevForm,
- queryMetric: key,
- }))
- }}
- />
- </div>
- <div className='mt-4'>
- <Select
- id='queryCondition'
- label={t('alert.condition')}
- items={_values(queryConditionTMapping)}
- title={form.queryCondition ? queryConditionTMapping[form.queryCondition] : ''}
- onSelect={(item) => {
- const key = _findKey(queryConditionTMapping, predicate => predicate === item)
-
- setForm(prevForm => ({
- ...prevForm,
- queryCondition: key,
- }))
- }}
- />
- </div>
- <Input
- name='queryValue'
- id='queryValue'
- type='text'
- label={t('alert.threshold')}
- value={form.queryValue || ''}
- placeholder='10'
- className='mt-4'
- onChange={handleInput}
- error={beenSubmitted ? errors.queryValue : null}
+ </div>
+ <div className='mt-4'>
+ <Select
+ id='queryCondition'
+ label={t('alert.condition')}
+ items={_values(queryConditionTMapping)}
+ title={form.queryCondition ? queryConditionTMapping[form.queryCondition] : ''}
+ onSelect={(item) => {
+ const key = _findKey(queryConditionTMapping, predicate => predicate === item)
+
+ setForm(prevForm => ({
+ ...prevForm,
+ queryCondition: key,
+ }))
+ }}
/>
- <div className='mt-4'>
- <Select
- id='queryTime'
- label={t('alert.time')}
- items={_values(queryTimeTMapping)}
- title={form.queryTime ? queryTimeTMapping[form.queryTime] : ''}
- onSelect={(item) => {
- const key = _findKey(queryTimeTMapping, predicate => predicate === item)
-
- setForm(prevForm => ({
- ...prevForm,
- queryTime: key,
- }))
- }}
- />
- </div>
- {isSettings ? (
- <div className='flex justify-between items-center mt-5'>
- <Button onClick={() => setShowModal(true)} danger semiSmall>
- <>
- <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
- {t('alert.delete')}
- </>
- </Button>
- <div className='flex justify-between items-center'>
- <Button className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-slate-700/50 dark:bg-slate-800 dark:hover:bg-slate-700' onClick={onCancel} secondary regular>
- {t('common.cancel')}
- </Button>
- <Button type='submit' primary regular>
- {t('common.save')}
- </Button>
- </div>
- </div>
- ) : (
- <div className='mt-5 flex justify-between items-center'>
+ </div>
+ <Input
+ name='queryValue'
+ id='queryValue'
+ type='text'
+ label={t('alert.threshold')}
+ value={form.queryValue || ''}
+ placeholder='10'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.queryValue : null}
+ />
+ <div className='mt-4'>
+ <Select
+ id='queryTime'
+ label={t('alert.time')}
+ items={_values(queryTimeTMapping)}
+ title={form.queryTime ? queryTimeTMapping[form.queryTime] : ''}
+ onSelect={(item) => {
+ const key = _findKey(queryTimeTMapping, predicate => predicate === item)
+
+ setForm(prevForm => ({
+ ...prevForm,
+ queryTime: key,
+ }))
+ }}
+ />
+ </div>
+ {isSettings ? (
+ <div className='flex justify-between items-center mt-5'>
+ <Button onClick={() => setShowModal(true)} danger semiSmall>
+ <>
+ <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
+ {t('alert.delete')}
+ </>
+ </Button>
+ <div className='flex justify-between items-center'>
<Button className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-slate-700/50 dark:bg-slate-800 dark:hover:bg-slate-700' onClick={onCancel} secondary regular>
{t('common.cancel')}
</Button>
@@ -356,21 +345,30 @@ const ProjectAlertsSettings = ({
{t('common.save')}
</Button>
</div>
- )}
- </form>
- <Modal
- onClose={() => setShowModal(false)}
- onSubmit={onDelete}
- submitText={t('alert.delete')}
- closeText={t('common.close')}
- title={t('alert.qDelete')}
- message={t('alert.deleteHint')}
- submitType='danger'
- type='error'
- isOpened={showModal}
- />
- </div>
- </Title>
+ </div>
+ ) : (
+ <div className='mt-5 flex justify-between items-center'>
+ <Button className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-slate-700/50 dark:bg-slate-800 dark:hover:bg-slate-700' onClick={onCancel} secondary regular>
+ {t('common.cancel')}
+ </Button>
+ <Button type='submit' primary regular>
+ {t('common.save')}
+ </Button>
+ </div>
+ )}
+ </form>
+ <Modal
+ onClose={() => setShowModal(false)}
+ onSubmit={onDelete}
+ submitText={t('alert.delete')}
+ closeText={t('common.close')}
+ title={t('alert.qDelete')}
+ message={t('alert.deleteHint')}
+ submitType='danger'
+ type='error'
+ isOpened={showModal}
+ />
+ </div>
)
}
diff --git a/app/pages/Project/Alerts/View/ProjectAlertsView.tsx b/app/pages/Project/Alerts/View/ProjectAlertsView.tsx
index a07da9e43..f89093c58 100644
--- a/app/pages/Project/Alerts/View/ProjectAlertsView.tsx
+++ b/app/pages/Project/Alerts/View/ProjectAlertsView.tsx
@@ -10,14 +10,14 @@ 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 { useNavigate } from '@remix-run/react'
import { useTranslation } from 'react-i18next'
import PropTypes from 'prop-types'
import {
BellIcon, CurrencyDollarIcon, PencilSquareIcon, FolderPlusIcon,
} from '@heroicons/react/24/outline'
-import routes from 'routes'
+import routes from 'routesPath'
import Button from 'ui/Button'
import PaidFeature from 'modals/PaidFeature'
import { QUERY_METRIC, PLAN_LIMITS } from 'redux/constants'
@@ -39,7 +39,7 @@ const ProjectAlerts = ({
i18n: { language: string },
} = useTranslation()
const [isPaidFeatureOpened, setIsPaidFeatureOpened] = useState<boolean>(false)
- const history = useHistory()
+ const navigate = useNavigate()
// @ts-ignore
const limits = PLAN_LIMITS[user?.planCode] || PLAN_LIMITS.trial
@@ -71,7 +71,7 @@ const ProjectAlerts = ({
return
}
- history.push(_replace(routes.create_alert, ':pid', projectId))
+ navigate(_replace(routes.create_alert, ':pid', projectId))
}
return (
@@ -174,7 +174,7 @@ const ProjectAlerts = ({
)}
<Button
onClick={() => {
- history.push(_replace(_replace(routes.alert_settings, ':pid', projectId), ':id', id))
+ navigate(_replace(_replace(routes.alert_settings, ':pid', projectId), ':id', id))
}}
className='dark:text-gray-50 dark:bg-slate-800 dark:hover:bg-slate-700'
secondary