Skip to content

Commit

Permalink
Fix money values on graphs and conversions graph tooltips (plausibl…
Browse files Browse the repository at this point in the history
…e#4717)

* Fix conversions graph tooltips

* Show revenue value instead of `undefined` in graph

This broke due to the unification of formatters. Not sure if this is the best fix
  • Loading branch information
macobo authored Oct 22, 2024
1 parent d727ba5 commit d648505
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions assets/js/dashboard/stats/reports/metric-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type FormattableMetric =
| 'total_visitors'
| 'current_visitors'
| 'exit_rate'
| 'conversions'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ValueType = any
Expand All @@ -30,6 +31,8 @@ export const MetricFormatterShort: Record<
visitors: numberShortFormatter,
visits: numberShortFormatter,

conversions: numberShortFormatter,

time_on_page: durationFormatter,
visit_duration: durationFormatter,

Expand All @@ -55,6 +58,8 @@ export const MetricFormatterLong: Record<
visitors: numberLongFormatter,
visits: numberLongFormatter,

conversions: numberLongFormatter,

time_on_page: durationFormatter,
visit_duration: durationFormatter,

Expand Down
14 changes: 10 additions & 4 deletions assets/js/dashboard/util/money.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { numberLongFormatter, numberShortFormatter } from "./number-formatter"

type Money = { long: string, short: string }

export function formatMoneyShort(value: Money | null) {
if (value) {
export function formatMoneyShort(value: Money | number | null) {
if (typeof value == 'number') {
return numberShortFormatter(value)
} else if (value) {
return value.short
} else {
return "-"
}
}

export function formatMoneyLong(value: Money | null) {
if (value) {
export function formatMoneyLong(value: Money | number | null) {
if (typeof value == 'number') {
return numberLongFormatter(value)
} else if (value) {
return value.long
} else {
return "-"
Expand Down

0 comments on commit d648505

Please sign in to comment.