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 performance metric cards with main metric cards component

Blue Mousebb52f41eadc8
diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsx
index fa52153da..096fdeedb 100644
--- a/app/pages/Project/View/ViewProject.tsx
+++ b/app/pages/Project/View/ViewProject.tsx
@@ -191,8 +191,7 @@ import SearchFilters from './components/SearchFilters'
import Filters from './components/Filters'
import LiveVisitorsDropdown from './components/LiveVisitorsDropdown'
import CountryDropdown from './components/CountryDropdown'
-import { MetricCard, MetricCards } from './components/MetricCards'
-import PerformanceMetricCards from './components/PerformanceMetricCards'
+import { MetricCard, MetricCards, PerformanceMetricCards } from './components/MetricCards'
import ProjectAlertsView from '../Alerts/View'
import Uptime from '../uptime/View'
import UTMDropdown from './components/UTMDropdown'
diff --git a/app/pages/Project/View/components/MetricCards.tsx b/app/pages/Project/View/components/MetricCards.tsx
index 113f79c49..08a166e75 100644
--- a/app/pages/Project/View/components/MetricCards.tsx
+++ b/app/pages/Project/View/components/MetricCards.tsx
@@ -8,7 +8,7 @@ import _isEmpty from 'lodash/isEmpty'
import _isNumber from 'lodash/isNumber'
import _map from 'lodash/map'
import { nFormatter, getStringFromTime, getTimeFromSeconds } from 'utils/generic'
-import { IOverallObject } from 'redux/models/IProject'
+import { IOverallObject, IOverallPerformanceObject } from 'redux/models/IProject'
import { ChevronDownIcon, ChevronUpIcon, XMarkIcon } from '@heroicons/react/24/outline'
import { Badge } from 'ui/Badge'
import { MonitorOverallObject } from 'redux/models/Uptime'
@@ -265,5 +265,63 @@ export const MetricCardsUptime = memo(({ overall }: IMetricCardsUptime) => {
)
})
+interface IPerformanceMetricCards {
+ overall: Partial<IOverallPerformanceObject>
+ overallCompare?: Partial<IOverallPerformanceObject>
+ activePeriodCompare?: string
+}
+
+export const PerformanceMetricCards = memo(
+ ({ overall, overallCompare, activePeriodCompare }: IPerformanceMetricCards) => {
+ const { t } = useTranslation('common')
+
+ let frontendChange = overall.frontendChange
+ let backendChange = overall.backendChange
+ let networkChange = overall.networkChange
+
+ if (!_isEmpty(overallCompare) && activePeriodCompare !== 'previous') {
+ // @ts-ignore
+ frontendChange = overall.current?.frontend - overallCompare?.current?.frontend
+ // @ts-ignore
+ backendChange = overall.current?.backend - overallCompare?.current?.backend
+ // @ts-ignore
+ networkChange = overall.current?.network - overallCompare?.current?.network
+ }
+
+ return (
+ <div className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'>
+ <MetricCard
+ label={t('dashboard.frontend')}
+ value={overall.current?.frontend}
+ change={frontendChange}
+ goodChangeDirection='up'
+ valueMapper={(value, type) =>
+ `${type === 'badge' && value > 0 ? '+' : ''}${getStringFromTime(getTimeFromSeconds(value), true)}`
+ }
+ />
+ <MetricCard
+ label={t('dashboard.backend')}
+ value={overall.current?.backend}
+ change={backendChange}
+ goodChangeDirection='up'
+ valueMapper={(value, type) =>
+ `${type === 'badge' && value > 0 ? '+' : ''}${getStringFromTime(getTimeFromSeconds(value), true)}`
+ }
+ />
+ <MetricCard
+ label={t('dashboard.network')}
+ value={overall.current?.network}
+ change={networkChange}
+ goodChangeDirection='up'
+ valueMapper={(value, type) =>
+ `${type === 'badge' && value > 0 ? '+' : ''}${getStringFromTime(getTimeFromSeconds(value), true)}`
+ }
+ />
+ </div>
+ )
+ },
+)
+
MetricCards.displayName = 'MetricCards'
MetricCardsUptime.displayName = 'MetricCardsUptime'
+PerformanceMetricCards.displayName = 'PerformanceMetricCards'
diff --git a/app/pages/Project/View/components/PerformanceMetricCards.tsx b/app/pages/Project/View/components/PerformanceMetricCards.tsx
deleted file mode 100644
index c559dba5f..000000000
--- a/app/pages/Project/View/components/PerformanceMetricCards.tsx
+++ /dev/null
@@ -1,63 +0,0 @@
-import React, { memo } from 'react'
-import { useTranslation } from 'react-i18next'
-import _isEmpty from 'lodash/isEmpty'
-import { getStringFromTime, getTimeFromSeconds } from 'utils/generic'
-import { IOverallPerformanceObject } from 'redux/models/IProject'
-import { MetricCard } from './MetricCards'
-
-interface IMetricCards {
- overall: Partial<IOverallPerformanceObject>
- overallCompare?: Partial<IOverallPerformanceObject>
- activePeriodCompare?: string
-}
-
-const PerformanceMetricCards = ({ overall, overallCompare, activePeriodCompare }: IMetricCards) => {
- const { t } = useTranslation('common')
-
- let frontendChange = overall.frontendChange
- let backendChange = overall.backendChange
- let networkChange = overall.networkChange
-
- if (!_isEmpty(overallCompare) && activePeriodCompare !== 'previous') {
- // @ts-ignore
- frontendChange = overall.current?.frontend - overallCompare?.current?.frontend
- // @ts-ignore
- backendChange = overall.current?.backend - overallCompare?.current?.backend
- // @ts-ignore
- networkChange = overall.current?.network - overallCompare?.current?.network
- }
-
- return (
- <div className='mb-5 flex flex-wrap justify-center gap-5 lg:justify-start'>
- <MetricCard
- label={t('dashboard.frontend')}
- value={overall.current?.frontend}
- change={frontendChange}
- goodChangeDirection='up'
- valueMapper={(value, type) =>
- `${type === 'badge' && value > 0 ? '+' : ''}${getStringFromTime(getTimeFromSeconds(value), true)}`
- }
- />
- <MetricCard
- label={t('dashboard.backend')}
- value={overall.current?.backend}
- change={backendChange}
- goodChangeDirection='up'
- valueMapper={(value, type) =>
- `${type === 'badge' && value > 0 ? '+' : ''}${getStringFromTime(getTimeFromSeconds(value), true)}`
- }
- />
- <MetricCard
- label={t('dashboard.network')}
- value={overall.current?.network}
- change={networkChange}
- goodChangeDirection='up'
- valueMapper={(value, type) =>
- `${type === 'badge' && value > 0 ? '+' : ''}${getStringFromTime(getTimeFromSeconds(value), true)}`
- }
- />
- </div>
- )
-}
-
-export default memo(PerformanceMetricCards)